Open Deadtem333 opened 1 year ago
Let me check.
Hi, the previous code i posted is not very good, can i upload the one i made yesterday and you can check it out?
ср, 5 апр. 2023 г., 01:14 Paddy @.***>:
Let me check.
— Reply to this email directly, view it on GitHub https://github.com/amazingpaddy/bing-telegram-bot/issues/1#issuecomment-1496668956, or unsubscribe https://github.com/notifications/unsubscribe-auth/A64OOD7QNUP6PHRSLV3LJELW7SMLLANCNFSM6AAAAAAWPF2ECQ . You are receiving this because you authored the thread.Message ID: @.***>
import library
import re
import asyncio
import pickle import aiogram
from EdgeGPT import Chatbot
Insert your bot token
BOT_TOKEN = ''
bot = aiogram.Bot(token=BOT_TOKEN)
Create a Dispatcher object - it will be responsible for incoming messages
dp = aiogram.dispatcher.Dispatcher(bot)
Add your Telegram ID to the list without the @ symbol
authorized_id = ['<INSERT YOUR TELEGRAM USER NAME, NOT THE DISPLAY NAME>']
Initiate a dictionary to store message history
message_history = {}
async def bingChat(prompt, cookiePath, context='', user_id=None):
global message_history
gbot = Chatbot(cookiePath=cookiePath)
full_prompt = ' '.join([str(context), str(prompt)]).strip()
message_history[user_id] = full_prompt
response_dict = await asyncio.wait_for(gbot.ask(prompt=full_prompt), timeout=30)
response = response_dict['item']['messages'][1]['text']
Save cookie
pay attention to the decorator
@dp.message_handler(content_types=['text'])
async def handle_message(message: aiogram.types.Message):
global message_history
username = message.from_user.username
user_id = message.from_user.id
async def main():
Launching the bot
if name == 'main':
asyncio.run(main())
in this code, I use the aiogram library for the telegram bot, I was able to change it so that the bot itself determines the user's messages and it seems like the bot should remember previous messages, but I could not check this, I will be glad if someone experienced can complete this code.