【问题标题】:Send a Whatsapp/SMS message with info obtained from a user with Autopilot发送一条 Whatsapp/SMS 消息,其中包含从使用 Autopilot 的用户处获得的信息
【发布时间】:2020-08-20 00:11:40
【问题描述】:

我制作了一个简单的机器人,它可以提供信息并从使用它的用户那里收集一些数据。例如,用户可以要求预约并提供他的手机。我想要做的是将 WA 或 SMS 消息发送到第三个号码,其中包含机器人收集的信息。这是收集部分的任务代码示例

"collect": {
            "name": "schedule_appt",
            "questions": [
                {
                    
                {
                    "question": "Let us your phone number and an expert will get in touch with you",
                    "name": "appt_phone_number",
                    "type": "Twilio.PHONE_NUMBER"
                }
            ]

现在,我想向另一个号码发送一条值为“Twilio.PHONE_NUMBER”的 WA 或 SMS 消息。是否可以使用 twilio 在机器人创建者中提供的选项,或者我应该为这种情况创建一些自定义代码?如果是这样,那将是最好的方法吗? PHP 应用程序,还是 Web 开发的东西?

我有点迷茫,所以任何建议都将不胜感激。

谢谢!

【问题讨论】:

    标签: twilio twilio-api twilio-php twilio-programmable-chat


    【解决方案1】:

    你可以这样做:

    {
        "actions": [
            {
                "collect": {
                    "name": "schedule_appt",
                    "questions": [
                        {
                            "question": "Let us your phone number and an expert will get in touch with you",
                            "name": "appt_phone_number",
                            "type": "Twilio.PHONE_NUMBER"
                        }
                    ],
                    "on_complete": {
                        "redirect": {
                            "method": "POST",
                            "uri": "https://xyz.twil.io/sostub"
                        }
                    }
                }
            }
        ]
    }
    

    Twilio Function(URL 的目标:https://xyz.twil.io/sostub 与您唯一的 Twilio 函数域匹配)

    exports.handler = async function(context, event, callback) {
        let twilioClient = context.getTwilioClient();
        let memory = JSON.parse(event.Memory);
        console.log("User Identifier: "+ event.UserIdentifier);
        console.log("Task: "+ event.CurrentTask);
        console.log(event.CurrentInput);
        let message = "Your Message Has been Sent!";
        let responseObject = {
            "actions": [
                {
                    "say": message
                }]
        };
        
        let sendSMS = () => { 
            try {   
            let result = twilioClient.messages
            .create({
               body: `Appointment Scheduled, Mobile Phone ${event.CurrentInput}`,
               to: '+14075551212',
               from: '+15095551212',
             });
             return result;
            } catch(e) {
              console.log(e);
              callback(e);
            }
        };
        
        let result = await sendSMS();    
        
        callback(null, responseObject);
    };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-10-25
      • 2016-12-12
      • 2017-02-04
      • 2018-11-26
      • 2019-09-19
      • 2013-10-08
      • 1970-01-01
      相关资源
      最近更新 更多