电报BOT,发送带有gif附件的消息

时间:2019-11-08 08:52:58

标签: php bots telegram

我使用此代码通过https://stackoverflow.com/a/32296353/6017365处的BOT发送图像,效果很好:

$bot_url    = "https://api.telegram.org/bot<bot_id>/";
$url        = $bot_url . "sendPhoto?chat_id=" . $chat_id ;

$post_fields = array('chat_id'   => $chat_id,
    'photo'     => new CURLFile(realpath("/path/to/image.png"))
);

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    "Content-Type:multipart/form-data"
));
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields); 
$output = curl_exec($ch);

然后我对其进行了修改,以使用sendVideovideo参数发送gif。

现在,我想编辑文件以发送带有gif作为附件的普通文本。...我试图在数组中添加text参数,但仅收到图像... 有什么建议吗?

1 个答案:

答案 0 :(得分:1)

只是为了澄清@AliKhalili的回复;

sendVideo接受称为caption可选参数,以向视频中添加一些文本。

与使用必需 text字段的sendMessage不同。