File size: 1,863 Bytes
9ff40ac
3c468c3
d30be39
 
 
 
 
3c468c3
9ff40ac
8a15f00
d30be39
 
 
 
 
 
 
 
3c468c3
 
 
 
 
 
 
 
 
d30be39
 
 
3c468c3
 
 
 
 
 
 
 
 
 
9ff40ac
 
 
3c468c3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9ff40ac
3c468c3
 
 
9ff40ac
3c468c3
 
9ff40ac
3c468c3
 
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import asyncio
from flask import Flask, request
from threading import Thread
import random
import time
import requests
import logging
import json

from pyrogram import Client
from config import API_ID, API_HASH, BOT_TOKEN, REPL_URL

app = Flask("")

@app.route("/")
def home():
    return "You have found the home of a Python program!"

# Handle updates sent by Telegram
@app.route(f"/{BOT_TOKEN}", methods=["POST"])
def handle_updates():
    update = json.loads(request.data)
    # Do something with the update, e.g., process incoming messages
    # For example, you can forward incoming messages to another chat:
    # app.send_message(chat_id="@your_chat", text=update["message"]["text"])
    return "OK"

def run():
    app.run()

def set_webhook():
    # Set the webhook URL to your bot on Telegram's server
    url = f"https://api.telegram.org/bot{BOT_TOKEN}/setWebhook"
    data = {"url": f"https://manishx-genatoz.hf.space/{BOT_TOKEN}"}
    r = requests.post(url, json=data)
    if r.status_code != 200:
        print(f"Failed to set webhook: {r.text}")
        return False
    print("Webhook set successfully")
    return True

if __name__ == '__main__':

    # Set the webhook URL
    if not set_webhook():
        exit(1)

    # Setting up uvloop
    try:
        import uvloop
        uvloop.install()
    except:
        print("Could not apply uvloop on project")

    # Defining path to plugins
    plugins = dict(root="plugins")

    # Defining the pyrogram client's instance
    client = Client("UploadBot",
                   api_id=API_ID,
                   api_hash=API_HASH,
                   bot_token=BOT_TOKEN,
                   plugins=plugins)

    # Start the Flask app in a separate thread
    t = Thread(target=run)
    t.start()

    # Start the Pyrogram client
    client.start()

    # Keep the client running
    client.idle()