# Creating a TeleBot

### Getting Started

1. Open up the IDE of your choice (PyCharm, VS Code, Google Colab, etc.)
2. Locate the terminal - usually found in a panel at the bottom or side of your IDE
3. Install the telebot package by typing `pip install python-telegram-bot`\
   \&#xNAN;*Note: Colab uses ! as a prefix to shell commands*
4. Run the command

Link to the Library: <https://github.com/python-telegram-bot/python-telegram-bot>

### Creating a Bot

* Launch Telegram&#x20;
* Search for the user @BotFather

<figure><img src="/files/mED4hpXcQxPbzLVffnbw" alt="" width="375"><figcaption><p>BotFather on Telegram</p></figcaption></figure>

* Create a new bot by using the command '**/start '**
* Follow the prompts and set the bot's name and username\
  Username must end with "bot"  ->  e.g. 'untitled\_bot'
* Receive your bot token: BotFather will provide you with a unique token that will be used to authenticate your bot

<figure><img src="/files/NRFuj689fjd6OFmEbq3e" alt="" width="563"><figcaption><p>Your Bot's Token</p></figcaption></figure>

Keep your token secure and do not share it publicly

* Input token into your environment

{% code overflow="wrap" %}

```python
# Replace "YOUR_API_TOKEN" with token received from BotFather

token = "YOUR_API_TOKEN"
```

{% endcode %}

* (Optional) Add a description, profile picture, etc.&#x20;

### Import Packages

We will be creating the telebot in the context of Google Colab!

So, *let's get started!* Paste the following code blocks into your file:

1. Allow for asynchronous programming capabilities

<pre class="language-python" data-overflow="wrap"><code class="lang-python"># Workaround for nested event loops in Jupyter (Google Colab)
# Jupyter notebooks already have a running loop via Tornado and the asyncio lib does not allow a nested loop, we need to use a separate package called nest_asyncio
<strong>
</strong>import asyncio
import nest_asyncio

nest_asyncio.apply() 

# for non-Jupyter notebook IDE's

import asyncio
</code></pre>

2. Enable logging

```python
import logging

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

logger = logging.getLogger(__name__)
```

This is setting up `logging` module, so you know when (and why) things don't work as expected.

Click [here](https://github.com/python-telegram-bot/python-telegram-bot/wiki/Exceptions%2C-Warnings-and-Logging) for more info.

3. Import from telegram package&#x20;

{% code overflow="wrap" %}

```python
from telegram import Update
from telegram.constants import ParseMode
from telegram import InlineQueryResultArticle, InputTextMessageContent
from telegram.ext import filters, MessageHandler, ApplicationBuilder, CommandHandler, ContextTypes, InlineQueryHandler
```

{% endcode %}

4. (Optional) Other useful packages

```python
import math
from random import random
import datetime
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://wiki.nushackers.org/orbital/telegram-bot/creating-a-telebot.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
