Binding Twilio经典功能,你如何使用标签和短信?

Binding Twilio经典功能,你如何使用标签和短信?,binding,notifications,tags,twilio,sms,Binding,Notifications,Tags,Twilio,Sms,Twilio功能问题:标记未按预期工作 我正在尝试为那些将短信“关键字1”、“关键字2”、“关键字3”等添加到我的号码的用户创建唯一的短信订阅列表 我通过一个经典函数拦截“传入消息”事件来实现这一点 我想轮询关键字,然后在订阅列表时为用户分配标签 然后,当我广播短信,我希望能够发送给那些谁是我的关键字标记的用户 例如,为了捕获关键字“test”并将标记“test”分配给用户,我使用下面的代码 然后使用“sendtest”命令向所有带有标签“test”的用户发送消息 我可以向“所有”标签广播,它可

Twilio功能问题:标记未按预期工作

我正在尝试为那些将短信“关键字1”、“关键字2”、“关键字3”等添加到我的号码的用户创建唯一的短信订阅列表

我通过一个经典函数拦截“传入消息”事件来实现这一点

我想轮询关键字,然后在订阅列表时为用户分配标签

然后,当我广播短信,我希望能够发送给那些谁是我的关键字标记的用户

例如,为了捕获关键字“test”并将标记“test”分配给用户,我使用下面的代码

然后使用“sendtest”命令向所有带有标签“test”的用户发送消息

我可以向“所有”标签广播,它可以正常工作,但如果我只想向带有标签[“测试”]的用户发送,则不会报告错误,系统会告诉我成功,但没有订阅者会收到任何消息

我想知道我在定义标签的过程中是否遇到了一些问题?看起来数据格式应该是某种字符串[]数组,我猜是['test','two','three']。(如果我能确认这是正确的)。但是我注意到,根据twilio提供的工作示例,如果我将通知参数设置为一个字符串,即:
tags:'all',
,那么这个语法可以向所有标记广播。不过,其他任何方法都不会奏效

是否有一些技巧可以让标签工作,或者当试图通过经典函数界面过滤通知时,标签根本不起作用

class TestCommand extends Command {
  run(callback) {
    // Create a new SMS Notify binding for this user's phone number
    //and try to tag the user with keyword 'test'
    notify.bindings.create({
      identity: this.fromNumber,
      bindingType: 'sms',
      address: this.fromNumber,
      tags: ['test']
    }).then((response) => {
      callback(null, 'test Message success')
    }).catch(err => {
      callback(err, 'test message fail')
    })
  }
}

class BroadcastTestCommand extends Command {
  run(callback) {
    // Check if sender is in list of admins, stored in the system environment
    // as a comma-separated string
    if (adminNumbers.indexOf(this.fromNumber) < 0) {
      return callback(null, 'broadcast Not Authorized')
    }

    // Create a new SMS Notify binding for this user's phone number
    //only notify users who are tagged with 'test'
    notify.notifications.create({
      tag: ['test'],
      body: this.commandText
    }).then((response) => {
      callback(null, 'broadcast test Success')
    }).catch(err => {
      console.log(err)
      callback(err, 'broadcast test Fail')
    })
  }
}

// Handle incoming SMS commands ####################
exports.handler = (context, event, callback) => {
  // Get command text from incoming SMS body
  let cmd = event.Body || ''
  cmd = cmd.trim().split(' ')[0].toLowerCase()

  // Default to help command
  let cmdInstance = new HelpCommand(event, context)

  // Choose other commands as appropriate
  switch(cmd) {
    case 'test': cmdInstance = new TestCommand(event, context); break;
    case 'sendtest': cmdInstance = new BroadcastTestCommand(event, context); break;

  }

  // Execute command
  cmdInstance.run((err, message) => {
    let twiml = new twilio.twiml.MessagingResponse()
    if (err) {
      console.log(err)
      message = 'There was a problem with your request. Try again!'
    }
    twiml.message(message)
    callback(null, twiml)
  })
}

类TestCommand扩展命令{
运行(回调){
//为此用户的电话号码创建新的SMS Notify绑定
//并尝试使用关键字“test”标记用户
notify.bindings.create({
身份:这是fromNumber,
bindingType:'sms',
地址:这是fromNumber,
标签:['test']
})。然后((响应)=>{
回调(null,“测试消息成功”)
}).catch(错误=>{
回调(错误,“测试消息失败”)
})
}
}
类BroadcastTestCommand扩展命令{
运行(回调){
//检查发件人是否在系统环境中存储的管理员列表中
//作为逗号分隔的字符串
if(adminNumbers.indexOf(this.fromNumber)<0){
返回回调(null,“广播未授权”)
}
//为此用户的电话号码创建新的SMS Notify绑定
//仅通知标记有“测试”的用户
notify.notifications.create({
标签:['test'],
正文:this.commandText
})。然后((响应)=>{
回调(null,“广播测试成功”)
}).catch(错误=>{
console.log(错误)
回调(错误,“广播测试失败”)
})
}
}
//处理传入的SMS命令####################
exports.handler=(上下文、事件、回调)=>{
//从传入的SMS正文获取命令文本
设cmd=event.Body | |“”
cmd=cmd.trim().split(“”)[0].toLowerCase()
//默认为帮助命令
让cmdInstance=new HelpCommand(事件、上下文)
//根据需要选择其他命令
开关(cmd){
案例“test”:cmdInstance=newtestCommand(事件、上下文);break;
案例“sendtest”:cmdInstance=new BroadcastTestCommand(事件、上下文);中断;
}
//执行命令
cmdInstance.run((错误,消息)=>{
让twiml=new twilio.twiml.MessagingResponse()
如果(错误){
console.log(错误)
消息='您的请求有问题。请重试!'
}
twiml.message(消息)
回调(null,twiml)
})
}

其他任何人都可以在这件事上大发雷霆。。 绑定上的Twilio文档会把你甩了

因为参数不是“tags”,而是“tag”

这很有效

class TestCommand extends Command {
  run(callback) {
    // Create a new SMS Notify binding for this user's phone number
    //and try to tag the user with keyword 'test'
    notify.bindings.create({
      identity: this.fromNumber,
      bindingType: 'sms',
      address: this.fromNumber,
      tag: ['test']
    }).then((response) => {
      callback(null, 'test Message success')
    }).catch(err => {
      callback(err, 'test message fail')
    })
  }
}