电报使用时间表消息

发布于 2025-02-01 07:38:48 字数 1953 浏览 2 评论 0原文

我想安排以特定UnixTime发送的电报机器人消息。

As from telegrams official api (https://core.telegram.org/api/scheduled-messages< /a>)应该通过设置Schedule_date标志来实现。

要安排一条消息,只需在sagech_date flag.sendmessage或messages.sendmedia中提供未来的unixtime。

但是我无法设置该标志。更确切地说,我什至不知道如何设置标志,或者我是否正在使用正确的API。

我尝试的是直接通过浏览器(也可以使用卷发)使用API​​,例如: https://api.telegram.org/botbot:token/sendmessage?chat_id = id = id =&text = text = text = test = test =

test通过 httpps://pypi.org/project/project/probrombotapi/pgrambotapi/#description https://telepot.readthedocs.io/en/latest/latest/latest/#send/ -a-message ,nor https://github.com/nickoara/nickoala/telepot

我想在Python环境中实现此功能,但是任何有效的建议都将不胜感激。

编辑: 我决定保存在数据库中某个Unixtime发送电报机器人消息的意图。然后,我创建一个无限的循环,该循环检查当前时间戳之前是否有任何未输入消息。如果循环检测到这样的消息,它将发送消息并设置标志,该消息已发送。

正如所承诺的,这是该行为中该行为的完全模拟示例: https://github.com/ Sokrates1989/nameTheCountDown-LightWeight

它可以创建一个可以传递名称和持续时间的机器人。持续时间通过后,它将发送带有传递名称的消息。基本上是一个简单的倒计时,您可以给几个名字,这些名字类似地运行。由于它是电报聊天,因此您可以通过修改聊天的Notificaiton来修改倒计时结束的方式。

这是动作中的机器人: http://t.me/nemethecountdownbot

I want to schedule a telegram bot message to be sent at a specific unixtime.

As from telegrams official api (https://core.telegram.org/api/scheduled-messages) that should be possible by setting the schedule_date flag.

To schedule a message, simply provide a future unixtime in the schedule_date flag of messages.sendMessage or messages.sendMedia.

However I was not able to set that flag. To be more precisely, I do not even know how to set a flag, or if I am using the correct api.

What I have tried is to use the api directly via the browser (could use curl as well) like so: https://api.telegram.org/botBOT:TOKEN/sendMessage?chat_id=ID&text=Test&schedule_date=1653503351

I also did not find any way to access this flag via https://pypi.org/project/pyTelegramBotAPI/#description https://telepot.readthedocs.io/en/latest/#send-a-message, nor https://github.com/nickoala/telepot.

I want to implement this feature in a python environment, but any working suggestion would be much appreciated.

EDIT:
I decided to save the intention to send a telegram bot message at a certain unixtime in a database. I then create an infinite loop that checks if there are any unsent messages before the current timestamp. If the loop detects such a message it sends the message and sets a flag, that that message has been sent.

And as promised, here is a fully dockerized example of that behaviour in action: https://github.com/Sokrates1989/nameTheCountDown-lightweight

It creates a bot that you can pass a name and the duration. Once the duration has passed it sends a message with the passed name. Basically a simple countdown that you can give several names, that run simltaniously. As it is a telegram chat, you can modify the way you are informed about the end of a countdown by modifying the notificaiton of that chat.

And here is the Bot in action: http://t.me/NameTheCountdownBot

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

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

发布评论

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

评论(2

眸中客 2025-02-08 07:38:48

我们不能通过bot api本身来做到这一点,并且sendmessage方法中没有schepe_date参数:
https://core.telegram.org.org/bots/api#sendmessage
您阅读的是电报客户,而不是机器人API消费者。

如果您真的不需要UnixTime,则可以简单地创建一个带有文本,CHAT_ID和PUSHSER_TIME列(例如22:15)的计划消息的表发送。然后发送消息并删除记录。

We can't do this by bot API itself, and there's no schedule_date parameter in sendMessage method:
https://core.telegram.org/bots/api#sendmessage
And what you've read is for Telegram clients, not bot API consumers.

If you don't really need unixtime, you can simply create a table for scheduled messages with a text, chat_id and a publish_time column (like 22:15), and run a command every minute to look if there's a message for current time to send. Then send the message and delete the record.

涙—继续流 2025-02-08 07:38:48

请注意,python-telegram-bot库具有用于调度任务的内置解决方案: Jobqueue 。此功能基于 apscheduler library 您也可以在没有python-telegram-bot的情况下使用。


免责声明:我当前是python-telegram-bot的维护者。

Note that the python-telegram-bot library has a built-in solution for scheduling tasks: The JobQueue. This feature is based on the APScheduler library, which you can ofc also use without python-telegram-bot.


Disclaimer: I'm currently the maintainer of python-telegram-bot.

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