Telegram node not excaping dot (.) MarkdownV2 Parsing

Describe the problem/error/question

Trying to send a message referencing a previous nodes value using Telegram message sent as MarkdownV2.

  • The above works with Markdown(Legacy) as an FYI so its only the V2 parsing it seems.

Get an error message stating that the DOT [.] is not being escaped and cannot use previous node values. If I escape with a \ the expression breaks.

  • {{ $json.yesterdays_currency_rate }} - dot is not escaped and message wont send
  • {{ $json\.yesterdays_currency_rate }} - breaks the expression (expected)
  • {{ $json\\.yesterdays_currency_rate }} - get invalid syntax error (expected)

Above SS is a simple test with just the previous node value added in. My message is longer and have several but same errors.

What is the error message (if any)?

Bad request - please check your parameters

Bad Request: can’t parse entities: Character ‘.’ is reserved and must be escaped with the preceding ''

Share the output returned by the last node

Information on your n8n setup

  • n8n version: 1.91.3
  • Database (default: SQLite): postgres
  • Running n8n via (Docker, npm, n8n cloud, desktop app): docker
  • Operating system: ubuntu

Hi @gleeballs welcome to the community!

I think the dot (.) that the error referring to isn’t related to the expression itself, but rather to the value it represents, in your case, “0.751654”

I encountered this issue as well and was able to solve it by changing the Parse Mode to HTML

image

Give it a try!

1 Like

This is true. Tested another expression and it works.

However, I need to use MarkdownV2 so somethings is amiss with the parsing somewhere but just not where I thought it was

So we are half solved for now

1 Like

To make that work, you should follow Telegram’s MarkdownV2 rules and escape each character they mention…

For example, the dot (.) is treated as a special character and must be escaped with a preceding backslash (\)

@gleeballs I hope this helps!


If you find this helpful, Kindly mark the reply as the solution :white_check_mark: so others with the same issue can find it easily :pray:t2:

I have read the docs.

I cannot escape the dot when it is being added dynamically via the expression. I cannot edit the data that has come from the previous node via expression.

I do not want to add a set node before either as the values are all dynamic and can change.

Well, these are Telegram’s rules!

If you don’t want to add something to parse and prepare the data so it’s correctly formatted, unfortunately I don’t have a dynamic solution for this…

I hope someone else can help…

I shouldn’t have to add something to prepare the data. The data is coming from an expression that is dynamic

I can use an expression in Markdown(Legacy) & HTML but not in Markdown V2.

This says to me there is something incorrect in the parsing/formatting of expressions to markdown v2 inside the node, hence the bug question.

hi you can try to escape on your dynamic expression like this

{{ $json.yesterdays_currency_rate.toString().replace(/\./, '\\.') }}

Thanks, this works in this simple example. My worry is that there are alot of characters that need escaping as per the docs and if my expression contains many of these characters, how can i escape them all?

I could potentially have all of them in an expression coming through and I won’t know about it until the node fails

  • In all other places characters ‘_’, ‘*’, ‘[’, ‘]’, ‘(’, ‘)’, ‘~’, ‘`’, ‘>’, ‘#’, ‘+’, ‘-’, ‘=’, ‘|’, ‘{’, ‘}’, ‘.’, ‘!’ must be escaped with the preceding character ''.

EDIT: I am also doing some math by adding 2 previous node’s values together and the toString then breaks this. This I could do before hand with a set node, but still something might slip through and stop the node

You can use node code to filter your data source before sending to telegram, this my code to filter from converted markdown default to markdown v2 just throw to AI to fit your flow and of course you can use advance logic to do math or anything you want just make sure you understand the fundamental

function cleanAndFormatText(text) {
  text = text.split('\n').filter(line => {
    return !/(.*?)(\.png|\.jpg|\.jpeg|\.gif|\.webp)/i.test(line);
  }).join('\n');

  // Escape dot
  text = text.replace(/\./g, '\\.');

  // Delete unnecessary char for Telegram Markdown V2
  const invalidChars = /([*_\[\]\(\)~`>#\+\-=\|\{\}\.\!])/g;
  text = text.replace(invalidChars, '');

  // delete all tag HTML
  text = text.replace(/<[^>]+>/g, '');

  // Change image tag to link ![](url)
  const imageRegex = /(https?:\/\/[^\s]+?\.(?:png|jpg|jpeg|gif|webp))/gi;
  text = text.replace(imageRegex, '!($1)');

  return text;
}

// HERE YOUR PREVIOUS PARAMETER MUST MATCH
const inputText = $json.data;

if (!inputText || typeof inputText !== 'string') {
  return [];
}

const cleanedText = cleanAndFormatText(inputText);

return [{
  json: {
    markdownV2: cleanedText,
  },
}];