Sending message in telegram bot with images
You can use /sendphoto
and set the caption
which appears under an image.
https://core.telegram.org/bots/api#sendphoto
No, You CAN send a text that contains photo in one single message. Telegram allows you do this but that the way is kinda tricky.
- Using https://core.telegram.org/bots/api#sendmessage method, set option
disable_web_page_preview
=>false
- In your
text
data put an image link with invisible character(s) inside your message text.
Example:
$message = <<<TEXT
*** your content ***
*** somewhere below (or above) a link to your image with invisible character(s) ***
<a href="https://www.carspecs.us/photos/c8447c97e355f462368178b3518367824a757327-2000.jpg"> </a>
TEXT;
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: multipart/form-data']);
curl_setopt($ch, CURLOPT_URL, 'https://api.telegram.org/bot<token>/sendMessage');
$postFields = array(
'chat_id' => '@username',
'text' => $message,
'parse_mode' => 'HTML',
'disable_web_page_preview' => false,
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
if(!curl_exec($ch))
echo curl_error($ch);
curl_close($ch);