Sending message in telegram bot with images

前端 未结 4 1743
一整个雨季
一整个雨季 2021-02-20 04:27

I have telegram-bot code on php, and reply messages sending by replyWithMessage method.

All command here:

 $this->replyWithMessage([\'te         


        
4条回答
  •  抹茶落季
    2021-02-20 05:09

    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.

    1. Using https://core.telegram.org/bots/api#sendmessage method, set option disable_web_page_preview => false
    2. In your text data put an image link with invisible character(s) inside your message text.

    Example:

    $message = << ‏ 
    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/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);
    

提交回复
热议问题