当我们使用rest api拨打电话时,我们在该url参数上使用了什么twiml [英] when we make call using rest api then what twiml we use on that url parameter
问题描述
我正在使用其余api创建呼叫-
I am Creating the call using the rest api-
try{
// Initiate a new outbound call
$call = $this->client->calls->create(
// to call.
"num2",
// Step 5: Change the 'From' number below to be a valid Twilio number
// that you've purchased or verified with Twilio.
"num1",
array("url" => "url-tw",
'IfMachine'=>'Continue')
);
echo "Started call: " . $call->sid;
} catch(Exception $e){
echo "Error: " . $e->getMessage();
}
在url-tw上应该使用什么twiml不能断开呼叫.
and on the url-tw what twiml should I use which can't disconnect the call.
在使用TwiML处理呼叫之前,但现在我必须检测到AnsweredBy选项,该选项仅在使用REST API进行呼叫时才可用.
Before I was handling the call using the TwiML but now I have to detect the AnsweredBy option which is only available if I make the call using the REST API so.
我使用的是我以前使用twiML拨打电话时使用过的相同twiml,例如使用<Dial>
可以再次拨打电话,但是如果我不使用任何twiml,它将断开通话.我错了.
for now I m using the same twiml I have used before when I was making calls using the twiML like use the <Dial>
which let to dial again but if I dont use any twiml it disconnect the call.So any advice where I m going wrong.
推荐答案
此处是Twilio的传播者.
Twilio evangelist here.
url
参数的值应该是可公开访问的URL,该URL返回 TwiML 包含您希望Twilio对调用方执行的指令.
The value of the url
parameter should be a publicly accessible URL that returns TwiML containing the instructions that you want Twilio to execute to the caller.
您的PHP开始调用的样子:
Your PHP to start the call would look like:
// Initiate a new outbound call
$call = $this->client->calls->create(
"num2",
"num1",
array("url" => "http://example.com/answer.php", 'IfMachine'=>'Continue')
);
然后在answer.php
中,您可以做两件事:
Then in answer.php
, you can do two things:
- 检查
AnsweredBy
参数以查看Twilio是否检测到机器或人. - 根据该值生成您要返回的Twiml
例如,要说与机器对人类不同的东西,您可以在PHP中执行以下操作:
For example to say something different to a machine v a human, you could do something like this in your PHP:
<?php
header("content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
?>
<?php if ($_REQUEST['AnsweredBy']=='machine'): ?>
<Response>
<Say>Hello machine</Say>
</Response>
<?php else: ?>
<Response>
<Dial>+15555555555</Dial>
</Response>
<?php endif ?>
希望有帮助.
这篇关于当我们使用rest api拨打电话时,我们在该url参数上使用了什么twiml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!