Modification & Replace

You can flexibly customize messages posted by the bot. There are several main commands for that: /setting, /settingchannel and /replace.

/setting – apply changes to all the source channels you have.

/settingchannel – apply changes to one source only (details).

/replace – create a replacement rule for one source.

Generally, with these commands you can change a message as you like adjusting the title (header), body, footer and a source link.

Changing title

The way how header (the title of a channel) is being shown in your subscriptions and your forwards can be modified.

/setting header + one of the following options:

none - no title
Ex. /setting header none
Ex. /settingchannel @channel_name header none

bold - add original channel's title in the beginning
Ex. /setting header bold
Ex. /settingchannel @channel_name header bold

from_only - don't show the title of the direct source, but show the title of the original source (if there is one)
Ex. /setting header from_only
Ex. /settingchannel @channel_name header from_only

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

Changing a link in the footer

By default on the standard account, the bot adds a footer with the link to the original message. This link looks like a symbol @. You can adjust how this footer looks like or disable this footer at all.

Please notice that this setting changes only the link added by @junction_bot in the end of the message. This setting doesn’t affect any other links in the message. How to modify other links please see here.

/setting link + one of the following options:

none - don't include the link
Ex. /setting link none

full - include the link as is
Ex. /setting link full

any other string - conceal link behind this text
Ex. /setting link Channel about kitties

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

Changing body with Before & After

With /setting before and /setting after you can add custom text in the beginning or at the end of the message.

To add a text containing several lines separate them with a tag <br>.

/setting before - add text in the beginning of the message.
Format: /setting before my text
Ex. /setting before So I have heard:<br>
Please notice that the message's body will go just after this text on the same line. If you want to start the message's body from a new line add <br> to the end of your text.

/setting before none - remove your text before the message.

/setting after - add text at the end of the message.
Format: /setting after my text
Ex. /setting after <br>In case of any questions please contact support@mail.com
Please notice that this text will go just after the message's body on the same line. Add <br> to the begining of your text if you want to start it from a new line.

/setting after none - remove your text  at the end of the message.

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

Changing body with Replace

You can set an auto-replacement rule which will replace a text A in the incoming messages with a text B (or with an empty string, just remove the text B). Use the command /replace for that.

It is important to make the following character changes:

  • In place of white spaces between words you put the &nbsp; (stands for NBSP – non-breaking space). Please note that &nbsp; is used only with the command /replace. You don’t need it when working with filters.
  • In place of new lines you put <br>

This can be done by using the find-and-replace function in any text editor.

Commands

/replace - replace text A with text B OR remove this rule if repeated second time. Format: /replace @source_channel text&nbsp;to&nbsp;replace target&nbsp;text Ex. /replace @channel_name To&nbsp;be&nbsp;or&nbsp;not&nbsp;to&nbsp;be Wake&nbsp;up! - will replace all occurrences of "To be or not to be" coming from the @channel with "Wake up!" Ex. /replace @channel_name My&nbsp;advertisement - will remove all occurrences of "My advertisement" coming from the @channel (literally will replace them with nothing) /replacerx - create a replacement rule using regular expressions. The format is the same as with /replace. /replace @channel_name - see all replace rules in the @channel_name /replacerx @channel_name - see all RegEx replace rules in the @channel_name

What can be used as a @channel_name? Read here!

Please note that the /replace and /replacerx commands work only with the body of a message, not changing the header (with the channel’s name) and the link to the original post.

To remove the replacement rule use the same command with the same arguments for the second time.

Replace with regular expressions

Also, you can use regular expressions to do your replacements. For that use the command /replacerx. It has the same format.

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

Useful replacement rules

When you are debugging a regular expression

Yes, we know, regular expressions are hard. Here are ready-made expressions for some popular tasks which you can do with replacement rules. Some of them can be solved without RegEx, but most need it:

