'How can I include '#' in my telegram BOT message?

I was trying to send a message through my telegram bot and the bot is working fine. The only problem is that the message body does not include the text after the character '#'.

So, if you are trying to send a message "Stack # Overflow". The message received is "Stack ".

const messageBody = `\n<strong>Send message</strong>\n
    <b>Journey details</b>
    <b>Estimated Distance: </b>${data.journeyDetails.estimatedDistance}
    <b>Estimated Time: </b>${data.journeyDetails.estimatedTime}
    <b>Pickup Address: </b>${data.journeyDetails.pickupAddress}
    <b>Drop Address: </b>${data.journeyDetails.dropAddress}\n
    `;

  await sendTelegramMessage(
    `${TELEGRAM_HOST}${TELEGRAM_API_ACCESS_KEY}/sendMessage?parse_mode=html&chat_id=${telegramChatId}&text=${messageBody}`
  );

Sometimes the pickup and drop address contains '#'.



Solution 1:[1]

You are using HTML, thus you need to escape the #-charcter. You could use %23 instead of # or use the function encodeURI(yourMessage). See this question for reference.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 A-Tech