A set of userful command line tools to interact with telegram.
What has inside | How | Docker
- ๐get_all_chats: Fetches all the chat IDs and names.
- ๐list_messages: List messages in a certain chat.
- ๐search_messages: Search messages in a certain chat.
- ๐delete_all: Delete all the messages that you have permission to delete in a certain chat.
- โplus_mode: Delete certain messages after certain time.
- ๐ฌwords_to_ifttt: Send an event to IFTTT when somebody said some words you interested.
- ๐special_attention_mode: Get notified when someone in special attention mode said something.
- Login to your Telegram account with the phone number of the account you wish to use.
- Click API Development tools.
- A
Create new application
window will appear if you didn't create one. Go head and create one. - Once you finish creation, get the
api_id
andapi_hash
, you will use it later.
TELEGRAM_API_ID=[YOUR_API_ID] TELEGRAM_API_HASH=[YOUR_API_HASH] python telefire.py get_all_chats
-100XXXXXXXXXX: CHANNEL_NAME0
XXXXXXXXXX: CHANNEL_NAME1
Those negative IDs start with -100
are private groups, that's the only way you can access to these groups. For public groups, you can either use id, public url, username to access to it.
TELEGRAM_API_ID=[YOUR_API_ID] TELEGRAM_API_HASH=[YOUR_API_HASH] python telefire.py list_messages --chat [CHAT_IDENTIFIER] [Optional: --user USER_IDENTIFIER]
For CHAT_IDENTIFIER
, it can be a chat ID you got from get_all_chats, or it can be something like t.me/LGTMer
or LGTMer
.
For USER_IDENTIFIER
, it can be the user's ID or username.
TELEGRAM_API_ID=[YOUR_API_ID] TELEGRAM_API_HASH=[YOUR_API_HASH] python telefire.py search_messages --peer [PEER_IDENTIFIER] --query [QUERY_STRING]
This command comes with some optional parameters that you can custom:
--slow
: Whether to use telegram's search API or iterate through whole message history to do the search. The later can be comprehensive if you are searching UTF-8 characters such as Chinese.--limit [INTEGER]
: Set the limit of search result, default100
.--from_id [USER_IDENTIFIER]
: The id/username of the message sender.
TELEGRAM_API_ID=[YOUR_API_ID] TELEGRAM_API_HASH=[YOUR_API_HASH] python telefire.py delete_all --chat [CHAT_IDENTIFIER] [Optional: --query QUERY_STRING]
For CHAT_IDENTIFIER
, smiliar to CHAT_IDENTIFIER
in get_all_chats, or it can be something like t.me/LGTMer
or LGTMer
.
You can also using the --query
to specify only messages containing certain string will be deleted.
TELEGRAM_API_ID=[YOUR_API_ID] TELEGRAM_API_HASH=[YOUR_API_HASH] python telefire.py plus_mode
It's a command you have to keep it running in the backgroud to use it. It's my personal favorite command! It includes several functions that's interesting and useful:
Auto delete mode
: Add\[NUMBER][s|m|h|d]
before the message you want to auto delete after certain time, for example, add\10s
(notice the space), then this message will be deleted automately after 10 seconds. you can also specify minutes(m
), hours(h
) and days(d
) as the message experation time.Shiny mode
: just try it, add\shiny
to your original message!.Search mode
: \search [CHAT] [USERNAME] [Optional: QUERY]
TELEGRAM_API_ID=[YOUR_API_ID] TELEGRAM_API_HASH=[YOUR_API_HASH] python telefire.py words_to_ifttt --event [IFTTT EVENT] --key [IFTTT WEBHOOK KEY] [WORDS YOU INTERESTED]
Like auto_delete
, you need to keep this command running to make it work. For the event
and key
, you can get it from here. For WORDS YOU INTERESTED
, it can be something like telefire "telefire is so cool"
, then whenever anybody said telefire or telefire is so cool, an IFTTT event will be sent and you can create an applet to do whatever you like on IFTTT, such as sending notifications, turn on a light, etc.
For all the others commands I didn't methtion or simply too lazy to add docs for it:
python telefire.py --help
to get a list of all the available commands. And:
python telefire.py COMMAND - --help
to learn how to use it.
This project also come with a Dockerfile
so that you don't need to setup any python environment, just run the following command:
docker build . -t telefire
docker run -ti --rm -v $(pwd)/telefire.py:/tg/telefire.py telefire python telefire.py [COMMAND] [OPTIONS]
And that's it, enjoy!
- โ๏ธ For deleting messages, add an option to delete messages based on time instead of always delete all.
- โ๏ธ A long-running service that will notify user if someone said something contains some interested words.