Skip to content

A set of useful command line tools to interact with telegram using telethon and python-fire.

License

Notifications You must be signed in to change notification settings

LeiShi1313/TeleFire

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Telethon X Fire - TeleFire

A set of userful command line tools to interact with telegram.

What has inside | How | Docker

What is inside

  • 🎏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.

Usage

Setup

  1. Login to your Telegram account with the phone number of the account you wish to use.
  2. Click API Development tools.
  3. A Create new application window will appear if you didn't create one. Go head and create one.
  4. Once you finish creation, get the api_id and api_hash, you will use it later.

get_all_chats

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.

list_messages

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.

search_messages

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, default 100.
  • --from_id [USER_IDENTIFIER]: The id/username of the message sender.

delete_all

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.

plus_mode

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]

words_to_ifttt

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.

Other commands

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.

Docker

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!

TODO

  • ✔️ 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.

About

A set of useful command line tools to interact with telegram using telethon and python-fire.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published