Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I send Tables with Telegram Bot API?

I need to send stock market data and the formatting sucks right now. Need to send something liike this

| Symbol | Price | Change |  |--------|-------|--------| | ABC | 20.85 | 1.626 |  | DEF | 78.95 | 0.099 |  | GHI | 23.45 | 0.192 |  | JKL | 98.85 | 0.292 | 

This is what I have tried.

| Symbol | Price | Change |   |--------|-------|--------|   | ABC | 20.85 | 1.626 |    | DEF | 78.95 | 0.099 |    | GHI | 23.45 | 0.192 |     | JKL | 98.85 | 0.292 | 
like image 240
Aditya Avatar asked Mar 18 '18 08:03

Aditya


People also ask

Can Telegram Bots store data?

Telegram stores all data, i.e. all chats and also the bots, encrypted in the cloud.

What can I do with Telegram API?

This is the API used by Telegram apps for all your actions on Telegram. To name a few: viewing your chats, sending and receiving messages, changing your display picture or creating new groups. Through the Telegram API you can do anything you can do in a Telegram app programatically.


1 Answers

Set the Telegram API parse_mode parameter to HTML and wrap the message in <pre></pre> , but remember that telegram API does not support nested tags.

<pre> | Tables   |      Are      |  Cool | |----------|:-------------:|------:| | col 1 is |  left-aligned | $1600 | | col 2 is |    centered   |   $12 | | col 3 is | right-aligned |    $1 | </pre> 

Result in Telegram messanger:

ScreenShot from telegram bot

Updated. How convert the tables in the picture

There will be a problem on the small screens of smartphones. So this method is not good. The only option is to convert the tables in the picture and so send :

  1. Or you can convert HTML to image using a headerless browser on your server.
  2. Or you can convert HTML to image using here external API services
  3. Or you can convert HTML to image using more difficult way by php GD
like image 51
Ruslan Novikov Avatar answered Sep 28 '22 08:09

Ruslan Novikov