botman / botman

A framework agnostic PHP library to build chat bots
https://botman.io
MIT License
6.06k stars 812 forks source link

Specify outbound driver #44

Closed andrewklau closed 7 years ago

andrewklau commented 7 years ago

With SlackBot it was possible to use the reply outside of the standard hear etc to send a message. Is there a way to specify the driver to keep using this functionality?

ie. bot initiated message

mpociot commented 7 years ago

Well you could use the reply method outside of the listener callbacks, but you need to specify the channel, recipient, etc. nonetheless. How did you do this using the old version of this package?

There is no such thing as being initialized because BotMan only responds to incoming webhooks.

andrewklau commented 7 years ago
$slackbot = new \SlackBot();
        $slackbot::reply('hello', [
          'channel' => 'dev',
          'username' => 'Bot',
          'icon_emoji' => ':robot_face:',
      ]);

Doing this with BotMan no longer seems to work anymore, do we need to pass the driver in?

mpociot commented 7 years ago

Ah right. That will no longer work because BotMan doesn't know which driver to use.

Sol it'd be best to pass the driver classname to the rely method in this case.

But isn't that basically the "fallback" method you're looking for?

andrewklau commented 7 years ago

Do you have an example of how to to pass the driver classname into the reply method?

mpociot commented 7 years ago

It's currently not possible to do this.

Please take a look at the fallback method, which gets triggered if no keyword matches your bot:

https://github.com/mpociot/botman#fallback-replies

andrewklau commented 7 years ago

Thanks, I guess we'll stick to SlackBot for a while.

It's more our app uses both the bot and sending bot initiated messages for other notifications. I'll look into submitting a PR if I get some time.

Thanks!