Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send an Embedded Image along with text in a Message via Telegram Bot API

Using Telegram Bot API,

I'm aware that it is possible to send an image via https://core.telegram.org/bots/api#sendphoto

However, how can I embed a remote image into a formatted message?

The message I am looking to send, can be compared to a news article with a title in bold, an image, and a longer text with links. I figured out how to create bold text and links with markdown, but I'm failing at inserting images. How can we do that?

like image 548
Pierre-Antoine Avatar asked Jul 31 '16 15:07

Pierre-Antoine


People also ask

Can Telegram BOT send pictures?

Photo to send. Pass a file_id as String to send a photo that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a photo from the Internet, or upload a local photo by passing a file path.

Can Telegram BOT send SMS?

Telegram Bot is a WordPress plugin that allows you to send automatic messages, emails and SMS based on Telegram conversations and much more. You can use the Telegram Bot WordPress plugin to automate business workflows involving the messenger app.

Can Telegram BOT send files?

Bots can currently send video files of up to 50 MB in size, this limit may be changed in the future. Use this method to send video files that are already on the Telegram servers.


2 Answers

you must set ParseMode in HTML and set your Image Url in A tag like this:

<a href="' + image + '">&#8205;</a>

&#8205; -> never show in message

like image 103
barzin.A Avatar answered Sep 25 '22 13:09

barzin.A


You can use zero-width space trick. Works for both Markdown and HTML parse mode.

Markdown:

$data = [
    'chat_id'    => $chat_id,
    'parse_mode' => 'markdown',
    'text' => "[​​​​​​​​​​​](https://upload.wikimedia.org/wikipedia/commons/thumb/0/02/Stack_Overflow_logo.svg/200px-Stack_Overflow_logo.svg.png) Some text here.",
];

Result:

enter image description here

Note: The zero-width space is in-between the brackets "[​​​​​​​​​​​]".

like image 28
Bing Han Avatar answered Sep 23 '22 13:09

Bing Han