The functions in this group prepare data for links and requests to external services: they encode text for a URL, calculate hashes and signatures, and escape Telegram formatting characters.
Where it helps:
- pass the subscriber’s name or email in a link parameter;
- sign a request to a payment service or your own API;
- show text with
_,*,.characters without breaking Telegram formatting.
Functions
| Function | Description | Example |
|---|---|---|
| urlencode(text) | Encodes text so it can be safely added to a link. Spaces become %20. | urlencode("a&b=1") → "a%26b%3D1" |
| urldecode(text) | Decodes text from a link back to plain text. | urldecode("a%26b%3D1") → "a&b=1" |
| base64_encode(text) | Encodes text in Base64. | base64_encode("hello") → "aGVsbG8=" |
| base64_decode(text) | Decodes text from Base64. | base64_decode("aGVsbG8=") → "hello" |
| md5(text) | Returns the MD5 hash of the string. | md5("hello") → "5d41402abc4b2a76b9719d911017c592" |
| sha1(text) | Returns the SHA-1 hash of the string. | sha1("hello") → "aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d" |
| sha256(text) | Returns the SHA-256 hash of the string. | sha256("hello") → "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824" |
| hmac_hex(key, text, algorithm) | Returns an HMAC signature of the text with a secret key, in hexadecimal. Algorithm: sha256 (default), sha1, sha512 or md5. | hmac_hex("key", "The quick brown fox jumps over the lazy dog") → "f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8" |
| tg_escape(text) | Adds a backslash before Telegram formatting characters (_ * [ ] ( ) ~ ` > # + - = | { } . !) so the text is shown as is. | tg_escape("1.5*2") → "1\.5\*2" |
Example: the subscriber’s name in a link
client.link = "https://site.com/order?name=" + urlencode(client.name)
If the subscriber’s name is “John Smith”, the link is https://site.com/order?name=John%20Smith. The site receives the name unchanged, and the space doesn’t break the address.
Example: signing a request to a payment service
Many services ask you to sign a request with a secret key to verify it came from you. Keep the key in a global variable, not in the formula text.
client.sign = hmac_hex(globals.secret_key, str(client.order_id) + ":" + str(client.amount))
Pass the sign value in the external request along with the order number and amount. The default algorithm is sha256; if the service needs another one, pass it as the third argument: hmac_hex(globals.secret_key, text, "sha512").
Example: text that doesn’t break Telegram formatting
client.safe_name = tg_escape(client.name)
If the subscriber’s name contains _ or *, Telegram may treat them as formatting. After tg_escape they are shown as plain text.
How to insert macros into URL buttons is described in Macros.
If you did not find the answer to your question, feel free to contact us in the chat inside your dashboard, message us on Telegram at @BotHelpSupportBot, or email us at hello@bothelp.io.
Enjoy the full functionality of the BotHelp platform for creating broadcasts, automated funnels, and chatbots — free for 14 days.
Sign up for BotHelp
Get 14 days of full access for free — enough to build your first bot and test it on real subscribers.
Create account