Spaces:
Running
Running
import gradio as gr | |
from telethon.sync import TelegramClient, events | |
import asyncio | |
import datetime | |
api_id = '10086982' | |
api_hash = '3ed461889a88b31fcbc323d13e43cf7e' | |
def handle_messages(): | |
async def process_messages(): | |
async with TelegramClient('anon', api_id, api_hash) as client: | |
async def my_event_handler(event): | |
sender = await event.get_sender() | |
sender_id = sender.id | |
sender_name = sender.first_name | |
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 | |
# ุชุนุฑูู ุงููุงุฌูุฉ | |
inputs = [] | |
output = "text" | |
gr.Interface(fn=handle_messages, inputs=inputs, outputs=output).launch() |