2

currently I'm working on a telegram bot in php and Yii2 framework. I want to send a message that has a fixed width in telegram. if i send "Hi!" it should fill a line like this image: enter image description here

is it possible? I want the spaces after message so <br> wont do that and breaks the line right after the word 'Hi'. can I do this without <code> tag? because this tag make the message like a line of code.

Matteo Enna
  • 1,285
  • 1
  • 15
  • 36

1 Answers1

4

White space(s) and newline(s) at the two ends of the string are trimmed for a good reason. So, it is not possible to send the text with space or newline character(s) at any of the two ends, though you can put spaces at the end of the lines before the last character that's neither a space nor a newline.

Update #1 There is a trick though. You can add Zero-width non-joiner as the text to a <a> tag with empty href after any number of spaces you want. So the essential params for sendMessage method will be:

$text = 'hi‌‌‌‌‌‌‌‌‌‌‌‌                           <a href="">&#8204;</a>';
$chat_id = <your chat_id>;
$parse_mode = 'HTML';


enter image description here

ManzoorWani
  • 1,016
  • 7
  • 14
  • actually its not the perfect way, i think i was so excited!! :( its fine in telegram desktop but when you look at your android phone there are characters like | (pipeline character) in the message. i think they are Zero-width non-joiners. but its better than nothing. if there is anyway to hide them i'll be appreciate it – mohammad fallah.rasoulnejad Mar 19 '17 at 07:10
  • The screenshot I shared is from my android phone and there is nothing like a pipeline character. Can you share the code you are using to send such a message? – ManzoorWani Mar 19 '17 at 07:14
  • The pipeline character may be on a specific device whose font may not be handling the `‌` properly, even though it's a non printable character. You should check on another device. I used my Moto G4 Plus. – ManzoorWani Mar 19 '17 at 07:18
  • thanks I got the problem. my android phone is LG optimus L5. the problem is with my phone's fonts. I sent the message to a nokia_x2 and it was clear there. thanks guys. – mohammad fallah.rasoulnejad Mar 19 '17 at 08:03