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 Thread
Attachments can be sent to a specific Thread through Telegraph ->inThread()
method:
Telegraph::message('hi')->inThread(THREAD_ID)->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();
WarningSent 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();
WarningSent 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();
WarningSent 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();
WarningSent 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();
WarningSent 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();
Sticker
Stickers can be sent through Telegraph ->sticker()
method:
Telegraph::sticker(Storage::path('my_sticker.tgs'))->send(); Telegraph::sticker('https://my-repository/my_sticker.tgs')->send(); Telegraph::sticker($telegramFileId)->send();
Where $telegramFileId
is file_id from telegram sticker set. File_id can obtain from Telegram Raw Bot (@RawDataBot). Just simply send a sticker to bot and you receive json data in answer. The required value is contained in 'message > sticker > file_id'.
Options
When sending files, some options are available:
Html caption
Telegraph::document(Storage::path('my_document.pdf')) ->html('<b>read this</b>') ->send();
WarningSent attachment captions can be edited with the editCaption call
Markdown caption
Telegraph::document(Storage::path('my_document.pdf')) ->markdown('read *this*') ->send();
WarningSent attachment captions can be edited with the editCaption call
MarkdownV2 caption
Telegraph::document(Storage::path('my_document.pdf')) ->markdownV2('read *this*') ->send();
WarningSent 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();
Media Group
Group of photos, videos, documents or audios as an album can be sent through Telegraph ->mediaGroup()
method:
Telegraph::mediaGroup([ [ 'type' => 'photo', 'media' => 'https://my-repository/photo1.jpg', ], [ 'type' => 'photo', 'media' => 'https://my-repository/photo2.jpg', ] ])->send();