irazasyed / telegram-bot-sdk

🤖 Telegram Bot API PHP SDK. Lets you build Telegram Bots easily! Supports Laravel out of the box.
https://telegram-bot-sdk.com
BSD 3-Clause "New" or "Revised" License
3.05k stars 673 forks source link

[Todo] Add Multi-Bot & Multi/Shared Commands Support! #22

Closed irazasyed closed 8 years ago

irazasyed commented 9 years ago

Would a multi-bot support be good? Looking for feedback.

I have plans to add but not on my priority list unless there's a requirement.

jonnywilliamson commented 9 years ago

Just so I'm clear in my mind,

Basically just allow you to control more than 1 bot from the same code base? ie Multiple api keys in config files etc?

Personally I don't have a need for this now, but I could see how that would be helpful to people.

irazasyed commented 9 years ago

Exactly!

Multiple API Keys, Same Code Base and Multiple/Shared Commands using the commands handler system.

This will come handy like in case where lets say there are 2 different bots in a group chat (Your own), Based on whichever bot the user sends a command to, the library will automatically trigger its appropriate command and respond accordingly.

Will also help in maintaining one setup to handle all your bots, Should make things easier instead of handling multiple setups for bot developers. I personally don't have multiple bots for now but i do have plans to create a few, maybe at that time i would feel a need for this.

Ham3D commented 9 years ago

+1

irazasyed commented 8 years ago

Just pushed multi-bot support: https://github.com/irazasyed/telegram-bot-sdk/commit/e74f71492fc92d584be473e256a2b5d91a69b8ed

Currently it works only with Laravel but obviously will add support for standalone users too.

Your routes could look like this (Basic example):

// http://domain.com/common/set-webhook
// "common" or {bot} is simply the key name you set in config -> bots array.
Route::get('/{bot}/set-webhook', function ($bot) {
    $response = Telegram::bot($bot)->setWebhook(['url' => 'https://domain.com/'.$bot.'/webhook']);
});

// https://domain.com/common/webhook
Route::post('/{bot}/webhook',  function ($bot) {
    $update = Telegram::bot($bot)->commandsHandler(true);

    return 'Thank You Telegram!';
});

If you guys are interested, feel free to test it using the master branch / 3.0-dev and leave your feedback. Also make sure to refer the config file as it has all the explanation and examples of how the new system works.

irazasyed commented 8 years ago

P.S I'm yet to update the commands handler to handle commands in a telegram group for multiple bots. Feel free to send a PR if you work on it though.

ghost commented 7 years ago

Sorry to open this up, But does this works for Standalone now?

irazasyed commented 7 years ago

@MostafaQanbaryan No problem. No, Standalone is not yet supported. It'll be supported before it's tagged.