dongtun3328 2016-10-19 13:37
浏览 30

在heroku上部署php消息传递应用程序并使用twilio发送消息

I am trying to deploy a sms application which is written in PHP and I am deploying it on Heroku and using Twilio to send messages. When someone sends a message on my Twilio number, this app will send an appropriate reply to that message. I am facing a problem with switch statement in this app. I am new to coding in PHP and I am unable to get this to work. I am pasting my code below. Please help me fix it. Thank you in advance.

<?php
    session_start();
    header("content-type: text/xml");
    switch ($answer) {
        case 'headache' : {
            print('OTC Crocin may help!');
            break;
        case 'stomachache' : {
            print('OTC Tylenol may help!');
            break;
        case 'cough' : {
            print('OTC Robitussin Cough may help!');
            break;
        case 'cold' : {
            print('OTC Aspirin may help!');
            break;  
        case 'vomiting' : {
            print('OTC Pepto-Bismol may help!');
            break;
        case 'headache doctor' : {
            print('Dr. Lorem Ipsum - Here is the address! Call at +1 xxx xxx xxxx');
            break;
        case 'stomachache doctor' : {
            print('Dr. Lorem Ipsum - Here is the address! Call at +1 xxx xxx xxxx');
            break;
        case 'cough doctor' : {
            print('Dr. Lorem Ipsum - Here is the address! Call at +1 xxx xxx xxxx');
            break;
        case 'cold doctor' : {
            print('Dr. Lorem Ipsum - Here is the address! Call at +1 xxx xxx xxxx');
            break;
        case 'vomiting doctor' : {
            print('Dr. Lorem Ipsum - Here is the address! Call at +1 xxx xxx xxxx');
            break;
    }




    $from   = $_POST['From'];
    $answer = $_POST['Body'];
    $reply  = array();


    echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
";
?>

<Response>
    <Sms>
            <?php
                if(is_array($reply)){
                    foreach($reply as $key => $value){
                        echo $value;
                    }
                }
                else{
                    echo $reply;
                }
            ?>
    </Sms>
</Response>
  • 写回答

1条回答 默认 最新

  • doucigua0278 2016-10-28 18:30
    关注

    Twilio developer evangelist here.

    You're responding to an incoming SMS message, however you are using the <Sms> TwiML verb. <Sms> is only used for sending an SMS message during a voice call.

    Instead, you want to use the <Message> TwiML verb which is for replying to SMS messages. So, the last part of your code should look like:

    <Response>
        <Message>
                <?php
                    if(is_array($reply)){
                        foreach($reply as $key => $value){
                            echo $value;
                        }
                    }
                    else{
                        echo $reply;
                    }
                ?>
        </Message>
    </Response>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算