telegram-bot-sdk icon indicating copy to clipboard operation
telegram-bot-sdk copied to clipboard

replyWithDocument not work

Open yaroslavpopovic opened this issue 6 years ago • 3 comments

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 { /** * @var string Command Name */ protected $name = "plist";

/**
 * @var string Command Description
 */
protected $description = "Scarica il file in pdf delle ultime richieste ricevute";

/**
 * @inheritdoc
 */
public function handle($arguments)
{
    $fileName = uniqid();
    $pdf = app('dompdf');
    $pdf->loadHTML('<h1>Tesdddddddddt</h1>');
    Storage::disk('public')->put($fileName.'.pdf', $pdf->output());

    $this->replyWithDocument([
        'document' => asset('storage/'.$fileName.'.pdf')
    ]);
}

}`

yaroslavpopovic avatar Feb 28 '19 07:02 yaroslavpopovic

👋 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.

welcome[bot] avatar Feb 28 '19 07:02 welcome[bot]

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.

marechenok avatar Aug 31 '20 13:08 marechenok

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!

egin10 avatar Jan 24 '21 11:01 egin10