-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtelegram.py
39 lines (25 loc) · 891 Bytes
/
telegram.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
28
29
30
31
32
33
34
35
36
37
38
39
import os
import telebot
from dotenv import load_dotenv
from chat import chat
load_dotenv()
bot = telebot.TeleBot(os.environ.get('TELEGRAM_KEY'))
g_messages = [] # group messages
p_messages = [] # private messages
@bot.message_handler(commands=['gpt'])
def group_message(message):
bot.send_chat_action(chat_id=message.chat.id, action="typing")
msg = message.text.replace('/gpt ', '')
g_messages.append(
{"role": "user", "content": msg})
reply(message, g_messages)
@bot.message_handler(chat_types=['private'])
def private_message(message):
bot.send_chat_action(chat_id=message.chat.id, action="typing")
p_messages.append(
{"role": "user", "content": message.text})
reply(message, p_messages)
def reply(message, array):
response = chat(array)
bot.reply_to(message, response.choices[0].message.content)
bot.infinity_polling()