chatbot.py 961 B

12345678910111213141516171819202122232425262728293031323334
  1. import aiohttp
  2. from pyrogram import filters
  3. from wbb import app
  4. from wbb.utils.botinfo import BOT_ID
  5. __MODULE__ = 'Chatbot'
  6. __HELP__ = "Reply To Any Message Of Bot To See This In Action."
  7. async def getresp(query):
  8. url = f"https://dsghrfgj.herokuapp.com/?query={query}"
  9. async with aiohttp.ClientSession() as session:
  10. async with session.get(url) as res:
  11. res = await res.json()
  12. text = res['response']['bot']
  13. return text
  14. @app.on_message(~filters.edited & filters.reply)
  15. async def chat_bot(_, message):
  16. if not message.reply_to_message.from_user.id == BOT_ID:
  17. return
  18. if not message.text:
  19. query = "Hello"
  20. else:
  21. query = message.text
  22. await app.send_chat_action(message.chat.id, "typing")
  23. try:
  24. res = await getresp(query)
  25. except Exception as e:
  26. res = str(e)
  27. await message.reply_text(res)
  28. await app.send_chat_action(message.chat.id, "cancel")