如何使用 Twilio 从软电话 (Sipdroid) 拨打电话? [英] How can I make an outgoing phone call from a soft phone (Sipdroid) using Twilio?

查看:32
本文介绍了如何使用 Twilio 从软电话 (Sipdroid) 拨打电话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经设置了一个 SIP 域,因此我可以将使用 Twilio 购买的号码的呼叫转移到我的软电话.

I've set up a SIP domain, so I can forward calls from numbers I bought with Twilio to my soft phone.

但我也想从软电话拨出 PSTN 号码.我怎样才能做到这一点?我怀疑它涉及 Elastic SIP Trunk,但我不知道如何配置它.

But I also want to make outgoing calls to PSTN numbers from the soft phone. How can I do this? I suspect it involves an Elastic SIP Trunk, but I can't figure out how to configure it.

推荐答案

我使用没有弹性中继的 PHP 帮助程序库做到了.

I did it using the PHP helper library without elastic trunking.

在 Twilio 控制台的 SIP 域设置中,您可以设置语音配置的请求 URL.似乎当您尝试通过 SIP 向任何号码拨打电话时,Twilio 会请求此 URL 并随请求发布所有呼叫信息变量.其中一个变量是Called",其格式为 sip:0123456789@yourdomain.sip.us1.twilio.com:5060,其中 0123456789 是您拨打的号码

In the SIP domains settings on your Twilio console you can set a request URL for voice configuration. It seems that when you try to make an outgoing call to any number via SIP then Twilio requests this URL and POSTs all the call info variables with the request. One of the variables is 'Called' which takes the format sip:0123456789@yourdomain.sip.us1.twilio.com:5060 where 0123456789 is the number you have dialled

所以我们需要做的就是从字符串中删除号码,然后让 Twilio 拨打它.很简单.

So all we need to do is strip the number out of the string and then ask Twilio to dial it. Easy enough.

我创建了这个 php 文件,我在英国,所以它格式化了号码以使用英国国家代码拨打电话.对于其他国家/地区,您必须对其进行一些更改.

I created this php file, I'm in the UK so it formats the number to call with the UK country code .You will have to change it a bit for other countries.

<?php
require_once './vendor/autoload.php';
use Twilio\Twiml;
$calledNo = explode("@", $_POST['Called']); // Splits sip:0123456789@yourdomain.sip.us1.twilio.com:5060 into an array at the @ character
$callthis = '+44'.substr($calledNo[0], 5); // $calledNo[0] is set to sip:0123456789, this line strips the first 5 characters leaving 123456789 and adds +44 to the start (UK country code)
$response = new Twiml();
$dial = $response->dial(['callerId' => '{Your caller id}']); // Your caller ID must be validated or the outgoing call will fail
$dial->number($callthis); // Calls +44123456789

echo $response;

将您的语音 URL 指向此文件,您就大功告成了.

Point your voice URL at this file and you're all set.

这篇关于如何使用 Twilio 从软电话 (Sipdroid) 拨打电话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