Open rulim34 opened 4 years ago
Hey @rulim34 why have you closed this issue? Have you managed to get it working?
@Kubitomakita I changed the implementation. Now I send the raw data to my own coded webhook handler, then the webhook handler process it and send a notification to Telegram.
I see, thanks for the update!
Let me reopen this ticket anyway as the underlying issue is still not resolved. I'd like to check and fix the newline characters
Sure. I think I know why it happened. To create a line break in Telegram, is to use \n
, but when I write \n
and save it, it will turn into \\n
. So in the previous webhok handler implementation, I write %0A
on the payload, and then the webhook handler replace it with \n
and send it to Telegram.
Makes sense as we have an issue with escaping \
due to JSON storage.
Thanks. It works for me. I'm using the %0A. I've searching everywhere for this solution. Thank you so much.
Try urlencode($text). It works for me.
I've figured out that only using the json unicode code point escape form: \u000a
(neither \n
\\n
\\\\n
%0A
%25%0A
) will preserve the real line break char, and you have to manually insert or replace all \\\\n
(the double escaped \n
after you write some \n
in notification content) with the raw \u000a
into the notification post content in your wp_posts
table, for replacing it would be like:
UPDATE wp_posts SET post_content = REPLACE(post_content, "\\\\\\\\n", "\\u000a") WHERE post_type = "notification"
note that \\\\\\\\n
is a quadruple escaped \n
for represeting the double escaped \n
, what a leaning toothpick it is!
https://github.com/BracketSpace/Notification/issues/286#issuecomment-753294425
when I write
\n
and save it, it will turn into\\n
It's caused by some escape operations done by the post content filter when the notification is being updated, also any chars within a <>
pair will be removed by strip_tags()
, so writing <{user_email}>
will result in an empty string, we have to use its corresponding html entity like <>
to avoid this.
Excellent find @n0099! I plan to move the notifications to a separate database table, which would resolve many issues.
God Bless you peeple. %0A is working for me
I spent about two days trying to figure out why the following was not working
curl -v -F parse_mode='Markdownv2' --form-string "text=bundle 123 \\n\\nabc" "https://api.telegram.org/bot${BOT_TOKEN}/sendMessage?chat_id=${CHAT_ID}
I tried "text=bundle 123 \n\nabc" "text=bundle 123 \n\nabc" "text=bundle 123 \\n\nabc" "text=bundle 123 \\\\n\nabc" without any luck. %0A does nothing too.
Finally found a working solution
curl -v -F "document=@./bundle.zip" -F parse_mode='HTML' "https://api.telegram.org/bot${BOT_TOKEN}/sendDocument?chat_id=${CHAT_ID}&caption=1%0A22%0A23"
Sure. I think I know why it happened. To create a line break in Telegram, is to use
\n
, but when I write\n
and save it, it will turn into\\n
. So in the previous webhok handler implementation, I write%0A
on the payload, and then the webhook handler replace it with\n
and send it to Telegram.
Cool, it works!
I have the same problem, but nothing works for me. So I used parsed_mode: MarkdownV2 (tap documentation) and double quotes. \r\n
works for me.
P.s. nah 4 years passed :/
Thanks. It works for me. I'm using the %0A. I've searching everywhere for this solution. Thank you so much.
%0A
works perfectly!
Bug description
I can't create line break when using webhook on Telegram Bot API
To reproduce
Steps to reproduce the behavior:
\n
or%0A
) on the text parameter\n
or%0A
) will be printed as character on the Telegram, it doesn't create new line.Expected behavior
New line created when i used the line break character.
Environment
Screenshots
The line break doesn't works:
Expected message: