首页 > 解决方案 > How to get chat id in telegram bot without message from user? Is it even real?

问题描述

I am making a telegram bot who will work like schedule and it is deployed on heroku. When server is restarting, chat id is clearing and the bot is not working

So I have a question. Can I somehow get chat id without user message? And is it even real?

标签: javascriptnode.jstelegram-botnode-telegram-bot-api

解决方案


你必须备份那些id和你的会话文件

会话文件包含有关您与电报的所有交互的信息(聊天、按摩......)

在服务器重新启动之前,保存会话文件记住保存会话文件并在重新启动后将它们再次复制到它们的目录中,就像机器人没有发生任何事情一样,因为所有内容都保存在这些文件中。

将您的机器人连接到数据库系统。mysql ,.....或者只是将聊天 id (或 peer id )编号(在更新数组中)保存到文件(txt , json ,...)中,然后在服务器重新启动后使用它们。

如果您丢失了会话文件,就好像机器人的内存被擦除了


推荐阅读