You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Not an issue but a addition I made. This is a fallback command that will be executed when no command is found. Sort of like a catch-all command, but loaded commands will be executed first. I don't know much how this pull request thing work so here it is, as a patch file for Bot.php :
14d13
< private $fallBackCommand = null;
38,46d36
< public function loadFallBackCommand($command) {
< if ($command instanceof Command\BaseCommand) {
< $this->fallBackCommand = $command;
< }
< else {
< throw new \Exception('Command must implement PhpSlackBot\Command\BaseCommand');
< }
< }
<
205,207d194
< }
< if (null !== $this->fallBackCommand) {
< return $this->fallBackCommand;
Usage :
require'vendor/autoload.php';
usePhpSlackBot\Bot;
// This special command executes when no command is foundclass FallBackCommand extends \PhpSlackBot\Command\BaseCommand {
protectedfunctionconfigure() {
// We don't have to configure a command name in this case
}
protectedfunctionexecute($data, $context) {
if ($data['type'] == 'message') {
$channel = $this->getChannelNameFromChannelId($data['channel']);
$username = $this->getUserNameFromUserId($data['user']);
echo$username.' from '.($channel ? $channel : 'DIRECT MESSAGE').' : '.$data['text'].PHP_EOL;
}
}
}
$bot = newBot();
$bot->setToken('TOKEN'); // Get your token here https://my.slack.com/services/new/bot$bot->loadFallBackAllCommand(newFallBackCommand());
$bot->run();
Hopefully there will be no bug in this code...
The text was updated successfully, but these errors were encountered:
Hello,
Not an issue but a addition I made. This is a fallback command that will be executed when no command is found. Sort of like a catch-all command, but loaded commands will be executed first. I don't know much how this pull request thing work so here it is, as a patch file for Bot.php :
Usage :
Hopefully there will be no bug in this code...
The text was updated successfully, but these errors were encountered: