Step 1: Create a bot
1. Go to Telegram and find the @BotFather bot.
2. Message him /start and follow the instructions.
3. Type the /newbot command and follow the instructions to create a new bot.
4. After successfully creating the bot, @BotFather will give you a token that you need to save.
Step 2: Set up the development environment
1. Install Python if it is not already installed on your computer.
2. Install the python-telegram-bot package, which allows you to interact with the Telegram API.
Step 3: Code the bot
1. Create a new Python file and import the required modules:
python
import telegram
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
2. Create a handler function for the /start command:
python
def start(update, context):
context.bot.send_message(chat_id=update.effective_chat.id, text="Привет! Я бот.")
3. Create a message handler function:
python
def echo(update, context):
context.bot.send_message(chat_id=update.effective_chat.id, text=update.message.text)
4. Create a main() function to start the bot:
python
def main():
updater = Updater(token='YOUR_TOKEN', use_context=True)
dispatcher = updater.dispatcher
start_handler = CommandHandler('start', start)
echo_handler = MessageHandler(Filters.text & (~Filters.command), echo)
dispatcher.add_handler(start_handler)
dispatcher.add_handler(echo_handler)
updater.start_polling()
updater.idle()
5. Replace YOUR_TOKEN with the token you received from @BotFather.
Step 4: Launching the bot
1. Run the Python file with the bot code.
2. Find your bot in Telegram and write a /start message to it.
3. Check the work of the bot by sending him a message.
Ready! Now you can continue to develop your bot by adding new features and handlers.