Skip to main content
Version: 3.x

🎬 Initilize SDK

Before you can start building a Telegram Bot, you need to configure Telegram Bot SDK with your Bot Token that was provided by BotFather. Once you do that, you'll get access to all the available Bot API Methods to make requests to the Telegram Bot API.

Here is how you can quickly set up and initialize a single bot operation:

require __DIR__.'/vendor/autoload.php';

use Telegram\Bot\Api;

$telegram = new Api('YOUR BOT TOKEN');

// Example usage
$response = $telegram->getMe();

🦾 Managing Multiple Bots

If you want to manage multiple bots, you can take advantage of the BotsManager like this:

use Telegram\Bot\BotsManager;

$config = [
'bots' => [
'mybot' => [
'token' => '123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11',
],
]
];

$telegram = new BotsManager($config);

// Example usage
$response = $telegram->bot('mybot')->getMe();
tip

FYI, $config can get large when handling multiple configurations. To avoid problems, create a dedicated file like config.php and require it in your code to return the array separately. You can use SDK's Laravel config file as a starting point.

info

The configuration guide provides further information on how to register multiple bots.

You can now get started to write your Telegram Bot.

Refer the configuration guide to know more about the available options with detailed information.