DEF STUDIO srl

Message API calls

message()

compose a new telegram message (will use the default parse mode set up in config/telegraph.php)

Telegraph::message('hello')->send();

markdown()

compose a new telegram message (parsed as markdown)

Telegraph::markdown('*hello* world')->send();

markdownV2()

compose a new telegram message (parsed as markdownV2)

Telegraph::markdownV2('*hello* world')->send();

html()

compose a new telegram message (parsed as html)

Telegraph::html('<b>hello</b> world')->send();

when()

allows to execute a closure when the given condition is verified

Telegraph::when(true, fn(Telegraph $telegraph) => $telegraph->message('conditional message')->send());

edit()

edits a message

Telegraph::edit($messageId)->markdown('new message')->send();

document()

sends a document

Telegraph::document($documentPath)->send();

location()

sends a location attachment

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

contact()

sens a contact attachment

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

photo()

sends a photo

Telegraph::photo($pathToPhotoFile)->send();

voice()

sends a vocal message

Telegraph::voice($pathToVoiceFile)->send();

mediaGroup()

sends a group of photos, videos, documents or audios as an album

Telegraph::mediaGroup([
        [
            'type' => 'photo',
            'media' => 'https://my-repository/photo1.jpg',
        ],
        [
            'type' => 'photo',
            'media' => 'https://my-repository/photo2.jpg',
        ]              
])->send();

editCaption()

edits an attachment caption

Telegraph::editCaption($messageId)->markdownV2('new caption')->send();

editMedia()

edits a media messages with a new media content

Telegraph::editMedia($messageId)->photo($path)->send();
Telegraph::editMedia($messageId)->document($path)->send();
Telegraph::editMedia($messageId)->animation($path)->send();
Telegraph::editMedia($messageId)->video($path)->send();
Telegraph::editMedia($messageId)->audio($path)->send();

poll()

creates a native poll. For more info, see telegram bot documentation

Telegraph::poll("What's your favourite programming language?")
    ->option('php')
    ->option('typescript')
    ->option('rust')
    ->allowMultipeAnswers()
    ->validUntil(now()->addMinutes(5))
    ->send();

quiz()

creates a quiz. For more info, see telegram bot documentation

Telegraph::quiz("What's your favourite programming language?")
    ->option('php', correct: true)
    ->option('typescript')
    ->option('rust')
    ->explanation('We all love php, right?')
    ->validUntil(now()->addMinutes(5))
    ->send();

thread()

set custom Telegraph Thread id

Telegraph::message('test')->inThread(thread_id);
Suggest a change
Last updated 27 January 2025