DEF STUDIO srl

Attachments

Telegraph supports different types of attachments both from local files, remote urls and existing files on Telegram servers (using their file_id)

Optional parameters

Attachments methods only supports required parameters, optional parameters can be sent through Telegraph ->withData() method:

Telegraph::message('hi')->withData('caption', 'test')->send();
Telegraph::withData('caption', 'test')->message('hi')->send();

Custom validation

Telegraph enforces Telegram default bot API limits for attachments. When using a local Bot API Server, wider limits are allowed (see docs for reference) and validation checks limits can be customized in telegraph.php config file (attachments section)

Attachment types

Photos

Photos can be sent through Telegraph ->photo() method:

Telegraph::photo(Storage::path('photo.jpg'))->send();
Telegraph::photo('https://my-repository/photo.jpg')->send();
Telegraph::photo($telegramFileId)->send();
Warning

Sent Photos can be edited with the editMedia call

Animations

Animations can be sent through Telegraph ->animation() method:

Telegraph::animation(Storage::path('gif.gif'))->send();
Telegraph::animation('https://my-repository/gif.gif')->send();
Telegraph::animation($telegramFileId)->send();
Warning

Sent Animations can be edited with the editMedia call

Video

Videos can be sent through Telegraph ->video() method:

Telegraph::video(Storage::path('video.mp4'))->send();
Telegraph::video('https://my-repository/video.mp4')->send();
Telegraph::video($telegramFileId)->send();
Warning

Sent Videos can be edited with the editMedia call

Audio

Audio (.MP3 or .M4A format) can be sent through Telegraph ->audio() method:

Telegraph::audio(Storage::path('audio.mp3'))->send();
Telegraph::audio('https://my-repository/audio.mp3')->send();
Telegraph::audio($telegramFileId)->send();
Warning

Sent Audio messages can be edited with the editMedia call

Vocal Messages

Vocals can be sent through Telegraph ->voice() method:

Telegraph::voice(Storage::path('voice.ogg'))->send();
Telegraph::voice('https://my-repository/voice.ogg')->send();
Telegraph::voice($telegramFileId)->send();

Documents

Documents can be sent through Telegraph ->document() method:

Telegraph::document(Storage::path('my_document.pdf'))->send();
Telegraph::document('https://my-repository/my_document.pdf')->send();
Telegraph::document($telegramFileId)->send();
Warning

Sent Documents can be edited with the editMedia call

Location

A location attachment can be sent through Telegraph ->location() method:

Telegraph::location(12.345, -54.321)->send();

Contact

A contact attachment can be sent through Telegraph ->contact() method:

Telegraph::contact('3331122111', 'firstName')->send();

Dice

An animated emoji attachment that will display a random value can be sent through Telegraph ->dice() method:

Telegraph::dice()->send();

Different items can be used as "dice"

Telegraph::dice(\DefStudio\Telegraph\Enums\Emojis::SLOT_MACHINE)->send();

Options

When sending files, some options are available:

Html caption

Telegraph::document(Storage::path('my_document.pdf'))
    ->html('<b>read this</b>')
    ->send();
Warning

Sent attachment captions can be edited with the editCaption call

Markdown caption

Telegraph::document(Storage::path('my_document.pdf'))
    ->markdown('read *this*')
    ->send();
Warning

Sent attachment captions can be edited with the editCaption call

MarkdownV2 caption

Telegraph::document(Storage::path('my_document.pdf'))
    ->markdownV2('read *this*')
    ->send();
Warning

Sent attachment captions can be edited with the editCaption call

Without notification

Telegraph::document(Storage::path('my_document.pdf'))
    ->silent()
    ->send();

Prevent sharing

Telegraph::document(Storage::path('my_document.pdf'))
    ->protected()
    ->send();

Reply to a message

Telegraph::document(Storage::path('my_document.pdf'))
    ->reply($messageId)
    ->send();

Attach a keyboard

Telegraph::document(Storage::path('brochure.pdf'))
      ->keyboard(fn (Keyboard $keyboard) => $keyboard->button('visit')->url('https://defstudio.it'))
    ->send();

Add a thumbnail

Telegraph::document(Storage::path('brochure.pdf'))
    ->thumbnail(Storage::path('brochure_thumbnail.jpg'))
    ->send();
Edit this page
Last updated 26 April 2024