Php 在带有图像的电报机器人中发送消息
我有php上的电报机器人代码,并通过Php 在带有图像的电报机器人中发送消息,php,telegram,telegram-bot,Php,Telegram,Telegram Bot,我有php上的电报机器人代码,并通过replyWithMessage方法回复发送的消息 此处的所有命令: $this->replyWithMessage(['text' => $item['title']. "\n\n" . $url]); 如何在文本之前添加一些预览图像 无法发送同时包含图像和文本的文本消息。但是,如果文本包含URL,默认情况下,Telegram会显示网页预览。 或者您可以一条接一条地发送两条消息或发送带有标题的照片。您可以使用/sendphoto并设置显示在图
replyWithMessage
方法回复发送的消息
此处的所有命令:
$this->replyWithMessage(['text' => $item['title']. "\n\n" . $url]);
如何在文本之前添加一些预览图像 无法发送同时包含图像和文本的文本消息。但是,如果文本包含URL,默认情况下,Telegram会显示网页预览。
或者您可以一条接一条地发送两条消息或发送带有标题的照片。您可以使用
/sendphoto
并设置显示在图像下的标题。
否,您可以在一条消息中发送包含照片的文本。电报可以让你这样做,但这种方式有点棘手
使用方法,设置选项disable\u web\u page\u preview
=>false
在文本中
数据中,在消息文本中放置一个带有不可见字符的图像链接
例如:
$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);
$message=$message,
“解析模式”=>“HTML”,
“禁用网页预览”=>false,
);
curl_setopt($ch,CURLOPT_POSTFIELDS,$POSTFIELDS);
如果(!curl_exec($ch))
回波旋度误差($ch);
卷曲关闭($ch);
您也可以使用降价:
var axios = require('axios');
axios.post('https://api.telegram.org/'+telegram_bot_id+'/sendMessage', { chat_id: _target_telegram_channel, parse_mode: 'markdown', text: '[ ](https://www.amazon.it/gp/product/B07NVCJ3V8?pf_rd_p=ba8c3f2e-eba5-4c79-9599-683af7a49dd1&pf_rd_r=XPRH5A07HN9W62DK1R84)' } )
.then(response => {
console.log(response);
})
.catch(error => {
console.log(error);
})
它具有0-200个字符的约束。照片标题(也可在按文件id重新发送照片时使用),0-1024个字符。实际信息如下:tl dr:1)put代码>在a标记内部而不是空白2)设置禁用网页\u预览=true