SendMediaGroup Telegram PHP

发布于 2025-02-12 03:53:04 字数 799 浏览 0 评论 0原文

我正在使用电报库

php电报bot sdk

和我想使用 sendmediagroup

这样的消息发送一些照片:

$reply = "*photos*";
$telegram->sendMediaGroup([
     'chat_id' => $chat,
     'media' => [
      ['type' => 'photo', 'media' => 'attach://photo1' ],
      ['type' => 'photo', 'media' => 'attach://photo2' ],
  ],
     'photo1' => InputFile::create(file_get_contents("https://".$_SERVER['SERVER_NAME']."/newbot/screens/ctry/en1.jpg")),
     'photo2' => InputFile::create(file_get_contents("https://".$_SERVER['SERVER_NAME']."/newbot/screens/ctry/en2.jpg")),
     'caption'=> $reply,
     'parse_mode' => 'markdown'
     ]);

我没有 json_encode file_get_get_contents T也工作

I am using telegram library

php telegram bot sdk

And I want to send some photos in message using sendMediaGroup

Like this:

$reply = "*photos*";
$telegram->sendMediaGroup([
     'chat_id' => $chat,
     'media' => [
      ['type' => 'photo', 'media' => 'attach://photo1' ],
      ['type' => 'photo', 'media' => 'attach://photo2' ],
  ],
     'photo1' => InputFile::create(file_get_contents("https://".$_SERVER['SERVER_NAME']."/newbot/screens/ctry/en1.jpg")),
     'photo2' => InputFile::create(file_get_contents("https://".$_SERVER['SERVER_NAME']."/newbot/screens/ctry/en2.jpg")),
     'caption'=> $reply,
     'parse_mode' => 'markdown'
     ]);

I used without json_encode and file_get_contents, but it doesn't worked too

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

瞄了个咪的 2025-02-19 03:53:04

你为什么使用那个库?这是普通的解决方案:

$token = '   TOKEN   ';
$website = 'https://api.telegram.org/bot'.$token;
$update = file_get_contents('php://input');
$update = json_decode($update, TRUE);
$message = $update['message']['text'];
$id = $update['message']['from']['id'];
$name = $update['message']['from']['first_name'];
$surname = $update['message']['from']['last_name'];
$username = $update['message']['from']['username'];

function sendPhoto($id, $photo, $text = null){
    GLOBAL $token;
    $url = 'https://api.telegram.org/bot'.$token."/sendPhoto?chat_id=$id&photo=$photo&parse_mode=HTML&caption=".urlencode($text);
    file_get_contents($url);
}

我还放置了一些有用的变量,并有机会放上标题(如果您不想要一个参数,请不要给出该参数)

Why do you use that library? Here's the normal solution:

$token = '   TOKEN   ';
$website = 'https://api.telegram.org/bot'.$token;
$update = file_get_contents('php://input');
$update = json_decode($update, TRUE);
$message = $update['message']['text'];
$id = $update['message']['from']['id'];
$name = $update['message']['from']['first_name'];
$surname = $update['message']['from']['last_name'];
$username = $update['message']['from']['username'];

function sendPhoto($id, $photo, $text = null){
    GLOBAL $token;
    $url = 'https://api.telegram.org/bot'.$token."/sendPhoto?chat_id=$id&photo=$photo&parse_mode=HTML&caption=".urlencode($text);
    file_get_contents($url);
}

I also put there some useful variable and the chance to put a caption (don't give that parameter if you don't want one)

凉城已无爱 2025-02-19 03:53:04

尝试一下:

$telegram->sendMediaGroup([
    'chat_id' => $chat,
    'media' => json_encode(
        [['type' => 'photo', 'media' => "https://" . $_SERVER['SERVER_NAME'] . "/newbot/screens/ctry/en1.jpg"]],
        [['type' => 'photo', 'media' => "https://" . $_SERVER['SERVER_NAME'] . "/newbot/screens/ctry/en2.jpg"]],
    ),
    'caption' => $reply,
    'parse_mode' => 'markdown'
]);

Try This:

$telegram->sendMediaGroup([
    'chat_id' => $chat,
    'media' => json_encode(
        [['type' => 'photo', 'media' => "https://" . $_SERVER['SERVER_NAME'] . "/newbot/screens/ctry/en1.jpg"]],
        [['type' => 'photo', 'media' => "https://" . $_SERVER['SERVER_NAME'] . "/newbot/screens/ctry/en2.jpg"]],
    ),
    'caption' => $reply,
    'parse_mode' => 'markdown'
]);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文