I’m trying to make a very simple Telegram Bot in Python that says "Hi" every minute. This is the code so far, but it does not post anything to my telegram.
import requests
import time
bot_token = "insert_token_here"
group_chat_id = "insert_group_chat_id_here"
def send_message(chat_id, text):
url = f"https://api.telegram.org/bot{bot_token}/sendMessage"
payload = {
"chat_id": chat_id,
"text": text
}
requests.post(url, data=payload)
while True:
send_message(group_chat_id, "Hi")
time.sleep(60)
2
Answers
You can give it a try, but make sure you installed "python-telegram-bot" through pip/pip3.
Replace "YOUR_TELEGRAM_BOT_TOKEN" and "YOUR_CHAT_ID" with your actual Telegram bot token and chat ID.
To create a simple Telegram bot in Python that sends "Hi" every minute, you can use the python-telegram-bot library. Make sure you have it installed by running:
pip install python-telegram-bot
Replace ‘YOUR_BOT_TOKEN’ with the actual token you obtain from BotFather on Telegram
Run the script, and your bot will say "Hi" every minute. Keep in mind that you need to start a conversation with your bot on Telegram before it can send messages to you.
You can also use
pyTelegramBotAPI
this is more convenient.Install it using
pip install pyTelegramBotAPI
and import is astelebot
. For more info checkout my project @ https://github.com/Sanskar-Shimpi/Telegram-Bot