TGViewer
Python RU Python RU @pro_python_code · 12.3K subscribers
Post #1039 3.32K
🤓 Как создать Telegram-бота с интеграцией ChatGPT.

1️⃣ Создание чатбота Telegram

• Откройте вашу IDE и создайте файл с именем telegram-bot.py

• Мы будем использовать этот пакет https://github.com/python-telegram-bot/python-telegram-bot, который поможет нам создать telegram-бота. Обязательно установите его с помощью:

pip3 install python-telegram-bot

• После установки вставьте этот код в файл telegram-bot.py:

import logging
import os
from telegram import Update
from telegram.ext import (ApplicationBuilder, CommandHandler, ContextTypes,
MessageHandler, filters)

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

async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
await context.bot.send_message(chat_id=update.effective_chat.id, text="I'm a bot, please talk to me!")

async def echo(update: Update, context: ContextTypes.DEFAULT_TYPE):
await context.bot.send_message(chat_id=update.effective_chat.id, text=update.message.text)

if __name__ == '__main__':
application = ApplicationBuilder().token(TELEGRAM_API_TOKEN).build()

start_handler = CommandHandler('start', start)
echo_handler = MessageHandler(filters.TEXT & (~filters.COMMAND), echo)
application.add_handler(start_handler)
application.add_handler(echo_handler)

application.run_polling()


Продолжение

@pro_python_code
  • 👍 9
  • ❤ 2
  • 🔥 2
More from @pro_python_code
  1. Oct 4, 2026Hugging Face исследовали multi-harness RL: обучение с подкреплением сразу через Claude Cod…
  2. Oct 1, 2026DeepSeek Harness вышел на десктоп: плагины без терминала и задачи по расписанию DeepSeek в…
  3. Sep 30, 2026Пишем игру на Python: неоновая аркада с разбором кода и ИИ Pygame часто считают библиотеко…
  4. Sep 29, 2026photo post
  5. Sep 28, 2026photo post
  6. Sep 26, 2026🐧 Linux Cheat Sheet - шпаргалка по командам Linux Самая удобная шпаргалка по Linux и Bash…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →