首页 > 解决方案 > How to add a second Twilio SMS channel to a single Microsoft Bot Framework v4 app?

问题描述

I have a Microsoft Bot Framework v4 bot. It has a Twilio SMS channel. Both work. My goal is to add a second Twilio SMS phone number that points to the same bot.

I wrote the code in the server to read the RecipientId and RecipientName. I want the server to recognize which number the user texted to and respond depending on that data.

I wrote a class (MyBotCredentialProviderStd) which implements ICredentialProvider. It allocates and stores a SimpleCredentialProvider instance and passes calls through to that object. When it receives a IsValidAppIdAsync call it compares the app id to a (for now) static value corresponding to a second bot registration for the same server app. If match, return true. If not match, call the MS class. Same for the GetAppPasswordAsync method.

This code works. I can send text messages to the two Twilio SMS messages. The server reads the target phone number and replies.

Is there a way to do this in the Azure Portal? Is there a better or simpler approach?

Thanks,

Adam Leffert www.leffert.com

标签: twiliobotframeworkchannels

解决方案


有没有办法在 Azure 门户中做到这一点?

抱歉不行。每个 Web App Bot/Bot Channels Registration 只能与一个 Twilio 号码相关联。

有没有更好或更简单的方法?

您使用的方法可能是最简单的。我能想到的唯一其他可行的选择是使用Twilio SMS API。流程将是这样的:

  1. 创建一个运行 Twilio SMS API 代码的服务器,该代码基本上只是通过DirectLine API将消息转发给机器人。用户向该服务器发送消息

  2. 对于发送给机器人的每个活动,请包括数字:Activity.ChannelData = new { fromNumber: <555-555-5555> }服务器将消息转发给机器人

  3. 处理您的机器人中的活动,并将其重新附加fromNumber到机器人的传出活动,以便您的 Twilio API 服务器知道将传出消息发送到哪里。Bot 将回复发送到服务器

  4. 然后让 Twilio API 服务器发送Activity.Text给用户。服务器将消息从机器人转发给用户

同样,您使用的路线可能是最容易开发和维护的。


推荐阅读