Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding line break to text message using Telegram bot

im trying to send telegram messages from Linux bash using curl. My current problem is that i am unable to send line breaks in the message.

My code is something like this:

msg="<a href=\"${img}\">&#160;</a><b>${title}</b><a href=\"${lnk}\">MORE INFO</a>"

curl --data chat_id=$chatID --data-urlencode "text=${msg}" "https://api.telegram.org/bot${apik}/sendMessage?parse_mode=HTML"

i tried with </br> \n %0D%0A, and none work.

like image 630
Dawix Avatar asked Oct 27 '25 00:10

Dawix


1 Answers

Maybe try setting your $msg variable as a heredoc:

#!/bin/bash

img="one"
title="two"
lnk="three"

read -r -d '' msg <<EOT
<a href="${img}"></a>
<b>"${title}"</b>
<a href="${lnk}">MORE INFO</a>
EOT

curl --data chat_id="$chatID" --data-urlencode "text=${msg}" "https://api.telegram.org/bot${apik}/sendMessage?parse_mode=HTML"

↳ Wikipedia : Here Documents

like image 52
l'L'l Avatar answered Oct 28 '25 15:10

l'L'l



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!