Modification & Replace
You can change a message as you like adding/adjusting the title (header), body, footer and a link to the original message.
Changing title
Where is it
Menu → Forwarding rule settings → Choose source and destination → Header
The way header (the title of a channel) is being shown in your subscriptions and your forwards can be modified.
⏵Commands
/setting header + one of the following options: none - no title Ex./setting header none
Ex./settingchannel
simple - add original channel's title in the beginning Ex.source_channel_reference
header none/setting header
simple Ex./settingchannel
bold - add original channel's title in the beginning, make it bold Ex.source_channel_reference
header simple/setting header bold
Ex./settingchannel
from_only - don't show the title of the direct source, but show the title of the original source (if there is one) Ex.source_channel_reference
header bold/setting header from_only
Ex./settingchannel
id - add original message's ID in the beginning Ex.source_channel_reference
header from_only/setting header
id Ex./settingchannel
any other text - add this text as a channel's title in the beginning Ex.source_channel_reference
header id/setting header
My Telegram Channel Ex./settingchannel
source_channel_reference
header My Telegram Channel
You can adjust this setting in the menu, but also you can use the commands. If you are using the commands, to apply this setting to one channel only, replace the command /setting
with /settingchannel source_channel_reference
(read more).
Changing a link in the footer
Where is it
Menu → Forwarding rule settings → Choose source and destination → Link to the original message
By default on the Economy 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 or disable this footer at all.
Please notice that this setting changes only the link added by @junction_bot at the end of the message. This setting doesn’t affect any other links in the message. How to modify other links please see here.
⏵Commands
/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
You can adjust this setting in the menu, but also you can use the commands. If you are using the commands, to apply this setting to one channel only, replace the command /setting
with /settingchannel source_channel_reference
(read more).
Changing body with Before & After
Where is it
Menu → Forwarding rule settings → Choose source and destination → Add in the beginning/end
With these settings 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>
.
⏵Commands
/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.
You can adjust this setting in the menu, but also you can use the commands. If you are using the commands, to apply this setting to one channel only, replace the command /setting
with /settingchannel source_channel_reference
(read more).
Changing body and buttons with Replace
Where is it
Menu → Forwarding rule settings → Choose source and destination → Replacements
You can set an auto-replacement rule that will replace a text A in the incoming messages with a text B (or with an empty string, just remove the text B).
It is important to make the following character changes:
- In place of
<
use<
- In place of
>
use>
This can be done by using the find-and-replace function in any text editor.
⏵Commands
Commands
/replace - replace text A with text B OR remove this rule if repeated second time. Format:/replace
Ex.source_channel_reference
text to replace target text/replace
- will replace all occurrences of "To be or not to be" coming from the source_channel with "Wake up!" Ex.source_channel_reference
To be or not to be Wake up!/replace
- will remove all occurrences of "My advertisement" coming from the source_channel (literally will replace them with nothing) /replacerx - create a replacement rule using regular expressions. The format is the same as with /replace. /replace source_channel_reference - see all replace rules in the source_channel /replacerx source_channel_reference - see all RegEx replace rules in source_channel When using these commands you should make the following changes: - In place of white spaces between words you put the (stands for NBSP - non-breaking space). Please note that is used only with the command /replace. You don't need it when working with filters. - In place of new lines you put <br> To remove the replacement rule use the same command with the same arguments for the second time.source_channel_reference
My advertisement
Please note that these replacement rules work only with the body of a message and with the buttons, not changing the header (with the channel’s name) and the link to the original post.
If you have multiple forwarding rules from the same source to different destinations, you can set different settings, filters and replacements for different destinations. See more details here.
Please see more examples here.
Replace with regular expressions
Also, you can use regular expressions to do your replacements. For that use the checkbox RE on the replacement rule panel or 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 “Java 8” and set the flags “Single line: Dot matches the new line” and “Global: Don’t return after the first match”. This will make it work in the same way as a @junction_bot’s matcher.
Help with regular expressions
Regular expressions are a vast topic. Help in this area is beyond the scope of the bot administration. Please do not write to admins in private asking them to make you a replacement rule or a filter. Also, the bot administration does not provide this kind of help in the support group.
The easiest way to have a regular expression created for your needs is to ask ChatGPT, it’s quite good in it. A support bot is available for Direct Connection subscribers, it is always ready to help in compiling the correct regular expressions.
Also, you can look for help in appropriate forums. For example StackOverflow or CodeProject.
Useful replacement rules

