allanberger / hello-telegram-bot

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Creating a Telegram Bot

Let's get started!

In this tutorial you'll get a Telegram Bot up and running on your local enviornment. Later you'll also learn how to deploy it to your OpenShift server.

We'll use the Python library provided by Telegram called python-telegram-bot.

To begin, you'll need a Telegram Access Token for your Bot.

  1. Create or sign in to your Telegram Account

  2. Search for @BotFather

    Search for @BotFather

  3. Initialize a conversation with the @BotFather

    Initialize Conversation with BotFather

  4. Create a new bot by typing /newbot and follow the guided process.

    Congratulations, you've created your Telegram Bot :)

  5. Generate an access token which you'll need to communicate with your bot by typing /token

  6. Replace your Telegram access token in telegram.py by YOUR TOKEN

  7. Fire up a command line and install the python-telegram-bot library through your command line by running:

    pip install python-telegram-bot

  8. To start your bot run python bot.py (stop your bot by running CTRL+Z)

  9. Your Bot supports the following inputs:

    • /start /start command
    • /hello /hello command
    • /help /help command
    • /caps your text Caps text
    • Echoes messages Echo text

Deploying your bot to OpenShift

Coming soon …

Notes

Add @Hello_Telegram_Bot and send him a message to test the features in this tutorial.

Find more infos and documentation about python-telegram-bot at https://github.com/python-telegram-bot/

To send 🔊 audio, 🖼 photos, etc check out the Telegram Bot API 🙂

Examples by python-telegram-bot

Get inspired by more Examples here:

echobot2.py

This is probably the base for most of the bots made with python-telegram-bot. It simply replies to each text message with a message that contains the same text.

timerbot.py

This bot uses the JobQueue class to send timed messages. The user sets a timer by using /set command with a specific time, for example /set 30. The bot then sets up a job to send a message to that user after 30 seconds. The user can also cancel the timer by sending /unset. To learn more about the JobQueue, read this wiki article.

conversationbot.py

A common task for a bot is to ask information from the user. In v5.0 of this library, we introduced the ConversationHandler for that exact purpose. This example uses it to retrieve user-information in a conversation-like style.

inlinekeyboard.py

This example sheds some light on inline keyboards, callback queries and message editing.

inlinebot.py

A basic example of an inline bot. Don't forget to enable inline mode with @BotFather.

About


Languages

Language:Python 100.0%