1. A header with the name of the original channel can be removed with
/setting header none
2. A link to the original post can be removed with
/setting link none
3. Any concrete links in a message’s body can be removed for example with a command
/replace @source <a&nbsp;href="https://concrete-link-here">text&nbsp;of&nbsp;the&nbsp;link&nbsp;here</a>
This will replace these specific links with an empty string
4. Any formatted links in a message’s body can be removed with
/replacerx @source <a[^<]+</a>
5. Any raw links can be removed with
/replacerx @source (http:\/\/|https:\/\/)([a-zA-Z0-9.\/\?=&_]+)
6. To remove only links containing t.me use
/replacerx @source (t.me)([a-zA-Z0-9.\/\?=&_]+)
This will replace all the with an empty string
7. To remove all links-usernames like @username
/replacerx @source @([a-zA-Z0-9=&_]+)
8. To remove the whole part of the message starting with the word “Postscriptum”
/replacerx @source Postscriptum.*
9. Remove all numbers in a format #12345
/replacerx @source #([0-9]+)
10. Remove every line containing a keyword
/replacerx @source .*\bkeyword\b.*
11. Remove every line containing a keyword, followed be digits (like “keyword123”)
/replacerx @source ^keyword[0-9]*$

Advanced example

Suppose we are running a channel that accumulates free trading signals from other channels, and we want to bring all signals to the same format. An example of a message in the source channel:

Buy BTC/USD
Stop-Loss at 11000
Take-Profit 1 at 11500
Take-Profit 2 at 11700
Take-Profit 3 at 12000

We want to have all messages in the following format:

BUY
#BTC/USD
SL: 11000 points
TP: 12000 points
Trade at your own risk!

Let’s assume that we have already set up a redirection with the /new command. Let’s also assume we’re using Direct Connection and the source channel number is &1234567890#1122334455. You can find out this number with the /forwards command. If you have a Standard account, use a link to the channel instead of &1234567890#1122334455 in all examples, for example, https://t.me/joinchat/AFjgGGiosdgJGgSDG.

We want to replace Buy with a space with BUY, new line and #:
/replace &1234567890#1122334455 Buy&nbsp; BUY<br>#
The first argument is our source &1234567890#1122334455.
The second one is what we want to replace. Please notice that for the commands /replace and /replacerx you need to use &nbsp; instead of spaces.
The third argument is a text which we want to put in place. A new line is <br>.

Next, we have a similar replacing rule: Stop-Loss at is replaced with SL:
/replace &1234567890#1122334455 Stop-Loss&nbsp;at SL:

The next command is going to be more complicated. We want to remove two lines Take-Profit 1 and Take-Profit 2, and instead of them to addpointsto a previous SL. Let’s use the command /replacerx, which allows us to use regular expressions.
/replacerx &1234567890#1122334455 \nTake-Profit&nbsp;1.*\n points<br>
In regular expressions, \n corresponds to a new line, .* corresponds to any combination of symbols. This way \nTake-Profit&nbsp;1.*\n corresponds to Take-Profit 1 together with a new line before it, a price after it (whatever the price is) and a new line after the price. We are replacing two new lines here, so we need to compensate it by adding <br> to the word points.

Next, we replace Take-Profit 2 plus a price and plus Take-Profit 3with TP:
/replacerx &1234567890#1122334455 Take-Profit&nbsp;2.*Take-Profit&nbsp;3 TP:

Finally we add a word points and a line Trade at your own risk! For that we use the setting after, which can add a text at the end of every message.
/settingchannel &1234567890#1122334455 after points<br>Trade at your own risk!

Finding out what is not working

If you have difficulties understanding why your replacement rules are not working you can try the following procedure.

Check what are the current replacement rules and that they are correct:

/replace @source_channel
/replacerx @source_channel

Enable explanation mode for your source:

/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 contain the raw body of the message without formatting. This is the way how bot sees this message before applying replacement rules. Usually, this makes clear why your rule is not applied.

FAQ

There are several possible ways:
1. A source channel’s header can be removed with a command
/setting header none

2. A link to a source post in a footer can be removed with a command
/setting link none

3. Any concrete links in a message’s body can be removed for example with a command
/replace @source <а href="https://concrete-link-here">
This will replace these specific links with an empty string.

4. Any formatted links in a message’s body can be removed with
/replacerx @source

5. Any raw links can be removed with
/replacerx @source (http\/\/:|https:\/\/)([a-zA-Z0-9.\/\?=&]+)

6. To remove only links containing t.me use
/replacerx @source (t.me)([a-zA-Z0-9.\/\?=&]+)
This will replace all the with an empty string.

7. To remove all links-usernames like @username
/replacerx @source @([a-zA-Z0-9=&]+)

Load More