[英]Nodejs Twilio API 3.x - messages.delete(…) is not a function
Was following this tutorial to try and delete sms messages and I can successfully retrieve an individual message via this code: 正在按照本教程尝试删除短信 ,我可以通过以下代码成功检索一条短信:
client.messages(sid).fetch()
.then((message) => {
console.log(message);
if (message.status === "received") {
client.messages(sid).delete() //failing here
.then(() => {
response.send('Message deleted');
})
.catch((err) => console.error(err));
}
})
The documentation example only shows how to remove the message body, not delete the messgae itself. 该文档示例仅显示如何删除消息正文,而不删除消息本身。 And when I console log
messages
, the only methods available are: 当我控制台日志
messages
,可用的唯一方法是:
{ create: [Function: create],
each: [Function: each],
list: [Function: list],
page: [Function: page],
getPage: [Function: getPage],
get: [Function: get] }
A note that I can successfully redact the message body, following the instructions here : 请注意,我可以按照此处的说明成功编辑邮件正文:
client.messages(sid).update({body: ''})
.then((message) => {
process.stdout.write(message.body);
response.send('message deleted');
})
I believe the method you are looking for is remove
. 我相信您正在寻找的方法是
remove
。 Modifying your code like below will actually remove the message: 如下所示修改您的代码实际上会删除该消息:
client.messages(sid).fetch().then((m) => {
if (m.status == "delivered") {
console.log("It's delivered")
console.log(m)
m.remove().then(() => console.log("message removed"))
}
})
You also need to take care of any media separately, as those are not deleted when deleting a message according to the documentation. 您还需要分别照顾任何媒体,因为根据文档删除消息时不会删除这些媒体。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.