Yes, we know, regular expressions are hard. Here are ready-made expressions for some popular tasks that you can do with replacement rules. Some of them can be solved without RegEx, but most need it.
If you use the main menu to create replacements, then specify the second argument of the /replace command in the From field, and the third in the To field. For instance, in example #4, the From field will contain <a[^<]+</a>
, and the To field will be empty. Also, since the /replacerx
command is used, the RE checkbox must be checked.
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 text in a message’s body can be removed with a command /replace
3.1. /replace source_channel_reference <a href="https://concrete-link-here">text of the link here</a>
This will replace these specific links with an empty string
3.2. /replace source_channel_reference @username
This will remove all occurrences of @username
4. Any formatted links in a message’s body can be removed with/replacerx source_channel_reference <a[^<]+</a>
5. Any raw links can be removed with/replacerx source_channel_reference (http:\/\/|https:\/\/)([a-zA-Z0-9.\/\?=&_]+)
6. To remove only links containing t.me use/replacerx source_channel_reference (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_channel_reference @([a-zA-Z0-9=&_\-]+)
8. To remove the whole part of the message starting with the word “Postscriptum”/replacerx source_channel_reference Postscriptum.*
9. Remove all numbers in format #12345/replacerx source_channel_reference #([0-9]+)
10. Remove every line containing a keyword
/replacerx source_channel_reference .*\bkeyword\b.*
11. Remove every line containing a keyword
, followed by digits (like “keyword123”)/replacerx source_channel_reference ^keyword[0-9]*$
12. Make a keyword
look bold/replace source_channel_reference keyword <b>keyword</b>
13. Remove empty lines/replace
source_channel_reference
<br><br> <br>
14. Remove all texts. Only media-like images will stay./replacerx source_channel_reference .*
15. Make all numbers look bold. Note that in the last argument we are inserting the text, matched by a RegEx, using the reference $1. You can read more about this powerful feature, for example, here./replacerx source_channel_reference ([0-9]+)
<b>$1</b>
16. Remove all text, leaving only a line with “Token: 0xdAC17F958D2ee523a2206206994597C13D831ec7”, where a token address can be any ETH20 address. /replacerx
source_channel_reference
(?s).*(Token: 0x[a-zA-Z0-9]+).*$1
What happens here?
– is just a space, you can replace it with a space if you work through menus instead of commands. So our expression is actually (?s).*(Token: 0x[a-zA-Z0-9]+).*
We say that we want to replace all text matching the expression with the value of the first group ($1). The first group in our case is (Token: 0x[a-zA-Z0-9]+)
.
The (?s).*
and .*
wrapper makes it so that all text around the line we want is replaced. Since .*
covers at most one line, we add a modifier (?s)
. Thanks to it, .*
will cover all lines before and after the tokenized line we need.
Replacing links
Links in a message can be of different types, so there is no one-size-fits-all command. First, we have to determine the type of link, and only then we can create the right replacement rule. To determine the type of a link, you must turn on the explain-report in Menu → Forwarding settings → Choose source and destination → Explanation report or with the command
/settingchannel source_channel_reference explain on
Now for every new message in this source, the bot will send a report including the raw, unformatted text of the message. This is how the bot sees the message when it applies the replacement rules. After enabling the report, we have to wait for a new message in the source containing the link we want to change.
Option 1. In the incoming report, we see that the link is given using the tag <a>. For example:Great news!
We won the "Fastest Telegram bot!" award.
<a href="https://old.junctionbot.io/getting-started/">Welcome to our website!<a>
Then in the replacement rule, we need to use this entire construction, remembering to replace all the spaces with
The following command will remove this link from the message:/replace
source_channel_reference
<a href="https://old.junctionbot.io/getting-started/">Welcome
to
our
website!</a>
This command will replace such a link with https://lectumbot.com:/replace
source_channel_reference
<a href="https://old.junctionbot.io/getting-started/">Welcome
to
our
website!</a>
<a href="https://lectumbot.com">Welcome
to
our
website!</a>
Be careful, there are only 3 spaces in the last command, between the arguments: source, what to change and what to change to.
Option 2. In the incoming report we see that the link is specified without formatting, just as text. Then there is no <a> tag around the link.
For example:Great news!
We won the "Fastest Telegram bot!" award.
Welcome to our website!https://old.junctionbot.io/getting-started/
Then, without any cunning, in the replacement rule we just specify a link. To remove it, we use the command:/replace
https://old.junctionbot.io/getting-started/source_channel_reference
To replace it with another link:/replace
https://old.junctionbot.io/getting-started/ https://lectumbot.comsource_channel_reference
Other options
If a link to the original post is added by the bot itself, it can be removed with the command/setting link none
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 this number with the /forwards
command. If you have an Economy 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 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
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 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 addpoints
to a previous SL
. Let’s use the command /replacerx
, which allows us to use regular expressions./replacerx &1234567890#1122334455 \nTake-Profit 1.*\n points<br>
In regular expressions, \n
corresponds to a new line, .*
corresponds to any combination of symbols. This way \nTake-Profit 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 3
with TP:
/replacerx &1234567890#1122334455 Take-Profit 2.*Take-Profit 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!
Replacing premium emojis
A premium emoji is represented by a tag <strong>
, for instance:
<strong documentid="123456789">????</strong>
You can get the exact code by enabling the explanation report (Menu → Forwarding settings → Choose source and destination → Explanation report) and sending an emoji to the source channel.
Knowing the exact code of the emoji, you can replace this emoji or add this emoji to your message with before/after. Remember, that to post premium emojis, your replacement rule should fulfill certain conditions.
AI-assisted editing and translation
You can describe in free form the changes you want to make to the text of your messages and let the AI do the rest of the work. In this way, you can either change some text elements or numbers, or rewrite the text completely anew (e.g. in a different language, in a different style, summarizing it, analyzing and inferring, etc.).
To learn how to set it up, see here.
Manual editing, replacing photos, videos etc
If you want to manually edit posts before posting them to a destination, use the review mode.
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_reference
/replacerx source_channel_reference
Enable explanation mode for your source:
Where is it
Menu → Forwarding rule settings → Choose source and destination → Processing report
Or with the command
/settingchannel source_channel_reference 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.
If you are still having difficulties, feel free to ask for help in the support chat. Your request should contain:
1. A forwarded message from the source
2. An explanation report for this message
3. A link to a regex101.com project containing the message’s body and the regex which you are trying to fix
4. A forwarded message from the destination
5. A bot’s response to a command /replacerx source_channel_reference
In 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 a @junction_bot’s matcher.
Questions about RegEx replacers not working will not be answered by the support without these pieces of information.