Closed andryushchenko closed 3 years ago
I will check this and fix it if possible.
I can confirm that a message with _
should work with the API. I have added a new test that confirms that. The issue must have to do with some other problem, I guess...
You can test with a URL like https://api.telegram.org/bot[yourToken]/sendMessage?chat_id=[yourChatId]&text=_ where [yourToken]
and [yourChatId]
are placeholders, of course.
I have made a new version 1.0.10 (There only some Nuget-Pakete are updated). Maybe this helps.
I found this code https://github.com/SeppPenner/Serilog.Sinks.Telegram/blob/71a1e425a42d69be0bec353fa54c93f9dc3fbf3f/src/Serilog.Sinks.Telegram/Sinks/Telegram/TelegramClient.cs#L63 As I understand Markdown formatting mode is used, so according to documentation https://core.telegram.org/bots/api#markdown-style underscore and some other characters should be escaped.
Your test https://github.com/SeppPenner/Serilog.Sinks.Telegram/blob/71a1e425a42d69be0bec353fa54c93f9dc3fbf3f/src/Serilog.Sinks.Telegram.Tests/TestSink.cs#L83 is passed because you have two underscores and this is correct italic text fragment. Suggested simple URL request successes because no formatting mode is used.
You're right, my mistake. I will check what needs to be escaped and provide an update soon.
I resolved this issue in the new version (1.0.11) which should be available soon. Now, the sink uses HTML formatting instead of Markdown or MarkdownV2 as Telegram has a strange markdown flavor in some cases (Escaping didn't work as I expected it to do and so on...). Reference is here https://core.telegram.org/bots/api#html-style. The sink now escapes the mentioned entities as described by Telegram:
All <, > and & symbols that are not a part of a tag or an HTML entity must be replaced with the corresponding HTML entities (< with <, > with > and & with &).
In my test case, the underscore worked properly with that formatting. Just tell me if you have any other issues.
I have faced error sending log message containing symbol _ After some tests I found it should be escaped
SelfLog:
I'm not familiar with Telegram API so I don't know if it is a bug or known limitation, but the workaround with escaping _ before sending message looks correct