-
-
Save Telegramsrv/3bdf23632707513e3083393523198e63 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Controllers; | |
use App\Http\Controllers\Conversations\DummyConvo; | |
use Mpociot\BotMan\BotMan; | |
class BotManController extends Controller { | |
/** @var BotMan */ | |
protected $botman; | |
public function __invoke() { | |
$this->botman = app('botman'); | |
$this->registerCommands(); | |
$time = microtime(true); | |
$this->botman->listen(); | |
$this->botman->reply('listen() time: '.round(microtime(true) - $time, 4)); | |
} | |
public function registerCommands() { | |
$this->botman->fallback(function (BotMan $bot) { | |
$bot->reply('dummy response fallback'); | |
}); | |
$this->botman->receivesAudio(function (BotMan $bot) { | |
$bot->reply('dummy response audio'); | |
}); | |
$this->botman->receivesFiles(function (BotMan $bot) { | |
$bot->reply('dummy response file'); | |
}); | |
$this->botman->receivesImages(function (BotMan $bot) { | |
$bot->reply('dummy response images'); | |
}); | |
$this->botman->receivesLocation(function (BotMan $bot) { | |
$bot->reply('dummy response location'); | |
}); | |
$this->botman->receivesVideos(function (BotMan $bot) { | |
$bot->reply('dummy response video'); | |
}); | |
$this->botman->hears('/one', function (BotMan $bot) { | |
$bot->startConversation(new DummyConvo()); | |
}); | |
$this->botman->hears('/two', function (BotMan $bot) { | |
$bot->reply('dummy response two'); | |
}); | |
$this->botman->hears('/three', function (BotMan $bot) { | |
$bot->reply('dummy response three'); | |
}); | |
$this->botman->hears('/four', function (BotMan $bot) { | |
$bot->reply('dummy response four'); | |
}); | |
$this->botman->hears('/five', function (BotMan $bot) { | |
$bot->reply('dummy response five'); | |
}); | |
$this->botman->hears('/six', function (BotMan $bot) { | |
$bot->reply('dummy response six'); | |
}); | |
$this->botman->hears('/seven', function (BotMan $bot) { | |
$bot->reply('dummy response seven'); | |
}); | |
$this->botman->hears('/eight', function (BotMan $bot) { | |
$bot->reply('dummy response eight'); | |
}); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Controllers\Conversations; | |
use Mpociot\BotMan\Answer; | |
use Mpociot\BotMan\Button; | |
use Mpociot\BotMan\Conversation; | |
use Mpociot\BotMan\Question; | |
class DummyConvo extends Conversation { | |
public function run() { | |
$this->askName(); | |
} | |
public function askName() { | |
$question = Question::create('What\'s your name?') | |
->addButtons( | |
[Button::create('I don\'t know my name')->value('foo')] | |
); | |
$this->ask($question, function (Answer $answer) { | |
if ($answer->isInteractiveMessageReply()) { | |
$this->say('Hi Nameless!'); | |
} else { | |
$this->say('Hi '.$answer->getText().'!'); | |
} | |
$this->askAge(); | |
}); | |
} | |
public function askAge() { | |
$question = Question::create('How old are you?') | |
->addButtons( | |
[Button::create('I don\'t know')->value('foo')] | |
); | |
$this->ask($question, function (Answer $answer) { | |
if ($answer->isInteractiveMessageReply()) { | |
$this->say('I\'m sorry!'); | |
} else { | |
$this->say('You are older than me!'); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment