简体   繁体   English

从 twilio webhook 获取值

[英]getting a value from a twilio webhook

I'm trying to get "my test message" from this webhook event data.我正在尝试从此 webhook 事件数据中获取“我的测试消息”。 I'm kinda new to this but below is what I've tried我对此有点陌生,但以下是我尝试过的

webhook received... 
{"interactionDateUpdated":"2021-12-18T18:08:34.222Z","interactionData":"{\"body\":\"my test message\"}","interactionDateCreated":"2021-12-18T18:08:34.222Z","interactionType":"Message",....

my code....我的代码....

const interactionType = event.interactionType;
  console.log("interaction type: ", interactionType)
//interaction type: Message (as expected)
  
  const eventText = event.interactionData;
  console.log("event text: ", eventText);
//event text: {"body":"my test message"}

  const message = Object.values(eventText);
  console.log("message: ", message)
//message: [ '{', '"', 'b', 'o', 'd', 'y', '"', ':', '"', 'm', 'y', ' ', 't', 'e', 's', 't', ' ', 'm', 'e', 's', 's', 'a', 'g', 'e', '"', '}' ] (I'm trying to get "my test message")

also tried this
  const messageBody = eventText["body"]
  console.log("message body?: ", messageBody)
//message body?: null (I'm trying to get "my test message")

I'm clearly not understanding correctly how to get this.我显然没有正确理解如何得到这个。

Appreciate it if someone could point out what i'm missing.如果有人能指出我所缺少的,将不胜感激。

Thanks, Jim谢谢,吉姆

You have to parse it the string to object before extracting value with Object.values在使用object提取值Object.values ,您必须将其解析为string

const message = Object.values(JSON.parse(eventText));

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

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