Twilio 根据传入电话号码转发来电



我最近将我的家庭座机号码移植到Twilio。现在,我创建了一个非常基本的呼叫转移TwiML Bin,将这个以前的固定电话号码的任何来电转接到我的手机:

<Response>
<Dial>mycellnumber</Dial>
</Response>

我想做的是有一些逻辑,根据与联系人列表中的号码匹配的传入呼叫者将传入呼叫转发到不同的单元格,如果传入号码不在联系人列表中,则默认转发。

例如,如果传入呼叫来自联系人列表中的号码Cell-X则将呼叫转接给Cell-X,否则如果在联系人列表中Cell-Y转发给Cell-Y,否则可能会转到云语音邮件或其他号码。

有没有办法在TwiML垃圾箱或工作室中做这样的事情,还是太复杂了?也许是任务路由器?这是住宅,所以我希望它对呼叫者不可见,而不是像 IVR 解决方案这样的东西,提示呼叫者按他们想要联系的人的号码。

我没有运气通过查看 Twilio 文档或搜索示例来找到具有此类逻辑的呼叫转移解决方案。请帮忙!

你可以用Twilio函数来做到这一点。


假设您的 Cell-X 列表如下所示:

const cellXContactList = ["+17782001001", "+17782001002", "+17782001003"];

您的 Cell-Y 列表如下所示:

const cellYContactList = ["+17782001004", "+17782001005", "+17782001006"];

然后,您可以使用如下所示的内容分发来电:

if (cellXContactList.length && cellXContactList.indexOf(event.From) !== -1) {
// caller number found in Cell-X contact list
destinationPhoneNumber = "+17781001001";
} else if (cellYContactList.length && cellYContactList.indexOf(event.From) !== -1) {
// caller number found in Cell-Y contact list
destinationPhoneNumber = "+17781001002";
}

以下是该函数的完整代码(替换为您的电话号码(:

// forward calls based on the incoming phone number
exports.handler = function (context, event, callback) {
// reference the Twilio helper library
const twiml = new Twilio.twiml.VoiceResponse();
// contacts lists
const cellXContactList = ["+17782001001", "+17782001002", "+17782001003"];
const cellYContactList = ["+17782001004", "+17782001005", "+17782001006"];
// if not in any contact list forward to this number
let destinationPhoneNumber = "+17781001000";
if (cellXContactList.length && cellXContactList.indexOf(event.From) !== -1) {
// caller number found in Cell-X contact list
destinationPhoneNumber = "+17781001001";
} else if (cellYContactList.length && cellYContactList.indexOf(event.From) !== -1) {
// caller number found in Cell-Y contact list
destinationPhoneNumber = "+17781001002";
}
twiml.dial({}, destinationPhoneNumber);
// return the TwiML
callback(null, twiml);
};


您可以在 (https://www.twilio.com/console/functions/manage( 的 Twilio 控制台中创建 Twilio 函数。从"空白"函数模板开始,然后替换为上面的代码。

创建并发布函数后,可以将 Twilio 号码配置为在"有呼叫进来"(https://www.twilio.com/console/phone-numbers/incoming(时运行它。

最新更新