Spaces:
Building
Building
measmonysuon
commited on
Create telegrabot.py
Browse files- telegrabot.py +41 -0
telegrabot.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import telebot
|
2 |
+
import socks
|
3 |
+
import socket
|
4 |
+
|
5 |
+
# Proxy configuration
|
6 |
+
PROXY_HOST = '64.29.87.81'
|
7 |
+
PROXY_PORT = 48558
|
8 |
+
PROXY_USERNAME = 'KNaDX4iRd2t6El0'
|
9 |
+
PROXY_PASSWORD = 'NleyoQHQJwHbqSH'
|
10 |
+
|
11 |
+
# Configure SOCKS proxy
|
12 |
+
socks.set_default_proxy(socks.SOCKS5, PROXY_HOST, PROXY_PORT, username=PROXY_USERNAME, password=PROXY_PASSWORD)
|
13 |
+
socket.socket = socks.socksocket
|
14 |
+
|
15 |
+
# Initialize the bot with your API token
|
16 |
+
API_TOKEN = '7484321656:AAExhpS7sOGMu2BCuPQrDjuXpY3sEQmBgfY'
|
17 |
+
bot = telebot.TeleBot(API_TOKEN)
|
18 |
+
|
19 |
+
@bot.message_handler(commands=['start'])
|
20 |
+
def handle_start(message):
|
21 |
+
# Extract username from message
|
22 |
+
username = message.from_user.username or "Guest"
|
23 |
+
|
24 |
+
# Construct URL with username
|
25 |
+
encoded_url = f"https://measmonysuon-webapp.hf.space/?username={username}"
|
26 |
+
|
27 |
+
# Send a message with the inline button to open the web app
|
28 |
+
markup = telebot.types.InlineKeyboardMarkup()
|
29 |
+
button = telebot.types.InlineKeyboardButton(
|
30 |
+
text="Open Web App",
|
31 |
+
web_app=telebot.types.WebAppInfo(url=encoded_url)
|
32 |
+
)
|
33 |
+
markup.add(button)
|
34 |
+
|
35 |
+
bot.send_message(
|
36 |
+
message.chat.id,
|
37 |
+
f"Welcome, {username}! Click the button below to open the web app:",
|
38 |
+
reply_markup=markup
|
39 |
+
)
|
40 |
+
|
41 |
+
bot.polling()
|