Skip to content
This repository was archived by the owner on May 21, 2023. It is now read-only.

Introduction to the API

Jannes Höke edited this page May 28, 2016 · 26 revisions

The API is exposed via the telegram.Bot class. The methods have names as described in the official Telegram Bot API, but equivalent snake_case methods are available for PEP8 enthusiasts. So for example telegram.Bot.send_message is the same as telegram.Bot.sendMessage.

To generate an Access Token, you have to talk to BotFather and follow a few simple steps (described here).

For full details see the Bots: An introduction for developers.

The first API call

To get a feeling for the API and how to speak to it with python-telegram-bot, please open a Python command line and follow the next few steps.

First, create an instance of the telegram.Bot. 'TOKEN' should be replaced by the API token you received from @BotFather:

>>> import telegram
>>> bot = telegram.Bot(token='TOKEN')

To check if your credentials are correct, call the getMe API method:

>>> print(bot.getMe())
{"first_name": "Toledo's Palace Bot", "username": "ToledosPalaceBot"}

Note: Bots can't initiate conversations with users. A user must either add them to a group or send them a message first. People can use telegram.me/<bot_username> links or username search to find your bot.

What to read next?

If you want to continue learning about the API, read Code snippets.

To get real and start building your first bot using the telegram.ext classes, read Extensions

Clone this wiki locally