DEF STUDIO srl

Bots API calls

botInfo()

retrieves Bot data from Telegram APIs

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

/*
id: xxxxx
is_bot: true
first_name: telegraph-test
username: my_test_bot
can_join_groups: true
can_read_all_group_messages: false
supports_inline_queries: false
*/

botUpdates()

retrieves the bot updates from Telegram APIs

Telegraph::bot($telegraphBot)->botUpdates()->send();
Warning

Manual updates polling is not available if a webhook is set up for the bot. Webhook should be remove first using its unregisterWebhook method

Long Polling

In production environment, a timeout (in seconds) should be declared, in order to allow long polling:

Telegraph::bot($telegraphBot)->botUpdates(timeout: 60)->send();

registerBotCommands()

register commands in Telegram Bot in order to display them to the user when the "/" key is pressed

Telegraph::registerBotCommands([
    'command1' => 'command 1 description',
    'command2' => 'command 2 description'
])->send();

unregisterBotCommands()

resets Telegram Bot registered commands

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

getRegisteredCommands()

retrieve bot's registered commands.

$response = Telegraph::getRegisteredCommands()->send();
$response->json('result');

registerWebhook()

register a webhook for the active bot

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

you can use the method parameters to customize the webhook settings:

  • dropPendingUpdates: drops pending updates from telegram
  • maxConnections: maximum allowed simultaneous connections to the webhook (defaults to 40)
  • secretToken: secret token to be sent in a X-Telegram-Bot-Api-Secret-Token header to verify the authenticity of the webhook

unregisterWebhook()

unregister a webhook for the active bot

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

getWebhookDebugInfo()

retrieves webhook debug data for the active bot

$response = Telegraph::getWebhookDebugInfo()->send();

getFileInfo

Retrieve file info from ID

Telegraph::getFileInfo($fileId)->send();

store()

Downloads a media file and stores it in the given path

/** @var DefStudio\Telegraph\DTO\Photo $photo */

Telegraph::store($photo, Storage::path('bot/images'), 'The Photo.jpg');
Warning

There is an hard limit of 20BM for downloaded files sizes. This is a Telegram limitation for bots, sadly, there is no workaround available. refer the docs for more info.

setBaseUrl()

allows to override Telegram API url on a per-message basis:

Telegraph::setBaseUrl('https://my-secret-server.dev')->message('secret message')->send();
Suggest a change
Last updated 27 January 2025