从 twilio webhook 获取值

getting a value from a twilio webhook

我正在尝试从此网络钩子事件数据中获取“我的测试消息”。我对此有点陌生,但以下是我尝试过的方法

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

我的代码....

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")

我显然没有正确理解如何得到这个。

如果有人能指出我所缺少的,我将不胜感激。

谢谢,吉姆

在使用 Object.values

提取值之前,您必须将其解析为 stringobject
const message = Object.values(JSON.parse(eventText));