You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Telegram-bot-sdk v3版本使用链接发送图片报错求助

Telegram Bot SDK v3 发送图片/视频URL报错解决方案

根据错误提示,v3版本要求所有文件类参数(如photo、video),无论是远程URL、本地文件路径还是文件资源,都必须通过Telegram\Bot\FileUpload\InputFile::create()方法包装,直接传入字符串URL会触发报错。

修改后的代码如下:

use Telegram\Bot\Api;
use Telegram\Bot\FileUpload\InputFile;

$telegram = new Api($bot_token);
$telegram->sendPhoto([
    'chat_id' => '533787134',
    'photo' => InputFile::create('https://telegram-bot-sdk.com/img/hero-banner.png'),
    'caption' => 'Some caption'
]);

补充说明

  • 发送本地文件时,将InputFile::create()的参数替换为本地文件绝对路径即可
  • 使用文件资源流时,直接将资源对象传入InputFile::create()即可

内容的提问来源于stack exchange,提问作者mr-mr7

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.23 16:08:12