gpt4 book ai didi

twilio - 如何使用短信 Hook 延迟对用户消息的响应?

转载 作者:行者123 更新时间:2023-12-02 00:13:51 26 4
gpt4 key购买 nike

我的目标是延迟 1-5 分钟回复用户消息。但是在文档中我看不到任何设置超时的能力。这是我的代码:

app.post('/sms', async (req, res) => {
const twiml = new MessagingResponse();
const msg = req.body.Body;
const toroMsg = await toroProcess(msg);
twiml.message(toroMsg);
res.writeHead(200, {'Content-Type': 'text/xml'});
res.end(twiml.toString());
});

最佳答案

此处为 Twilio 开发人员布道师。

responding with TwiML 时,无法在 Twilio 中延迟对消息的响应。 .

相反,您需要控制应用程序中的延迟,并且 use the Twilio REST API to send the message稍后。

看起来您在问题中使用了 Express 和 Node。最简单的方法是像这样使用 setTimeout:

const twilioClient = require('twilio')(process.env.TWILIO_ACCOUNT_SID, process.env.TWILIO_AUTH_TOKEN);

app.post('/sms', async (req, res) => {
const msg = req.body.Body;
const toroMsg = await toroProcess(msg);
setTimeout(() => {
twilioClient.messages.create({
to: req.body.From,
from: req.body.To,
body: toroMsg
})
}, 60 * 1000)
const twiml = new MessagingResponse();
res.writeHead(200, {'Content-Type': 'text/xml'});
res.end(twiml.toString());
});

由于这依赖于当前正在运行的进程,您可能希望使用更具弹性的东西,以便在进程重新启动或崩溃时不会丢失消息。类似于 AgendaBull .

如果这有帮助,请告诉我。

关于twilio - 如何使用短信 Hook 延迟对用户消息的响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57669902/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com