Telegram-bot-sdk: several bots configuration

Created on 5 Apr 2017  路  3Comments  路  Source: irazasyed/telegram-bot-sdk

Hi, I have several Bot in my application but there is only one set of configurations in the config file.
I think it should be possible to set multiple bots, like what we do when Using Multiple Database Connections

return [

    /*
    |--------------------------------------------------------------------------
    | Default Bot
    |--------------------------------------------------------------------------
    |
    */

    'default' => 'bot1',

    /*
    |--------------------------------------------------------------------------
    | Bot Connections
    |--------------------------------------------------------------------------
    |
    */

    'connections' => [

        'bot1' => [
            'bot_token' => env('TELEGRAM_BOT_TOKEN', '1:eff'),
            'async_requests' => env('TELEGRAM_ASYNC_REQUESTS', true),
            'http_client_handler' => null,
            'commands' => [
                    Telegram\Bot\Commands\HelpCommand::class,
                ],
        ],

        'bot2' => [
            'bot_token' => env('TELEGRAM_BOT_TOKEN', '2:eff'),
            'async_requests' => env('TELEGRAM_ASYNC_REQUESTS', false),
            'http_client_handler' => null,
            'commands' => [
                    Telegram\Bot\Commands\HelpCommand::class,
                ],
        ],

        'bot3' => [
            'bot_token' => env('TELEGRAM_BOT_TOKEN', '3:eff'),
            'async_requests' => env('TELEGRAM_ASYNC_REQUESTS', true),
            'http_client_handler' => null,
            'commands' => [
                    Telegram\Bot\Commands\HelpCommand::class,
                ],
        ],

    ],

Most helpful comment

You can refer the config file. Obviously, you need to use the v3 (unstable) or dev-develop branch + publish the config file (If on Laravel).

All 3 comments

Hi, Yes! Multi-bot is supported.

You can work on it using Telegram::bot('bot1')->sendMessage() like so. Where bot1 is your keyname of the config.

Your webhook should be dynamic. Something like /bot/{bot}/secret/webhook and then pass the {bot} value to Telegram::bot($bot)->getWebhookUpdate() and so on.

Let me know if you have any questions. All the methods work the same as it works for a single bot. And ofc the commands can be either shared or registered separately for each of them.

how about config file? How should I write it? was my sample correct?

You can refer the config file. Obviously, you need to use the v3 (unstable) or dev-develop branch + publish the config file (If on Laravel).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

behnamazimi picture behnamazimi  路  4Comments

jobs2008 picture jobs2008  路  3Comments

b10585 picture b10585  路  4Comments

maminbajand picture maminbajand  路  4Comments

Enelar picture Enelar  路  3Comments