【问题标题】:Cloud function ids not responding to Telegram webhook云功能 ID 未响应 Telegram webhook
【发布时间】:2020-12-08 17:22:21
【问题描述】:

我正在尝试编写我的第一个电报机器人。我决定使用谷歌云功能来执行机器人逻辑。我正在使用的代码是

const bot = new Telegraf(config().bot.token)
bot.start(ctx => ctx.reply('Welcome'))
bot.hears('hi', ctx => ctx.reply('Hey there'))

bot.telegram.setWebhook(
  `https://us-central1-some-project.cloudfunctions.net/${process.env.FUNCTION_TARGET}`,
);

exports.bot = https.onRequest((req, res) => {
  bot.handleUpdate(req.body, res);
})

问题是在一段时间不活动后,机器人停止响应消息。重新部署功能后,它再次开始工作。我什至不知道如何调试这个问题。

【问题讨论】:

  • 我建议的第一件事是学习一些关于 GCP Cloud Logging 的知识。从那里你应该能够看到你的函数执行产生的日志,看看是否有任何错误消息或其他诊断产生,可以为我们提供关于问题可能是什么的线索。
  • @Kolban 查看日志,有很多超时,例如Function execution took 60011 ms, finished with status: 'timeout'。这正常吗?奇怪的是,它几乎以零延迟执行了将近一天,然后突然开始出现这些超时
  • 这似乎是说确实正在调用云函数,但该函数没有在 60 秒内结束,并且被 GCP 显式终止。这正常吗……通常不会。我会调查您的云功能代码在做什么以及为什么它在 60 秒内没有响应。后端掉线了吗?
  • 能否请您提供更多详细信息,也许 CF 是做什么的?

标签: node.js firebase google-cloud-functions telegram-bot telegraf


【解决方案1】:

GCF 超时,因为需要为不受支持的消息定义回退, 像这样的

bot.on('message', ctx => ctx.reply('Not supported command'));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-07-15
    • 1970-01-01
    • 1970-01-01
    • 2019-12-18
    • 1970-01-01
    • 1970-01-01
    • 2019-06-26
    • 2021-12-01
    相关资源
    最近更新 更多