You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Telegram Bot部署Google Cloud Functions后次日失效的问题及解决方法

Telegram Bot部署Google Cloud Functions后次日失效问题及解决方法

问题详情

使用Node.js搭配Telegraf库开发Telegram Bot,部署到Google Cloud Functions实现命令触发逻辑。本地运行正常,首次部署后的前10分钟也能正常工作(云函数默认超时设置为1分钟),但次日Bot无法正常响应命令。

原代码

// 导入依赖
bot.start((ctx) => {/* 业务代码 */});

bot.command('Instagram', (ctx) => { /* 业务代码 */ });

bot.command('Collaborazione', (ctx) => { /* 业务代码 */ });

bot.telegram.setWebhook('我的HTTPS触发器地址');

bot.launch();

exports.myBot = functions.https.onRequest(async (request, response) => {
    functions.logger.info('Hello logs!', { structuredData: true });
    return await bot.handleUpdate(request.body, response).then((rv) => {
        // 如果请求并非来自Telegram,rv会是undefined,但我们仍需返回200状态码
        return !rv && response.sendStatus(200);
    });
});

解决方法

将云函数的异步处理函数改为普通函数,并移除return语句,修改后的代码如下:

exports.myBot = functions.https.onRequest((request, response) => {
 bot.handleUpdate(request.body, response)
})

内容的提问来源于stack exchange,提问作者Gabriele Sabatino

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 22:28:16