dotxxh0998 2014-07-09 12:28
浏览 74
已采纳

拨出呼叫的Twilio来电显示

In my web application I have used Twilio api for making calls,

params = {"PhoneNumber": 'xxxx123'};
params = {"callerId": 'aaaa987'};
params["PhoneNumber"] = 'xxxx123';
params["callerId"] = 'aaaa987';
Twilio.Device.connect(params); 

But in receiver phone/twilio call logs did not get from number aaaa987, it is some other number like xyz567 every time.

How can I set from number for Twilio outgoing calls ?

  • 写回答

1条回答 默认 最新

  • duanmou9228 2014-07-09 12:56
    关注

    Twilio evangelist here.

    So to make sure I understand your question:

    1. You want to use the Twilio Client for JavaScript to make a phone call from a browser to a regular PSTN phone
    2. You want to have the Client pass parameters to Twilio to set the phone number and caller ID of the call to the PSTN phone

    Assuming I understand your question correctly, it looks like you are on the right track, passing an array of values into the Connect function. Now, what Twilio will do with that array is we will take each item in the array and convert it into a parameter that we send with the HTTP request we make to the Voice Request URL you have configured for your TwiML app.

    Based on the tags you set for your question, it looks like you are using PHP? If that's correct then you would just set the Voice URL to a PHP page that you have hosted on the internet.

    That PHP page can use the $_REQUEST object to access the HTTP parameters Twilio is including in its request and use them to dynamically generate TwiML. In your case since you want to have Twilio dial out to another phone number, you are going to need to generate TwiML containing the <Dial> verb.

    Here is a sample that shows how you can use the Twilio PHP Helper library to generate TwiML:

    $response = new Services_Twilio_Twiml();
    $response->dial($_REQUEST['PhoneNumber'], array(
      'callerId' => $_REQUEST['callerId']
    ));
    print $response;
    

    In this case I am grabbing the PhoneNumber and callerId parameters from the HTTP request made by Twilio and injecting them into the dial method. This would result in the helper library generating some TwiML that looks like this:

    <Response>
        <Dial callerId="aaaa987">xxxx123</Dial>
    </Response>
    

    Your PHP page returns the generated TwiML to Twilio in response to Twilios HTTP request. Twilio then executes the TwiML making cool things happen, like a phone call to the number you've specified.

    If you want a bit more of a step-by-step walk-through for Twilio Client for JavaScript, I'd suggest talking a look at the Twilio Client for JavaScript Quickstart. Its available in PHP and will take you through using Client for both inbound and outbound phone calls, including setting up a server side application in PHP to generate and return TwiML and also passing parameters into that PHP file.

    Hope that helps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?