T
T
thisall2020-12-19 15:01:57
Bots
thisall, 2020-12-19 15:01:57

How to send photos and message via Telegram bot on Laravel?

I wrote this

foreach ($photos as $photo) {
            $response = Telegram::sendPhoto([
                'chat_id' => 'CHAT_ID',
                'photo' => "https://domen.ru/{$photo}",
                'caption' => ''
            ]);

            $messageId[] = $response->getMessageId();
        }

And send a message like this
Telegram::sendMessage([
            'chat_id' => $chat_id,
            'text' => $reply,
            'reply_markup' => $reply_markup
        ]);

But it throws an error
local.ERROR: A path to local file, a URL, or a file resource should be uploaded using `Telegram\Bot\FileUpload\InputFile::create($pathOrUrlOrResource, $filename)` for `photo` property. Please view docs for example. {"exception":"[object] (Telegram\\Bot\\Exceptions\\CouldNotUploadInputFile(code: 0): A path to local file, a URL, or a file resource should be uploaded using `Telegram\\Bot\\FileUpload\\InputFile::create($pathOrUrlOrResource, $filename)` for `photo` property. Please view docs for example. at /var/www/u1240338/data/www/chpokepanel.xyz/rest/vendor/irazasyed/telegram-bot-sdk/src/Exceptions/CouldNotUploadInputFile.php:52)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2020-12-19
@thisall

Well, it’s clear because the message says what needs to be done:

$response = Telegram::sendPhoto([
  'chat_id' => 'CHAT_ID',
  'photo' => \Telegram\Bot\FileUpload\InputFile::create("https://domen.ru/{$photo}"),
  'caption' => ''
]);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question