-3

I'm trying to build a Telegram bot that enables to send messages 'in assigned time or date' and 'every day'

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?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
hyunseo
  • 55
  • 1
  • 5
  • there is a method called job_queue.run_daily() in [python-telegram-bot](https://python-telegram-bot.readthedocs.io/) library – Aditya Yadav Jan 01 '22 at 10:12
  • Do you want to send messages automatically "in assigned time" or you want just to enable bot to send something "in assigned time"? – wowkin2 Jan 04 '22 at 18:56

1 Answers1

0

For doing that you don't need python-telegram-bot, you can do it with just "requests" and "telepot" modules

I hope that you at least are well documented about BotFather. And aquiring your chat ID, from here for example.

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.

Cheers

damiasroca
  • 11
  • 3
  • Hi, thank you for your helpful answer! I tried to type as you've written and add schedule module like schedule.every(3).seconds.do...etc but it didn't work. Actually, I have no idea how to make them compatible. Can you give more advice to solve this problem? Thank you so much – hyunseo Jan 03 '22 at 06:07
  • Where do you plan to run this bot? Linux server, windows server, your machine? My advice, if you are using linux, is to run it as a [cronjob](https://en.wikipedia.org/wiki/Cron) – damiasroca Jan 03 '22 at 18:20