0

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 '#'.

1 Answers1

0

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.

A-Tech
  • 806
  • 6
  • 22