[英]returning empty object Nodejs adding attributes to twilio conversations API
我正在使用 twilio 对话 Api 创建一个小的短信聊天应用程序。 我需要设置一个属性 object,但是当我像下面那样设置它时,它只会返回空。 有哪位twilio高手知道怎么解决吗?
从文档中注意:
属性 -
一个可选的字符串元数据字段,您可以使用它来存储您想要的任何数据。 如果指定,字符串值必须包含结构上有效的 JSON。 请注意,如果未设置属性,将返回“{}”。
await subClient.conversations.services(convoServiceSid)
.conversations
.create({
attributes: {read: "false"} // when I fetch conversation, this attributes is empty object....
})
.then(conversation => console.log(conversation.sid));
因此,在文档中它说 The string value must contain STRUCTURALLY VALID JSON
解决方案如下
await subClient.conversations.services(convoServiceSid)
.conversations
.create({
attributes: '{"read": "false"}' <-- needed to wrap object in quotes, also need to wrap key in quotes! success!
})
.then(conversation => console.log(conversation.sid));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.