cotestatnt / AsyncTelegram2

Powerful, flexible and secure Arduino Telegram BOT library. Hardware independent, it can be used with any MCU capable of handling an SSL connection.
MIT License
83 stars 25 forks source link

"<" seems to break something? #108

Closed wardom closed 1 year ago

wardom commented 1 year ago

Hello Tolentino, love your work!

I'm new to this, so I might be doing something wrong and apologise if so.

While tinkering, I've found that by adding "<" to an outgoing message the bot doesn't send the message. I've tried using the example codes you've provided but none of them get sent if the message includes "<".

I also tried the "echoBot" example provided. It works flawlessly but if the message includes "<" the bot will not echo the message. image This was done using the echoBot sketch. Other symbols don't seem to cause any problems.

I hope I explained well enough, please let me know if you need anymore information. Thank you for your time.

sanderkob commented 1 year ago

See https://stackoverflow.com/questions/40626896/telegram-does-not-escape-some-markdown-characters where it is mentioned that "<" will be read as tag start and probably unrecognized.

cotestatnt commented 1 year ago

Hi @sanderkob The default formatting options used by AsyncTelegram2 library is HTML The char '<' it's an HTML start TAG so probally the server parser expect the remaining code and this cause error.

Try switching to the MarkdownV2 formatting style.

Check the example or simply add this line: myBot.setFormattingStyle(AsyncTelegram2::FormatStyle::HTML /* MARKDOWN */);

You can try also to encode your message text using entity name or entity number:

Result Description Entity Name Entity Number
non-breaking space &nbsp; &#160;
< less than &lt; &#60;
> greater than &gt; &#62;
& ampersand &amp; &#38;
" double quotation mark &quot; &#34;
' single quotation mark (apostrophe) &apos; &#39;
¢ cent &cent; &#162;
£ pound &pound; &#163;
¥ yen &yen; &#165;
euro &euro; &#8364;
© copyright &copy; &#169;
® registered trademark &reg; &#174;
wardom commented 1 year ago

Hello, thank you for the replies

Added the line: myBot.setFormattingStyle(AsyncTelegram2::FormatStyle::HTML /* MARKDOWN */); Now the bot is able to display the char "<" when using entity names or entity numbers.

Appreciate the help and looking forward to more of your work!