通过Twilio Studio将消息从WhatsApp推送到Twilio Flex会导致架构验证警告12200

时间:2019-01-16 13:43:42

标签: javascript twilio twilio-programmable-chat twilio-studio twilio-flex

我已经按照博客文章Twilio WhatsApp API and Flex in Minutes中所述设置了项目。

我遵循了说明,即使在两个不同的帐户上重复两次该过程之后,(通过沙箱)发送邮件时,也会出现以下错误:

  

cvc-complex-type.2.4.a:发现无效的内容(从元素'Enqueue'开始)。预期为“ {Sms,消息,重定向}”之一。

该任务未在Flex中显示。

我尝试检查WhatsApp发送的内容与SMS到达时发送的内容。这是一个简单的函数关于trigger.message的SMS的内容:

{
    EventType=onMessageSent,
    InstanceSid=IS5aa457db5a2d44049c95f2d0b2699f56,
    Attributes={\"proxied\":true}, 
    DateCreated=2019-01-16T12:37:43.664Z, 
    Index=3, 
    From=sms_g13aggbhlwpgk7tbah3llj2kyjpsvvju, 
    MessageSid=IM9123e909eeda41ac92890201a6c3f1b4, 
    Source=API, 
    AccountSid=ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX, 
    ChannelSid=CHbc79143368db4680a66c6c504103619f, 
    RetryCount=0, 
    ClientIdentity=sms_g13aggbhlwpgk7tbah3llj2kyjpsvvju, 
    WebhookType=studio, 
    To=CHbc79143368db4680a66c6c504103619f, 
    Body=Test Message, 
    ChannelAttributes={
        status=ACTIVE, 
        forwarding=true, 
        serviceNumber=sms_g13aggbhlwpgk7tbah3llj2kyjpsvvju, 
        twilioNumber=+1228xxxxxxx, 
        from=+44798xxxxxxx, 
        channel_type=sms, 
        proxySession=KC1be96a19ed42aca39f9b6a9f06c26997
    }, 
    WebhookSid=WHcfc83a43a7c2424693fd0053b8b00a01
}

这是WhatsApp消息显示的内容:

{
    ApiVersion=2010-04-01, 
    SmsSid=SMb44cfdb4854c41e9ee255032a5449199, 
    SmsStatus=received, 
    SmsMessageSid=SMb44cfdb4854c41e9ee255032a5449199, 
    NumSegments=1, 
    From=whatsapp:+44798xxxxxxx, 
    To=whatsapp:+1228xxxxxxx, 
    MessageSid=SMb44cfdb4854c41e9ee255032a5449199, 
    Body=Test Message, 
    AccountSid=ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX, 
    NumMedia=0
}

如您所见,ChannelAttributesChannelSid丢失了,而这正是Flex所使用的。

然后我尝试使用一个函数转换响应:

exports.handler = function(context, event, callback) {    
    let response;
    if (!event.message.ChannelAttributes) {
        response = {
            name: event.message.From,
            channelType: 'sms',
            channelSid: 'CHbc79143368db4680a66c6c504103619f'
        };
    }
    else {
        response = {
            name: "WhatsApp_" + event.message.ChannelAttributes.from,
            channelType: event.message.ChannelAttributes.channel_type,
            channelSid: event.message.ChannelSid
        };
    }

    const twilioResponse = new Twilio.Response();
    twilioResponse.setStatusCode(200);
    twilioResponse.appendHeader('Content-Type', 'application/json');
    twilioResponse.setBody(response);

    callback(null, twilioResponse);
};

并在Studio中分配属性,例如:

{
    "name":"{{widgets.MyFunction.body.name}}",
    "channelType":"{{widgets.MyFunction.body.channelType}}",
    "channelSid":"{{widgets.MyFunction.body.channelSid}}"
}

不幸的是,这显示了相同的错误。

0 个答案:

没有答案