首页 文章

如何从Microsoft Bot Framework发送SMS(使用Twilio Channels )?

提问于
浏览
1

目前我的机器人在Facebook Messenger上,由员工使用 . 我希望我的机器人能够向一个人发送一条短信,以欢迎他/她加入我们的团队并凭借其凭据 .

我知道Microsoft Bot Framework集成了Twilio,所以我在这之后整合了Twilio Channels :https://docs.microsoft.com/en-us/bot-framework/channel-connect-twilio,所以我有一部电话,一切都配置得很好,因为我可以手动发送短信(来自Twilio的仪表板),它有效 .

问题是我现在不知道如何在机器人中使用它 .

const confirmPerson = (session, results) => {
  try {
    if (results.response && session.userData.required) {

      // Here I want to send SMS

      session.endDialog('SMS sent ! (TODO)');
    } else {
      session.endDialog('SMS cancelled !');
    }
  } catch (e) {
    console.error(e);
    session.endDialog('I had a problem while sending SMS :/');
  }
};

怎么做到这一点?

编辑:精确,欢迎员工的人是一名教练,只需从机器人发送短信,其中包含用户在首次使用后连接的webapp中使用的凭据欢迎

1 回答

  • 2

    Twilio开发者传道者在这里 .

    您可以通过sending an ad-hoc proactive message在bot框架中执行此操作 . 看来你在文档中找到了一个地址应该是什么样子 .

    既然你是这个API包装器的话 . 只需将 twilio 安装到您的项目中:

    npm install twilio
    

    然后收集您的帐户凭据并使用如下模块:

    const Twilio = require('twilio');
    
    const confirmPerson = (session, results) => {
      try {
        if (results.response && session.userData.required) {
    
          const client = new Twilio('your_account_sid','your_auth_token');
    
          client.messages.create({
            to: session.userData.phoneNumber,   // or whereever it's stored.
            from: 'your_twilio_number',
            body: 'Your body here'
          }).then(function() {
            session.endDialog('SMS sent ! (TODO)');
          }).catch(function() {
            session.endDialog('SMS could not be sent.');
          })
    
        } else {
          session.endDialog('SMS cancelled !');
        }
      } catch (e) {
        console.error(e);
        session.endDialog('I had a problem while sending SMS :/');
      }
    };
    

    让我知道这是怎么回事 .

相关问题