电报使用时间表消息
我想安排以特定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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我们不能通过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 insendMessage
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.
请注意,
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: TheJobQueue
. This feature is based on theAPScheduler
library, which you can ofc also use withoutpython-telegram-bot
.Disclaimer: I'm currently the maintainer of
python-telegram-bot
.