Filtering

You can manage incoming messages by applying filtering rules. You decide which messages you receive and which will be filtered out so you will not see them (like advertisements, for example).

Filters can be applied to channels separately or to all channels at once. You can combine any quantity of filters of any kind.

Supported features: mustHave, mustNotHave, regex, filtering by attachment type, copy filters.

Commands

/filter - create a filter (for 1 source) OR remove a filter if entered second time. Combines with: 'mustHave', 'mustNotHave', 'every', type of attachement /filterrx - filtering by regex (see examples here) /filterall, /filterrxall - create a filter for all sources /filter source_channel - see all current filters applied to a channel

How to point the source_channel? Read here!

If you are using Direct Connection, please replace source_channel with your virtual channel ID (i.e. &1234567890#787878)

mustHave, mustNotHave

mustHave - you will receive only messages with a specific text
Format: /filter source_channel mustHave text to receive
Ex. /filter https://t.me/junction_bot_news mustHave cool cats
Please remember that the text of a filter applies as a whole phrase, not as separate words. So in this example you will receive all messages containing an exact phrase "cool cats". You don't need to use any escape characters like   here.

mustNotHave - filters out messages with a specific text
Format: /filter source_channel mustNotHave text to filter out
Ex. /filter https://t.me/junction_bot_news mustNotHave old hats

Combining filters

Several mustHave filters will be combined based on the “OR” rule.

Several mustNotHave filters will be combined based on the “AND” rule.

Note: You can’t combine them in one command. You should use a separate command for every filter.

Examples:
/filter @junction_bot_news mustHave cats
/filter @junction_bot_news mustHave kittens
You will receive all messages containing either the word 'cats' or the word 'kittens'
/filter @junction_bot_news mustNotHave dogs
/filter @junction_bot_news mustNotHave puppies 
You will not receive any messages containing words 'cats' or 'kittens'

Filtering by type of attachment

Also you can filter out media messages. For that use one of the following strings as a filter text: <photo>, <document>, <audio>, <video>, <sticker>, <voice>, <location>, <animation>, <videonote>, <poll>.

Examples:
/filter source_channel mustHave <audio> - you will receive only messages containing audio attachments from the channel
/filter source_channel mustNotHave <photo> - you will not receive any messages containing pictures from the channel

Advanced filtering

You can use filtering by regular expressions (regex). Use command /filterrx for it.

Here are some common examples:
1. A word in the caption of an image:
.*word.*<photo>
2. Two words in a certain order
.*word1.*word2.*
3. To make matching case insensitive
(?i:.*wOrd1.*woRd2.*)
4. Any word from a set
.*word1.*|.*word2.*|.*word3.*
5. You can combine them. For example, any of the words, case insensitive
(?i:.*wOrd1.*|.*worD2.*|.*woRd3.*)

Please note that the filter with the regular expression word2 DOES NOT MATCH the message word1 word2 word3, as it contains words other than word2. Remember to add .* On both sides of the word: .*word2.*

To filter out all the messages containing both words in any order, you should use two filters:
.*word1.*word2.*
.*word2.*word1.*

For example:
/filterrx source_channel mustNotHave .*bitcoin.*litecoin.*
/filterrx source_channel mustNotHave .*litecoin.*bitcoin.*

Note an important nuance: when filtering, the bot can add a space and/or a media content code at the end of the text. Therefore, we advise you to always put .* at the end of your RegEx filters.

If you need something more complicated, please don’t ask in the support group. Read an article, there are thousands of them on the Internet. Ask in the corresponding forum or just google your case and find a ready solution.

There is a very convenient instrument to test regular expressions: https://regex101.com. Set the Flavor to “golang” and set the flag “Single line: Dot matches the new line”. This will make it work in the same way as @junction_bot’s matcher.

Setting a filter to all your sources

To add a filter to all your current sources, use the /filterall or /filterrxall (for regular expressions) command.

Please note that new forwarding rules are always created with an empty filter list. You can copy filters to them from an existing source.

For instance:
/filterrxall add mustNotHave .*(http\/\/:|https:\/\/).*

This command will add to all your sources a filter, which will stop any message containing a link.

Copy filters

You can copy all filters from one channel to another. To do this use the following command format:

/filter channel_to_copy_filters_to addAllFrom channel_to_copy_filters_from

Remove filters

To remove a filter just send the same command once more.

To see all current filters applied to a channel use command

/filter source_channel

To delete all filters from all your channels use the command

/filterall DELETE ALL

For RegEx filters use /filterrx and /filterrxall correspondingly.

Receiving only N-th message

You can set a frequency of precessed messages, so only every n-th message will be copied (in the following example – every second message). To do this, use the following command format:

/filter source_channel every 2

Filtering by date and time

You can set up the filtering of messages depending on the date and time they come.

/filtertime source_channel mustHave time interval

Time interval sets:
– The interval when messages should come for mustHave
– The interval when messages should not come for mustNotHave

Time interval may contain day of the week, time and timezone.

Day of the week. It always starts with a letter w and then follow the numbers of the days of the week (starting from Mon).
Example:

w135
Corresponds to the 1st, 3rd and 5th days of the week (Mon, Wed, Fri)

w67
Corresponds to the 6th and 7th days of the week (Sat, Sun)

Time. Time is always in 24h format, an interval from – to (inclusive), hours:minutes.
Examples:
9:30-17:30
0:00-23:59

Timezone. Please see the list of available timezones here. If you do not explicitly mention the timezone then it will be set to CET – Central European Time (Amsterdam/Berlin/Prague/Vienna)

Examples:

/filtertime @source mustNotHave 0:00-7:00
Messages will not come from midnight till 7 AM at CET.

/filtertime @source mustHave w12345 8:00-20:00 America/New_York
Messages will come only on working days (Mon-Fri) starting from 8 AM and till 8 PM at New York time.

To add a temporal filter to all your sources you can use the command /filtertimeall. For example:
/filtertimeall mustNotHave 0:00-7:00

Duplicates

In some cases one message can come to you several times. For example, if you are subscribed to two channels that both have forwarded the same post. To filter out all identical messages use the command /setting duplicate.

/setting duplicate + one of the following options:

pass - disabled, allow duplicates
Ex. /setting duplicate pass

filter - filter duplicated messages out
Ex. /setting duplicate filter

To apply this setting to one channel only, replace the command /setting with /settingchannel @channel_name (read more).

Bulk modification of filters

/filterall – this command will add this filter to all your subscriptions and forwardings. Please notice that there is no such thing as a common set of filters – a set of filters applied to all the rules does not exist. There is a set of filters per concrete subscription / forwarding rule.

/filterall works with the same combinations as /filter.

Instead of source_channel you set an action: add or remove.

/filterall add - adds a new filter to all channels.
Format: /filterall add [rule] text to receive
Ex. /filterall add mustHave bitcoin  OR /filterall add mustNotHave litecoin

/filterall remove - removes the filter from all channels.
Format: /filterall remove [rule] text to filter out
Ex. /filterall remove mustHave bitcoin  OR /filterall remove mustNotHave litecoin

Change the command to /filterrxall to use regular expressions.

One source – many destinations

If you have several forwarding rules to different channels from one source and want to set a filter to one source-destination rule only, follow this instruction.

Add the following construction to the source name: ->-1001251642436
Where -1001251642436 is the identifier of the destination channel in the Telegram system plus prefix “-100” (it’s the way how Telegram distinguishes numbers if channels from numbers of other objects). To find this number is very simple, search the Internet for instructions. For example, forward a message from the channel to the bot @junction_helper0_bot. There you will see the channel number in forward_from_chat.id or forward_from.id.
So, for example, the configuration command might look like this:
/filter source_channel->-1001251642436 mustHave cats

Filtering posts of a specific person

Let’s say @source is the source chat. To forward only messages from @user do the following:

  1. Create a new forwarding rule with the command /new
  2. Turn on the copying of authors’ names with the command
    /settingchannel source_channel author full
  3. Set up the filter for the name you need with the command
    /filter source_channel mustHave @user

Finding out what is not working

Check what are the current filters and that they are correct:

/filter source_channel
/filterrx source_channel

If you set up a lot of filters it can be difficult to figure out why a certain message is passing or why it is not. To help you in that there is a special setting called explain. You can set it on with the command:

/settingchannel source_channel explain on

If it’s enabled you will receive a report for every new message coming from this source_channel. The report will explain why this message is filtered out or allowed to pass.

To disbale an explanation mode use the command

/settingchannel source_channel explain off

FAQ

/filter @channel_name – see all current filters applied to a channel.

Please check the following:

  • Filter should be set on a source channel.
  • Filters are sensitive to case.

If words come together in a filter, for example “one two three”, they should also come together in a message – “one two three” – to be matched.
Also remember that unsubscribing from a channel will delete all your filters so use disabling.

If you have a paid account you can use an explanation feature. Activate it by the command /settingchannel … explain on

You will start receiving explanations about filters matching on the messages.

Load More