irazasyed / telegram-bot-sdk

🤖 Telegram Bot API PHP SDK. Lets you build Telegram Bots easily! Supports Laravel out of the box.
https://telegram-bot-sdk.com
BSD 3-Clause "New" or "Revised" License
3.03k stars 671 forks source link

replyWithDocument not work #630

Closed yaroslavpopovic closed 1 year ago

yaroslavpopovic commented 5 years ago

Hi, I'm trying to reply by sending a document with the method replyWithDocument but it does not work. With the method replyWithMessage I have no problem

`<?php namespace App\TelegramCommands; use Illuminate\Support\Facades\Storage; use Telegram\Bot\Commands\Command; use Telegram\Bot\Laravel\Facades\Telegram;

class PdfListCommand extends Command { /**

welcome[bot] commented 5 years ago

👋 Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you include steps to reproduce it. We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.

To help make it easier for us to investigate your issue, please follow the contributing guidelines.

marechenok commented 4 years ago

As for version 3.1

A path to local file, a URL, or a file resource should be uploaded using Telegram\Bot\FileUpload\InputFile::create($pathOrUrlOrResource, $filename) for document property.

egin10 commented 3 years ago

I use version 3.4 and this is my code to send a file. Thanks @marechenok.

use Telegram\Bot\FileUpload\InputFile;
...
public function handle()
{        
    $response = $this->getUpdate();
    $chat_id = $response->getChat()->getId();

    $filename = 'students.xlsx';
    $pathOrUrlOrResource = public_path('files/students/' . $filename);
    $inputFile = InputFile::create($pathOrUrlOrResource, $filename);

    $response = $this->telegram->sendDocument([
        'chat_id' => $chat_id,
        'document' => $inputFile
    ]);
}

It works!