简体   繁体   English

每天在指定时间发送消息的电报机器人

[英]Telegram bot that sends messages in assigned time every day

I'm trying to build a Telegram bot that enables to send messages 'in assigned time or date' and 'every day'我正在尝试构建一个 Telegram 机器人,它可以“在指定的时间或日期”和“每天”发送消息

Trying to look for a good example but failed to find one.试图寻找一个好的例子,但没有找到一个。 Because majority are related to crawling thing but mine isn't something to do with it.因为大多数都与爬行有关,但我的与它无关。 Just picture and text.只是图片和文字。

Do you have good examples that perfectly match with what I want?您有与我想要的完全匹配的好例子吗?

For doing that you don't need python-telegram-bot, you can do it with just "requests" and "telepot" modules为此,您不需要 python-telegram-bot,只需“请求”和“telepot”模块即可

I hope that you at least are well documented about BotFather .我希望您至少对BotFath有充分的记录。 And aquiring your chat ID, from here for example.例如,从这里获取您的聊天 ID。

And something like that should work:类似的东西应该有效:

import requests
import telepot

token = "your_TOKEN"
chat_id = "your_ID"
bot = telepot.Bot(token)

def send_message(text):
   url_req = "https://api.telegram.org/bot" + token + "/sendMessage" + "?chat_id=" + chat_id + "&text=" + text 
   results = requests.get(url_req)
   print(results.json())
   bot.sendPhoto(chat_id, 'URL_OF_YOUR_PHOTO')

send_message("YOUR_MESSAGE")

Then add a cronjob to run that script at the times you want.然后添加一个 cronjob 以在您想要的时间运行该脚本。

Cheers干杯

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM