简体   繁体   English

来自 webhook 的传入 twilio 正文中没有消息

[英]No message in incoming twilio body from webhook

In all the twilio docs and examples I've read, the incoming body from an incoming sms webhook has a "message" property, however all I am getting is a single, ugly string.在我读过的所有 twilio 文档和示例中,来自传入 sms webhook 的传入正文具有“消息”属性,但是我得到的只是一个丑陋的字符串。

// incoming request
{
    "body":"ToCountry=US&ToState=CA&SmsMessageSid=SMa40a4ba8fec941e6636ebd82aabxxx&NumMedia=0&ToCity=LAYTONVILLE&FromZip=45251&SmsSid=SMa40a4ba8fec941e6636ebd82aab1a080&FromState=OH&SmsStatus=received&FromCity=CINCINNATI&Body=message4321&FromCountry=US&To=%2B17074140303&ToZip=95417&NumSegments=1&MessageSid=SMa40a4ba8fec941e6636ebd82aab1a080&AccountSid=ACb237933f0f845f5cbe9fcbe67d3b604e&From=%2B15135057457&ApiVersion=2010-04-01",
    ...
}

What I want is in this field Body=message4321 but I have to parse a string to do so.我想要的是在这个字段中Body=message4321但我必须解析一个字符串才能这样做。

I feel like I'm doing something wrong.我觉得我做错了什么。 Why does it look like query params?为什么它看起来像查询参数? I set up the webhook by going into my phone number, then under messaging having "A message comes in Webhook POST https://my-url "我通过输入我的电话号码来设置 webhook,然后在消息下显示“Webhook POST https://my-url 中出现一条消息”

I guess twilio sends the form as type: application/x-www-form-urlencoded.我猜 twilio 将表单发送为类型:application/x-www-form-urlencoded。 Using qs npm package is cleanest way to parse.使用 qs npm 包是最干净的解析方式。

qs.parse(queryString).Body;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM