How to install telegram bot


How to Add a Bot in Telegram

A feature that makes popular instant messaging app Telegram stand out is the option to use bots in group chats. Their purpose is to essentially enhance the Telegram experience through convenience and entertainment. If you’re an admin for a Supergroup and want to know how to add a bot, we’ve covered the steps on how-to in this article.

We’ll be adding bots to chat groups via different operating systems, learning more about their usefulness and how they differ from human members in chats. Plus, our FAQs include how to create your own unique bot.

How to Add Bots on Telegram?

A Telegram bot is a third-party application used to improve its functionality by performing specific functions, follow instructions, and interact with other members. The following sections are the steps for adding a bot to a Supergroup.

Add a Bot to a Supergroup Chat Using an iPhone

  1. Launch the Telegram app.
  2. At the bottom of the screen, click on the Contacts icon.
  3. At the top of the screen, click on the search bar.
  4. Type in the name of the bot you wish to add @[botname].
  5. Click on the bot name to display it in the chat.
  6. From the top-right hand corner of the chat window, select the bot’s profile image.
  7. Locate and select the “Add to Group” option below the “Send Message” option to access a list of groups to add members to.
  8. Select the group you wish to add the bot to.
  9. Click on “Yes” to confirm.

Add a Bot to a Supergroup Chat Using an Android

  1. Launch the Telegram app.
  2. At the bottom of the screen, click on the Contacts icon.
  3. At the top of the screen, click on the search bar.
  4. Type in the name of the bot you wish to add @[botname].
  5. Click on the bot name to display it in the chat.
  6. From the top-right hand corner of the chat window, select the bot’s profile image.
  7. Locate and select the “Add to Group” option below the “Send Message” option to access a list of groups to add members to.
  8. Select the group you wish to add the bot to.
  9. Click on “Yes” to confirm.

Add a Bot to a Supergroup Chat Using Mac

  1. Navigate to the “Applications” folder to locate and launch the Telegram app.
  2. In the search text field at the top left-hand corner of the screen, enter the name of the bot you wish to add.
  3. Hit the return key for a list of bot search results matching your query.
  4. Click on the bot you wish to add to the group, the bot will open and display on the right.
  5. To bring up the bot’s profile, select the bot’s name from the top of the window.
  6. Towards the top-right hand corner of the window, select the “Add to Group” option.
  7. Select which Supergroup you want to add to the bot.
  8. Click “OK” to confirm.

Add a Bot to a Supergroup Chat Using Windows 10

  1. Navigate to the Windows menu to locate and launch the Telegram app.
  2. In the search text field at the top left-hand corner of the screen, enter the name of the bot you wish to add.
  3. Hit the return key for a list of bot search results matching your query.
  4. Click on the bot you wish to add to the group, the bot will open and display on the right.
  5. To bring up the bot’s profile, select the bot’s name from the top of the window.
  6. Towards the top-right hand corner of the window, select the “Add to Group” option.
  7. Select which Supergroup you want to add the bot to.
  8. Click “OK” to confirm.

Bot Perks

Using bots in Telegram can be practical:

  • Bots can be used as virtual assistants to provide weather forecasts, alerts, translation, and other admin services.
  • Bots can deliver relevant content by providing customized news and notifications as soon as it’s available.
  • Accept payments for goods and services. The bot payment API is a free platform where sellers can receive payment from Telegram users.
  • Bots can help create social connections by connecting people wanting to conversate based on mutual interests or proximity.
  • Bots can integrate with other services such as YouTube and Music bots for extra entertainment.
  • Bots provide multi and single-player games, from simple puzzles to real-time strategy games.

How Are Bots Different Than Humans?

The following are differences between human members and bots in Telegram:

  • For bots running in privacy mode, once added to a group they will not receive messages previously sent to the group.
  • They have limited cloud storage therefore older processed messages are promptly removed by the server.
  • Bots are not able to start conversations with people. They must be added to a group or a user must send them a message first.
  • Their username will always end in “bot.”
  • Their label displays as “bot” with no last seen time or online status information available.

BotFather

“BotFather is the one bot to rule them all.”

BotFather is the bot used to create new bots and manage existing ones via Telegram. To contact the BotFather, you can either search for him under username @Botfather or navigate to https://telegram.me/botfather to start a conversation. BotFather will introduce himself and a “Start” button will be available for you to talk back.

Additional FAQs

How to Remove Bots on Telegram?

To remove a Telegram bot from your conversation list via Android:

Note: Removing a bot will also remove the conversation.

1. Launch the Telegram app.

2. Press down and hold on to the bot’s name to display a menu at the bottom of the screen.

3. Select “Delete and stop.”

4. Click on “OK” to confirm.

1. Launch the Telegram app.

2. Locate the bot you wish to remove and swipe left on the conversation.

3. Click on the “Delete” icon from the set of icons that slide out from the right.

4. Select “Delete and Stop” from the option displayed at the bottom of the screen.

How to Add a Bot to a Telegram Group?

To add a bot to a chat group using an Android or iPhone device:

1. Launch the Telegram app.

2. At the bottom of the screen, click on the Contacts icon.

3. At the top of the screen, click on the search bar.

4. Type in the name of the bot you wish to add @[botname].

5. Click on the bot name to display it in the chat.

6. From the top-right hand corner of the chat window, select the bot’s profile image.

7. Locate and select the “Add to Group” option below the “Send Message” option to access a list of groups to add members to.

8. Select the group you wish to add the bot to.

9. Click on “Yes” to confirm.

To add a bot to a chat group using a Mac or PC:

1. Navigate to the Applications folder (Mac) or Windows menu (PC) to locate and launch the Telegram app.

2. In the search field, at the top left-hand corner of the screen, enter the name of the bot you wish to add.

3. Hit the return key for a list of bot search results matching your query.

4. Click on the bot you wish to add to the group, the bot will open and display on the right.

5. To bring up the bot’s profile, select the bot’s name from the top of the window.

6. Towards the top-right hand corner of the window, select the “Add to Group” option.

7. Select which Supergroup you want to add the bot to.

8. Click “OK” to confirm.

How to Create a New Telegram Bot?

1. First, start up a conversation with BotFather either by searching for him under the username @Botfather or by navigating to https://telegram.me/botfather.

2. Then enter and send the command “/newbot.

3. BotFather will ask for a name and username. Provide a friendly name and unique username.

· BotFather will generate an authorization token.

4. Copy the token to your clipboard and navigate to your bot’s “Channels” section via the Azure portal then click on “Telegram.”

5. Paste the authorization token into the “Access Token” field then “Save.

· Your bot is now created successfully; single, and ready to mingle with other Telegram members.

· Enable “Inline queries” so users can call your bot by entering its username and the query into any chat.

· Check out the Bot API manual to find out what you can teach your bot to do.

Telegram’s Little Virtual Assistants

AI-inspired bots in Telegram are used to enhance the messaging experience by essentially performing admin tasks, connecting people, and providing entertainment. Bots in messaging apps have become increasingly common and the option to use them is available via several popular apps.

Now that you know how to add a bot to a chat, create a bot, and other bot information; do you think the bot did a great job at enhancing your experience? How did the bot serve the group – and did it work as expected? Let us know what you think generally about the use of bots in messaging apps in the comments section below.

python-telegram-bot · PyPI

We have made you a wrapper you can’t refuse

We have a vibrant community of developers helping each other in our Telegram group. Join us!

Stay tuned for library updates and new releases on our Telegram Channel.

Table of contents

  • Introduction

  • Telegram API support

  • Installing

  • Getting started

    1. Learning by example

    2. Logging

    3. Documentation

  • Getting help

  • Contributing

  • License

Introduction

This library provides a pure Python interface for the Telegram Bot API. It’s compatible with Python versions 3.7+. PTB might also work on PyPy, though there have been a lot of issues before. Hence, PyPy is not officially supported.

In addition to the pure API implementation, this library features a number of high-level classes to make the development of bots easy and straightforward. These classes are contained in the telegram.ext submodule.

A pure API implementation without telegram.ext is available as the standalone package python-telegram-bot-raw. See here for details.

Note

Installing both python-telegram-bot and python-telegram-bot-raw in conjunction will result in undesired side-effects, so only install one of both.

Telegram API support

All types and methods of the Telegram Bot API 6.2 are supported.

Installing

You can install or upgrade python-telegram-bot with:

$ pip install python-telegram-bot --upgrade

Or you can install from source with:

$ git clone https://github.com/python-telegram-bot/python-telegram-bot --recursive $ cd python-telegram-bot $ python setup.py install

In case you have a previously cloned local repository already, you should initialize the added urllib3 submodule before installing with:

$ git submodule update --init --recursive

Optional Dependencies

PTB can be installed with optional dependencies:

  • pip install python-telegram-bot[passport] installs the cryptography library. Use this, if you want to use Telegram Passport related functionality.

  • pip install python-telegram-bot[ujson] installs the ujson library. It will then be used for JSON de- & encoding, which can bring speed up compared to the standard json library.

  • pip install python-telegram-bot[socks] installs the PySocks library. Use this, if you want to work behind a Socks5 server.

Getting started

Our Wiki contains a lot of resources to get you started with python-telegram-bot:

  • Introduction to the API

  • Tutorial: Your first Bot

Other references:

  • Telegram API documentation

  • python-telegram-bot documentation

Learning by example

We believe that the best way to learn this package is by example. Here are some examples for you to review. Even if it is not your approach for learning, please take a look at echobot.py, it is the de facto base for most of the bots out there. Best of all, the code for these examples are released to the public domain, so you can start by grabbing the code and building on top of it.

Visit this page to discover the official examples or look at the examples on the wiki to see other bots the community has built.

Logging

This library uses the logging module. To set up logging to standard output, put:

import logging logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')

at the beginning of your script.

You can also use logs in your application by calling logging.getLogger() and setting the log level you want:

logger = logging.getLogger() logger.setLevel(logging.INFO)

If you want DEBUG logs instead:

logger.setLevel(logging.DEBUG)

Documentation

python-telegram-bot’s documentation lives at readthedocs.io.

Getting help

You can get help in several ways:

  1. We have a vibrant community of developers helping each other in our Telegram group. Join us!

  2. Report bugs, request new features or ask questions by creating an issue or a discussion.

  3. Our Wiki pages offer a growing amount of resources.

  4. You can even ask for help on Stack Overflow using the python-telegram-bot tag.

Contributing

Contributions of all sizes are welcome. Please review our contribution guidelines to get started. You can also help by reporting bugs.

Donating

Occasionally we are asked if we accept donations to support the development. While we appreciate the thought, maintaining PTB is our hobby and we have almost no running costs for it. We therefore have nothing set up to accept donations. If you still want to donate, we kindly ask you to donate to another open source project/initiative of your choice instead.

License

You may copy, distribute and modify the software provided that modifications are described and licensed for free under LGPL-3. Derivatives works (including modifications or anything statically linked to the library) can only be redistributed under LGPL-3, but applications that use the library don’t have to be.

Create a Telegram bot | Selectel Knowledge Base

Using bots, you can simplify the task of communicating with users by creating a smart assistant for them. Bots understand text commands and can access the API of your website, service, or be a standalone product with unique services. Usually, a server is required to create a bot, but in this article we will analyze an approach that allows us to do without it. It is ideal for large fluctuations in the number of requests and perfectly withstands peak loads.
You can set up a Telegram bot on Cloud Functions using the official API and an example prepared by us in 3 steps:

  1. Program the logic of the Telegram bot.
  2. Register a new bot in Telegram.
  3. Link the bot and its logic together.

Program the logic of the Telegram bot

To simplify the task, we have written an example of such a bot. Its source code is available at github.com/selectel/cloud-telegram-bot. He understands commands:

  • /start with a welcome message;
  • /sticker with a sticker;
  • /getwebhook so you can get information about your bot settings;
  • /setwebhook to set up your bot, but more on that later.

Go through the following steps with our example bot to get comfortable:

  1. Download the source code as an archive ("Clone or download" → "Download ZIP") and extract it.
  2. Inside should be:
    • "setup.py" with minimal code so that the Python environment takes the contents of the folder as a module to install;
    • "requirements.txt" with a description of the dependencies;
    • "bot" is the folder with the source code of our bot.
  3. Select all these files and folders, and then create a new ZIP archive from them, then the source code inside the archive will not have extra folders (as is the case with the archive downloaded from github).
  4. Go to control panel section Cloud Platform Function and press the button Create Function .
  5. Select the runtime and give it a name, such as Bot .
  6. In the Load field, select Archive .
  7. Download the ZIP file as Feature Code .
  8. Specify Path to file as /bot/tele_bot.py .
  9. Specify Callable function as main .
  10. Get the token according to the instructions and in the field Environment variables add its key and value.
  11. Click the Save and Deploy button .
  12. To get a link to call the function, go to the Triggers tab and click on the HTTP request toggle switch.

Now we have an API that implements the bot response logic. The next step is to register it in Telegram.

Register a new bot in Telegram

In order for Telegram to know about the existence of our bot, it needs to be registered. There is only one way to do this:

  1. Find the @BotFather bot in Telegram. This is an official bot created specifically for managing bots.
  2. Send him a command:

     /newbot 
  3. @BotFather will ask you what you want to name your bot. In the next message, send its name ending in "_bot".

  4. Write down the received token from @BotFather - this is the key for working with the Telegram API.

Now we have an API, registering a bot in Telegram and its token. It remains to tie it together.

How to link the bot and its logic together?

At this stage, you need to make sure that the bot knows the user's token, and Telegram knows where its API is:

  1. Find the "TOKEN" environment variable in the function settings. We left it empty at the first stage.
  2. Set this variable to your bot's token that you received from @BotFather.
  3. Click Save and Expand .

Next, we need to send the messages that users send to Telegram to our bot - to the API that was created for it.

Method 1. Through the @SelectelServerless_bot bot

  1. Find the @SelectelServerless_bot bot in Telegram.
  2. Enter command:

     /setwebhook   
  3. The bot will respond with what it receives from the Telegram API. If everything is fine, it will be "true".

  4. To make sure everything is correct, send the command:

     /getwebhook  
  5. The response should contain information about the webhook, including the URL you specified.

Method 2. From a prepared form

Open the form (or copy it to your Cloud storage). Paste the token from your bot into the first field, the URL of the cloud function into the second and click on the "Set Webhook" button. Api.telegram.org will be called and you will see the result.

Note: VPN may be required.

Total

Ready for work, a bot available in Telegram that responds to commands and is able to automatically scale under load and without a server.

How to add a bot to a Telegram channel, chat or group

Messenger developers encourage the creation of robots, so their number is growing every day. Today we will tell you how to find and add a bot to Telegram, as well as how to use it. These are very useful programs that can manage channels for you or post messages / mailing lists in your groups, etc. After all, it takes a lot of time to search and issue information, and a high-quality robot will do everything by itself. If you are in business, then robots can be a great marketing tool.

Where to find the service you need

If you don't know the exact name of the resource you need, you can use the Telegram Store website https://storebot.me/
This is a catalog that provides information about all current developments. If it's not convenient to search on the site, look for @strorebot.
You can view the top chart, new items or recently added.
You can also type a keyword related to the purpose of the service into the search bar to help you perform a targeted search.

How can I find out more about the bot?

All additional information is described by the developer at the creation stage. It is also available to the user:

  1. Click on the name of the bot program in the list of your account.
  2. In the top line, click on the title. If you are using the web version, then click on the logo to the right of the message entry line.
  3. A window will open showing the description and the correct title.

The information also appears when the robot starts.

How to add a bot to Telegram?

After you know the name of the resource, enter it in the search bar (magnifying glass icon). A list of programs matching the typed string will appear on the screen. Choose the one you want and click on it. Now the robot will always be on the list.

To start a chat, just click on it. Messages are entered in the search bar. As you can see, you don’t need to take any special actions to add a bot to a Telegram chat.

How to add a Telegram bot to a group

Consider step by step:

  1. Create a Telegram group. To do this, click the main menu icon in the upper left corner and click on the desired item. Specify the contacts of the participants and enter the name of the group.
  2. Open the group and click on its name at the top (the group's logo next to the input line in the web version).
  3. Find the item "Add member" (Add member for a non-Russian messenger).
  4. In the window, click the magnifying glass icon and enter the name of the robot to be added.
  5. Confirm your consent and the program will appear in the group.

We figured out how to add a bot to a conversation. It remains to learn how to add a bot to a Telegram channel. To do this, follow these steps: