我正在尝试在Twilio中设置一些电话号码。我可以很好地调用它们,并在连接该特定客户端时正常连接(我正在使用唯一的URL来定义在调用特定号码时应拨打哪个客户端,例如:https://example.io/my/path/to/the/twiml/?attribute=CLIENT_IDENTIFIER)< / p>
当特定客户端未连接到我的应用程序时出现问题。发生这种情况时,会说出自动消息,但随后呼叫会断开。我希望它像普通电话一样响起,直到碰到语音邮件为止。那就是我的问题。这是我的PHP:
<?php
declare(strict_types=1);
use Twilio\TwiML\VoiceResponse;
require_once '../../../vendor/autoload.php';
$response = new VoiceResponse();
$response->say('This call may be monitored for quality assurance',
['voice' => 'woman', 'language' => 'us-EN']);
$dial = $response->dial('', [
'record' => 'record-from-ringing-dual',
'recordingStatusCallback' => 'https://example.com/my/callback/'
]);
$dial->client($_GET['CLIENT_IDENTIFIER'], [
'statusCallbackEvent' => 'completed',
'statusCallback' => 'https://example.com/my/callback/'
]);
echo $response;
我的状态回调未得到呼叫,因此我知道呼叫尚未完成。所以我的问题是这样的:
当无法连接到我通过的客户端时,如何使Twilio不立即断开连接?
答案 0 :(得分:2)
这里是Twilio开发人员的传播者。
如果<Dial>
无法连接,它将通过传递DialCallStatus
作为参数来对其action
attribute进行网络挂接。您可以使用更多TwiML来响应Webhook,以继续通话。
因此,您的初始PHP应该看起来像这样,并向<Dial>
添加了一个action属性:
<?php
declare(strict_types=1);
use Twilio\TwiML\VoiceResponse;
require_once '../../../vendor/autoload.php';
$response = new VoiceResponse();
$response->say('This call may be monitored for quality assurance',
['voice' => 'woman', 'language' => 'us-EN']);
$dial = $response->dial('', [
'record' => 'record-from-ringing-dual',
'recordingStatusCallback' => 'https://example.com/my/callback/',
'action' => 'https://example.com/my/action/'
]);
$dial->client($_GET['CLIENT_IDENTIFIER'], [
'statusCallbackEvent' => 'completed',
'statusCallback' => 'https://example.com/my/callback/'
]);
echo $response;
然后/my/action/
可以执行以下操作:
<?php
declare(strict_types=1);
use Twilio\TwiML\VoiceResponse;
require_once '../../../vendor/autoload.php';
$response = new VoiceResponse();
if ($_POST['DialCallStatus'] == 'completed') {
// the call succeeded, just end it
$response->hangup();
} else {
$response->say('The person you are calling cannot be reached right now. Please leave a message',
['voice' => 'woman', 'language' => 'us-EN']);
$response->record([
'action' => 'https://example.com/my/callback/'
]);
}
echo $response;
让我知道是否有帮助。
答案 1 :(得分:0)
twilio自动驾驶仪中的listen action似乎可以解决您正在寻找的等待时间。