0

在 Twilio 中,他们有一个关于 php 中“电话调查”的示例。
电话投票有以下文件,make call.php、poll.php 和 process_poll.php。
拨打电话 php - 包含 SID 等并拨打电话。poll php - 在 Gather 标记中包含实际的投票问题。如此处所示:

<?php
require 'Services/Twilio.php';
$response = new Services_Twilio_Twiml();
$gather = $response->gather(array(
    'action' => 'php url to hit',
    'method' => 'GET',
    'numDigits' => '1'
));
$gather->say("Hi question one here");
$gather->say("From 1 to 5 with 5 being the best service.  How would you rate?");

header('Content-Type: text/xml');
print $response;
?>

进程 poll php 包含他们选择选项后的下一步。出于篇幅的原因,我不会在后面发布 db 区域。

if (isset($choices[$digit])) {
    mysql_query("INSERT INTO `results` (`" . $choices[$digit] . "`) VALUES ('1')");
    $say = 'Ok got it.  Next question.';
} else {
    $say = "Sorry, I don't have that option.  Next question.";
}
// @end snippet
// @start snippet

$response = new Services_Twilio_Twiml();
$response->say($say);
$response->hangup();
header('Content-Type: text/xml');
print $response;

我的问题是我将如何添加其他问题。当前发生的是用户听到第一个问题。从电话垫中选择选项。在对他们的回答进行消息响应后,连接结束。我想再添加大约 3 个问题,然后再回答。如何实现?我会添加一个回复,将他们发送到第二组问题的另一个网址吗?

你能给我一些关于如何实现这一点的指导吗?我是一个php新手。

4

1 回答 1

0

来自 Twilio 的 Ricky 在这里。

好问题。有几种不同的方法可以构建它。您概述的为每个问题和响应设置单独的 URL 的方法绝对有效。在这种情况下,poll.php将变为poll1.php

<?php
require 'Services/Twilio.php';
$response = new Services_Twilio_Twiml();
$gather = $response->gather(array(
    'action' => 'php url to hit',
    'method' => 'GET',
    'numDigits' => '1'
));
$gather->say("Hi question one here");
$gather->say("From 1 to 5 with 5 being the best service.  How would you rate?");

header('Content-Type: text/xml');
print $response;
?>

您可能希望将其处理为process_poll1.php

if (isset($choices[$digit])) {
    mysql_query("INSERT INTO `results` (`" . $choices[$digit] . "`) VALUES ('1')");
    $say = 'Ok got it.  Next question.';
} else {
    $say = "Sorry, I don't have that option.  Next question.";
}
// @end snippet
// @start snippet

$response = new Services_Twilio_Twiml();
$response->say($say);
$response->redirect("php url to hit for next question");
header('Content-Type: text/xml');
print $response;

除了我在此文件中更改的名称外,还有一个关键更改。我们将使用TwiML 动词将用户移动到下一个投票问题,而不是挂断电话。用我们替换$response->hangup();的代码来做到这一点$response->redirect("php url to hit for next question");。您希望将其重定向到poll2.php,然后对该 go 执行收集操作process_poll2.php。然后根据需要继续回答尽可能多的问题。

让我知道这是否有帮助!

于 2015-09-15T15:30:14.707 回答