猿问

twilio 如何使用 PHP 和 JavaScript 从队列中选择呼叫

我正在使用 twiml 创建一个呼叫排队系统,一切正常,就像我可以接听电话和排队呼叫,但我无法从队列中接听电话,我写了这段代码,但它不工作


当有来电时,这是我的 twiml:


我接到第一个电话,其他后续电话排队,但现在第一个电话结束后,我无法选择排队的电话。当我挂断电话时,它会将第一个呼叫者排在队列中。


header("Content-type: text/xml");


$name = $_POST['name'];

$email = $_POST['email'];


$message = '<?xml version="1.0" encoding="UTF-8"?>

<Response>

    <Say>Please wait and one of our agents will be with you shortly.</Say>

    <Dial>

        <Client>joey</Client>

        <Parameter name="name" value="'.$name.'" />

        <Parameter name="email" value="'.$email.'" />

    </Dial>

    <Say>Our agents are still busy please hold.</Say>

    <Enqueue waitUrl="waiting.php">Support</Enqueue>

</Response>';


echo $message;

因此,要从队列中接听电话,我发现了这个 Twilio PHP 代码:


use Twilio\TwiML\VoiceResponse;


$support = $_REQUEST['To'];


$response = new VoiceResponse();

$response->say("You will now be connected to the first caller in the queue.");

$dial = $response->dial('');

$dial->queue($support, ['url' => 'about_to_connect.php']);


echo $response;

使用此 JavaSCript 代码


 queueButton.click(function() {

        Twilio.Device.connect({

            To: 'Support'

        });

    });

在这里,我想按照这个答案Twilio 将代理连接到队列中的呼叫


但是当我单击一个按钮来接听电话时,什么也没有发生,而是我收到了这个 js 错误


twilio.js:7100 Received an error from the gateway: {code: 31002, connection: Connection, message: "Connection Declined", twilioError: Error


code: 31005

description: "Connection error"

explanation: "A connection error occurred during the call"

总而言之,我只需要一个关于如何将代理连接到队列的解决方案,例如查看队列中有多少呼叫并能够从队列中选择它们


倚天杖
浏览 95回答 1
1回答

凤凰求蛊

我想到了。所以要调用队列,我需要第二个号码,我可以用它来调用队列,但我没有第二个号码,所以因为我有 twiml Gather 的 input.php 文件,我做了一个 if 语句检查是否用户呼叫是代理或只是客户,如果是代理我拨打队列if($_POST['user_type'] == 'agent'){&nbsp; <Response>&nbsp; &nbsp; <Dial>&nbsp; &nbsp; &nbsp; &nbsp; <Queue url="about_to_connect.xml">my_queue_name</Queue>&nbsp; &nbsp; </Dial></Response>}else{&nbsp; //My Gather here}为了能够检查用户是代理还是客户,当我调用队列时,我传递了一个名为 user_type 的自定义变量:let connection = Twilio.Device.connect({&nbsp; "user_type": "agent"});所以我可以打电话给我的队列。那时我意识到 twiml 很棒,它的工作是控制调用。我建议您购买第二个号码以避免减慢您的通话速度。
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答