twilio - 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
解决方案
有没有办法在 Azure 门户中做到这一点?
抱歉不行。每个 Web App Bot/Bot Channels Registration 只能与一个 Twilio 号码相关联。
有没有更好或更简单的方法?
您使用的方法可能是最简单的。我能想到的唯一其他可行的选择是使用Twilio SMS API。流程将是这样的:
创建一个运行 Twilio SMS API 代码的服务器,该代码基本上只是通过DirectLine API将消息转发给机器人。用户向该服务器发送消息
对于发送给机器人的每个活动,请包括数字:
Activity.ChannelData = new { fromNumber: <555-555-5555> }
。服务器将消息转发给机器人处理您的机器人中的活动,并将其重新附加
fromNumber
到机器人的传出活动,以便您的 Twilio API 服务器知道将传出消息发送到哪里。Bot 将回复发送到服务器然后让 Twilio API 服务器发送
Activity.Text
给用户。服务器将消息从机器人转发给用户
同样,您使用的路线可能是最容易开发和维护的。
推荐阅读
- bash - 将数字参数范围传递给 Bash 脚本
- editor - “视图 -> 组 -> 最大列数:2”的 Sublime 3 键绑定
- javascript - 将字符串添加到变量中会在 javascript onkey 函数中添加“\”
- django - Django - 子模板从父模板扩展 CSS 但无法使用其 CSS
- javascript - 聚焦元素时,页面不会在 Firefox 和 IE 中滚动?
- laravel - 如何上传数组输入类型的图像
- javascript - 错误:无效的 Chai 属性:toBe。您指的是 “to” 吗?
- node.js - nexe、节点和 sqlite3
- python - python将beautifulsoup输出转换为dict/json
- android - GridLayoutManager - 获取项目的行索引