In this article, I am going to show you one of the easiest ways to send Telegram messages automatically to a Telegram group. So without further ado, let’s get started.
If you want to learn to automate everything using Telegram Bot then watch this free tutorial.
Table of Contents
Telegram Group Creation
You need to create a Telegram group so that later on we can add our Telegram bot to the group. If you already have a bot then just move on to the next steps.
Create Telegram Bot
We now need to create a Telegram Bot using Botfather. Follow the steps mentioned in this video to create a Telegram bot.
Steps to create a bot
- Search for Botfather in Telegram
- Write /newbot and hit Enter
- Provide name to this bot. I am calling it “Just Another Bot” and hit Enter
- Give a unique ID to your Bot. I am giving “vikasjha001_bot” and hitting Enter
- Write /setprivacy and hit Enter
- Select the Bot name which we just created and Disable the Privacy.
- That’s all. Now we are ready with the Bot.
Add Telegram Bot to the Group
Now you can add the newly created Telegram bot to the group. Steps are:
- Go to the Telegram group which you previously created.
- Click on Add new member
- Provide the name of your Telegram bot
- Add the member
Install and Import Requests Library
We will be using the Requests library to call Telegram /sendMessage API. So make sure to install the requests library by following the below command.
pip install requests
Send Telegram Messages Automatically
Here is a sample program that is going to send messages to any telegram group. Please replace anything which is mentioned inside angular brackets with actual value.
<your bot token> should be replaced with the bot token which you received while creating the bot.
import requests jokes = ["joke 1", "joke 2", "Joke 3"] for joke in jokes: base_url = "https://api.telegram.org/bot<your bot token>/sendMessage?chat_id=<your group id>&text=joke print("Message is sent")