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.

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

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题