File size: 1,255 Bytes
9681664
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
40
import requests
import os
from telegram import Update, Bot
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, CallbackContext

TELEGRAM_TOKEN = os.getenv("TELEGRAM_TOKEN")
MOLBOT_URL = os.getenv("MOLBOT_URL")  # উদাহরণ: https://suj2026-molbot.hf.space/

bot = Bot(token=TELEGRAM_TOKEN)

def start(update: Update, context: CallbackContext):
    update.message.reply_text("Hi! I'm your Molbot AI 🤖")

def handle_message(update: Update, context: CallbackContext):
    user_msg = update.message.text
    try:
        response = requests.post(
            MOLBOT_URL,
            headers={"Content-Type": "application/json"},
            json={"message": user_msg}
        ).json()

        reply_text = response.get("choices", [{}])[0].get("message", {}).get("content", "Sorry, couldn't reply.")
        update.message.reply_text(reply_text)

    except Exception as e:
        update.message.reply_text(f"Error: {e}")

def main():
    updater = Updater(TELEGRAM_TOKEN)
    dp = updater.dispatcher

    dp.add_handler(CommandHandler("start", start))
    dp.add_handler(MessageHandler(Filters.text & ~Filters.command, handle_message))

    updater.start_polling()
    updater.idle()

if __name__ == "__main__":
    main()