Last active
March 18, 2023 22:36
-
-
Save md-farhan-memon/4ff51b81cba44bffce48f39ad3c0540f to your computer and use it in GitHub Desktop.
Script to listen to Telegram messages as a user, filter by keywords and push it to slack or do whatever you need. Using Telethon.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from telethon import TelegramClient, events, sync | |
import re, requests | |
# Remember to use your own values from my.telegram.org! | |
api_id = '...' | |
api_hash = '...' | |
username = '...' | |
channel_name = '...' | |
slack_webhook_url = '...' | |
client = TelegramClient(username, api_id, api_hash) | |
@client.on(events.NewMessage(chats=channel_name)) | |
async def my_event_handler(event): | |
text = event.raw_text | |
if re.search("(any|keyword|to|filter)", text, re.I): | |
print(text) | |
obj = {'text': "https://t.me/" + channel_name + "/" + str(event.message.id)} | |
requests.post(slack_webhook_url, json = obj) | |
print('slacked!') | |
client.start() | |
client.run_until_disconnected() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment