如何使用Node-Telegram-bot-api在电信中获取上一个消息的消息ID?

发布于 2025-02-12 01:34:42 字数 544 浏览 1 评论 0原文

我正在使用node.js和node-telegram-bot-api库开发电报机器人。我想在聊天中获取上一条消息的ID。我该如何实现?

我尝试使用此https://api.telegram.org/botхххх:хххххх/getUpdates?offset= -1 但是它给出以下错误消息:

{"ok":false,"error_code":409,"description":"Conflict: can't use getUpdates method while webhook is active; use deleteWebhook to delete the webhook first"}

I'm developing a Telegram bot using Node.js and node-telegram-bot-api library. I want to get the id of the previous message in the chat. How can I achieve this?

I tried using this https://api.telegram.org/botХХХХ:ХХХХХХ/getUpdates?offset=-1
but it gives the following error message:

{"ok":false,"error_code":409,"description":"Conflict: can't use getUpdates method while webhook is active; use deleteWebhook to delete the webhook first"}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏末 2025-02-19 01:34:42

telegram docs

有两种接收机器人更新的方法 - 一方面getupdates方法,另一只手与webhooks。

后来,在

如果设置了一个传出的Webhook,此方法将无法使用。

基本上,有两种方法是如何接收电报机器人的更新(消息,新用户等)。一个通过getupdates方法 - 使用此方法时,您应该定期运行getupdates方法,以接收所有新的更新。

第二种方法是通过Webhook - 您设置了一个URL,每当您的机器人收到更新时,电报都会发送请求。在大多数情况下,这是一种更实用的接收更新的方法,尽管难以实施。

这两种方法是互斥的 - 如果您设置了Webhook,则不能使用getupdates方法。如果要使用getupdates方法,该解决方案是用 deletewebhook 方法。

As per Telegram docs:

There are two mutually exclusive ways of receiving updates for your bot - the getUpdates method on one hand and webhooks on the other.

Later, in the description of getUpdates method:

This method will not work if an outgoing webhook is set up.

Basically, there are two methods of how to receive updates (messages, new users etc.) of your Telegram bot. One is via getUpdates method - when using this method, you should run getUpdates method regularly to receive all the new updates.

The second method is via webhook - you set up a url where Telegram will send a request whenever your bot receives an Update. In most cases this is a more practical way to receive Updates, albeit a bit harder to implement.

These two methods are mutually exclusive - if you have webhook set up, you can't use getUpdates method. The solution, if you want to use getUpdates method, is to delete the webhook with the deleteWebhook method.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文