botman / studio

Ready to use BotMan + Laravel framework
330 stars 91 forks source link

Idea for multiple Telegram Bots on a single installation #81

Open Kianda opened 5 years ago

Kianda commented 5 years ago

I have multiple small Telegram bots that do, mostly, useless crap. IMHO have a BotMan studio running for each of my small bots it's an overkill.

I'll try to explain my idea to support multiple telegram bots with one single BotMan Studio installation. I'm not a Laravel expert and what I would like to know it's if this can be done or maybe there is a better way to do it.

The main issue is the Telegram Token. If we could load dynamically that, then, probably, BotMan Studio would work without any additional trouble.

My idea is this:

Change the Telegram webook from: https://yourapp.domain/botman to https://yourapp.domain/botman/{botusername}

Change the routing to something like this (changing also the $except on class VerifyCsrfToken): Route::match(['get', 'post'], '/botman/{botusername?}', 'BotManController@handle');

Then on BotMan Studio .env map each token like this:

TELEGRAM_TOKEN_MY_BOT_USERNAME1 = <YOUR-TELEGRAM-TOKEN1-HERE>
TELEGRAM_TOKEN_MY_BOT_USERNAME2 = <YOUR-TELEGRAM-TOKEN2-HERE>
...

At this point when we land on the route https://yourapp.domain/botman/{botusername} we set the {botusername} 'somewhere' and then use that to load the Telegram Token dynamically inside the TelegramDriver class.

Does this make any sense or there is a simpler way to achieve the same result?

Thanks!

Lloople commented 4 years ago

I don't think this approach would be useful.

The same way you have a different Laravel app for each website you built, you have a different Botman app for each bot you have published. It's the same as a web or api, you need to have your specific models, database, controllers, etc...

If the logic behind your multiple bots are always the same, maybe what you need is just one bot instead.

Erik-Jonker commented 3 years ago

@Lloople I disagree. Why would you require a Laravel app for each website? What if you build something like a headless CMS that provides data to your multiple websites - or if you simply build multiple "sub" websites on your one Laravel app?

I'm in the same situation where multiple bots are required on the same installation. Why limit the developer?

@Kianda were you able to figure out a possible solution?

Kianda commented 3 years ago

@Erik-Jonker yes, managed to get it working on Telegram (vendor/botman/driver-telegram/src/TelegramDriver.php) but the modifications I've made are not super 'clean'! It was just a "quick fix" to get it working asap on a single install. I made a patch (cweagans/composer-patches) instead of a fork, I should be able to get it if you want!