from telegram import Update

from telegram.ext import Updater, CommandHandler, CallbackContext

import requests


# টেলিগ্রাম বটের টোকেন

TOKEN = 'YOUR_BOT_TOKEN'


# ওয়েবসাইট API এর ইউআরএল

API_URL = 'https://yourwebsite.com/api'


# স্টার্ট কমান্ড হ্যান্ডলার

def start(update: Update, context: CallbackContext) -> None:

    update.message.reply_text("Welcome! Use /register to register and /shorten to shorten links.")


# রেজিস্টার কমান্ড হ্যান্ডলার

def register(update: Update, context: CallbackContext) -> None:

    user_id = update.message.from_user.id

    username = update.message.from_user.username

    # API-তে রেজিস্টার করার জন্য রিকুয়েস্ট পাঠান

    response = requests.post(f'{API_URL}/register', json={'user_id': user_id, 'username': username})

    if response.status_code == 200:

        update.message.reply_text("Registered successfully! Send your API key to proceed.")

    else:

        update.message.reply_text("Registration failed.")


# API কী সাবমিট করার হ্যান্ডলার

def set_api(update: Update, context: CallbackContext) -> None:

    user_id = update.message.from_user.id

    api_key = ' '.join(context.args)

    # API কী সংরক্ষণের জন্য রিকুয়েস্ট পাঠান

    response = requests.post(f'{API_URL}/set_api', json={'user_id': user_id, 'api_key': api_key})

    if response.status_code == 200:

        update.message.reply_text("API key set successfully!")

    else:

        update.message.reply_text("Failed to set API key.")


# লিংক সট করার হ্যান্ডলার

def shorten(update: Update, context: CallbackContext) -> None:

    user_id = update.message.from_user.id

    url_to_shorten = ' '.join(context.args)

    response = requests.post(f'{API_URL}/shorten', json={'user_id': user_id, 'url': url_to_shorten})

    if response.status_code == 200:

        short_url = response.json().get('short_url')

        update.message.reply_text(f"Shortened URL: {short_url}\n\nJoin our group: @mrbest08011982@gm")

    else:

        update.message.reply_text("Failed to shorten the URL.")


def main() -> None:

    updater = Updater(TOKEN)

    dispatcher = updater.dispatcher


    dispatcher.add_handler(CommandHandler('start', start))

    dispatcher.add_handler(CommandHandler('register', register))

    dispatcher.add_handler(CommandHandler('setapi', set_api))

    dispatcher.add_handler(CommandHandler('shorten', shorten))


    updater.start_polling()

    updater.idle()


if __name__ == '__main__':

    main()

Comments