Python 2.7 Python (2.7) Telegram Bot

Discussion in 'Coding' started by Sascha, May 30, 2017.

  1. Sascha

    Sascha Active Member Staff Member

    As many of you know already, telegram offers a open API for coding bots. This is an awesome replacement for E-Mail and SMS notifications. Here is a super simple example how to start making your own Python Telegram Bot.

    1. PIP & Library

    After installing PIP , use the following command to install the required libary:
    pip install pyTelegramBotAPI
    2. Create the bot and receive the tokens from Telegram

    3. How to tell the bot in which channel to send messages to?

    Invite the bot to the channel or group where you want to send messages. Wait until a message is sent into the group or send a message yourself. Then visit: (replace the "TOKEN_HERE" with your bot token. It should look like this: "294044544:AAG-F6JIC7ptNTqadg345TI1NiQmHYMybOU") to get the chat id. It will look similar to this: "297178735".

    4. Source code:

    import telebot
    tb = telebot.TeleBot(token)
    tb.send_message(chatid, 'hey. i am the bot!')
    Long and Detailed Guide:

    Edit: Thanks to Telegram User "aknownstranger" for pointing out a pip typo.
    Last edited: May 30, 2017
    JohnDoe likes this.