Can you randomize a SMS response on Twilio?

时间:2017-04-10 02:29:25

标签: twilio twilio-api twilio-php

Is there a way to randomize responses on your Twilio number? For example I send a text to the local number I purchased and Twilio looks at a list of responses and sends a text back from this list randomly?

1 个答案:

答案 0 :(得分:0)

您需要自己在服务器上执行此操作。

创建一个end-point,一个返回TwiML(Twilio标记语言)的页面,将其托管在您的服务器上并将其公开给Internet。

使用终点的URL配置Twilio号码,we​​bhook选项。

以下是一些可以放在服务器上的示例代码,以帮助您入门:

<?php
    header("content-type: text/xml");
    echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";


$input = array("Friday", "Saturday", "Sunday");
$rand_key = array_rand($input);


?>

<Response>
    <Message><?php echo $input[$rand_key] . "\n"; ?></Message>
</Response>

更多信息:https://www.twilio.com/docs/quickstart/php/sms/hello-monkey

相关问题