| 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()) |
|
|
| |
| phone_number = gr.inputs.Textbox(label="ุฑูู
ุงููุงุชู", type="str") |
|
|
| |
| inputs = [phone_number] |
| output = "text" |
|
|
| gr.Interface(fn=handle_messages, inputs=inputs, outputs=output).launch() |