【问题标题】:Is it possible to trigger a flow based on a condition within a function for SMS routing是否可以根据 SMS 路由功能中的条件触发流程
【发布时间】:2022-12-03 18:56:39
【问题描述】:

我有一个简单的流程,可以将传入的 SMS 消息发布到 slack。我还有一个功能可以让我发送和接收 SMS 消息。 (即如果短信来自 MY_NUMBER 并且消息以 +12121212 开头:那么它会将消息发送到 +12121212。

如果消息不是来自 MY_NUMBER,它将把 SMS 转发给 MY_NUMBER)

我希望函数触发流程而不是将消息转发到 MY_NUMBER。

我想在函数运行后触发我的流程:

例如

exports.handler = function(context, event, callback) {
    const MY_NUMBER = '+0000000000000';
         
    let twiml = new Twilio.twiml.MessagingResponse();
    if (event.From === MY_NUMBER) {
        const separatorPosition = event.Body.indexOf(':');
        if (separatorPosition < 1) {
            twiml.message('You need to specify a recipient number and a ":" before the message.');
        } else {
            const recipientNumber = event.Body.substr(0, separatorPosition).trim();
            const messageBody = event.Body.substr(separatorPosition + 1).trim();
            twiml.message({ to: recipientNumber }, messageBody);
        }
    } else {  ***MY FLOW SHOULD BE TRIGGERED HERE***
      // the above line should replace  `twiml.message({ to: MY_NUMBER }, `${event.From}: ${event.Body}`);`    
    }
    callback(null, twiml);
};

【问题讨论】:

    标签: javascript twilio slack


    【解决方案1】:

    您可以通过以下代码 sn-p 从 Twilio Functions 触发 Studio 流程:

    
    exports.handler = function (context, event, callback) {
      const client = context.getTwilioClient();
    
      client.studio.v2.flows('<Flow ID>')
        .executions
        .create({ to: recipientNumber, from: MY_NUMBER })
        .then(execution => {
          return callback(null, "hello"); // You could return something else as well
        }
    };
    

    您可以在控制台中找到流的 ID(或者当您单击根元素并检查 Flow Configuration 时):

    【讨论】:

      【解决方案2】:

      您可以使用此 android 应用程序将收到的短信重定向到 slack https://play.google.com/store/apps/details?id=com.sms.pipe

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-11-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多