Twilio 根据来电 phone 号码转接来电

Twilio forward incoming calls based on the incoming phone number

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

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

我想做的是根据来电者与联系人列表中的号码相匹配的逻辑,将来电转发到不同的单元格,如果来电号码不在联系人列表中,则默认转发.

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

有没有办法在 TwiML Bin 或 Studio 中做这样的事情,还是太复杂了?也许任务路由器?这是住宅,所以我希望呼叫者看不到它,而不是像 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";
}

下面是该函数的完整代码(替换为您的 phone 数字):

// 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 函数。从 "Blank" 函数模板开始,然后替换为上面的代码。

创建并发布函数后,您可以将 Twilio 编号配置为 运行 它 "A CALL COMES IN" (https://www.twilio.com/console/phone-numbers/incoming)。