-
Notifications
You must be signed in to change notification settings - Fork 0
/
telegramBot.py
27 lines (20 loc) · 1.02 KB
/
telegramBot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from config import settings
from telegram import Update
from telegram.ext import ApplicationBuilder, ContextTypes, CommandHandler, MessageHandler
from telegram.ext.filters import BaseFilter
from brain import ChatbotManager
chat_manager = ChatbotManager()
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
await context.bot.send_message(chat_id=update.effective_chat.id, text="Hola!")
async def message_callback(update: Update, context: ContextTypes.DEFAULT_TYPE):
message = update.message.text
gpt_response = chat_manager.ask(message)
await context.bot.send_message(chat_id=update.effective_chat.id, text=gpt_response)
if __name__ == '__main__':
print('Starting bot...')
application = ApplicationBuilder().token(settings.TELEGRAM_TOKEN).build()
start_handler = CommandHandler('start', start)
message_handler = MessageHandler(filters=BaseFilter(), callback=message_callback)
application.add_handler(message_handler)
application.add_handler(start_handler)
application.run_polling()