Spaces:
Running
Running
Commit
ยท
d32bbaf
1
Parent(s):
5460775
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from telethon.sync import TelegramClient, events
|
3 |
+
import asyncio
|
4 |
+
import datetime
|
5 |
+
|
6 |
+
def handle_messages(api_id, api_hash, sender_name, chat_id, text):
|
7 |
+
async def process_messages():
|
8 |
+
async with TelegramClient('anon', api_id, api_hash) as client:
|
9 |
+
@client.on(events.NewMessage())
|
10 |
+
async def my_event_handler(event):
|
11 |
+
sender = await event.get_sender()
|
12 |
+
sender_id = sender.id
|
13 |
+
chat = await event.get_chat()
|
14 |
+
chat_id = chat.id
|
15 |
+
text = event.raw_text
|
16 |
+
|
17 |
+
# ู
ููุงุณ ุงูุฒู
ู
|
18 |
+
checkpoint = datetime.datetime.now()
|
19 |
+
print(f'Checkpoint: {checkpoint}')
|
20 |
+
|
21 |
+
# ุฑุณุงูุฉ ุดุฎุตูุฉ
|
22 |
+
if chat_id == sender_id:
|
23 |
+
response = f'ุงููุง {sender_name} , ููุฏ ุชูููุช ุฑุณุงูุชู ุณุฃููู
ุจุงูุฑุฏ ุนููู ุจุฃูุฑุจ ููุช ู
ู
ูู ูุดูุฑุงู ูุชููู
ู.'
|
24 |
+
await client.send_message(chat_id, response)
|
25 |
+
|
26 |
+
# ุฑุณุงูุฉ ู
ุฌู
ูุนุฉ
|
27 |
+
elif '@Mohammed_Alakhras' in text:
|
28 |
+
response = f'ุงููุง {sender_name} , ููุฏ ุชูููุช ุฑุณุงูุชู ุณุฃููู
ุจุงูุฑุฏ ุนููู ุจุฃูุฑุจ ููุช ู
ู
ูู ูุดูุฑุงู ูุชููู
ู.'
|
29 |
+
await client.send_message(chat_id, response)
|
30 |
+
|
31 |
+
await client.run_until_disconnected()
|
32 |
+
|
33 |
+
asyncio.run(process_messages())
|
34 |
+
|
35 |
+
# ุชุนุฑูู ุญููู ุงููุต ูู Gradio
|
36 |
+
phone_number = gr.inputs.Textbox(label="ุฑูู
ุงููุงุชู", type="str")
|
37 |
+
|
38 |
+
# ุชุนุฑูู ุงููุงุฌูุฉ
|
39 |
+
inputs = [phone_number]
|
40 |
+
output = "text"
|
41 |
+
|
42 |
+
gr.Interface(fn=handle_messages, inputs=inputs, outputs=output).launch()
|