Spaces:
Running
Running
File size: 1,735 Bytes
d32bbaf |
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 |
import gradio as gr
from telethon.sync import TelegramClient, events
import asyncio
import datetime
def handle_messages(api_id, api_hash, sender_name, chat_id, text):
async def process_messages():
async with TelegramClient('anon', api_id, api_hash) as client:
@client.on(events.NewMessage())
async def my_event_handler(event):
sender = await event.get_sender()
sender_id = sender.id
chat = await event.get_chat()
chat_id = chat.id
text = event.raw_text
# ู
ููุงุณ ุงูุฒู
ู
checkpoint = datetime.datetime.now()
print(f'Checkpoint: {checkpoint}')
# ุฑุณุงูุฉ ุดุฎุตูุฉ
if chat_id == sender_id:
response = f'ุงููุง {sender_name} , ููุฏ ุชูููุช ุฑุณุงูุชู ุณุฃููู
ุจุงูุฑุฏ ุนููู ุจุฃูุฑุจ ููุช ู
ู
ูู ูุดูุฑุงู ูุชููู
ู.'
await client.send_message(chat_id, response)
# ุฑุณุงูุฉ ู
ุฌู
ูุนุฉ
elif '@Mohammed_Alakhras' in text:
response = f'ุงููุง {sender_name} , ููุฏ ุชูููุช ุฑุณุงูุชู ุณุฃููู
ุจุงูุฑุฏ ุนููู ุจุฃูุฑุจ ููุช ู
ู
ูู ูุดูุฑุงู ูุชููู
ู.'
await client.send_message(chat_id, response)
await client.run_until_disconnected()
asyncio.run(process_messages())
# ุชุนุฑูู ุญููู ุงููุต ูู Gradio
phone_number = gr.inputs.Textbox(label="ุฑูู
ุงููุงุชู", type="str")
# ุชุนุฑูู ุงููุงุฌูุฉ
inputs = [phone_number]
output = "text"
gr.Interface(fn=handle_messages, inputs=inputs, outputs=output).launch() |