Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Bot\Conversations;
- use Mpociot\BotMan\Button;
- use Mpociot\BotMan\Conversation;
- use Mpociot\BotMan\Question;
- class SimpleEditConversation extends Conversation
- {
- protected $cont;
- /**
- * Start the conversation
- */
- public function run()
- {
- $this->cont=0;
- $this->askAccion();
- }
- public function askAccion()
- {
- $question = Question::create('cont = '.$this->cont)
- ->fallback('Unable to create a new database')
- ->callbackId('create_database')
- ->addButtons([
- Button::create('minus 1')->value('minus'),
- Button::create( $this->cont)->value($this->cont),
- Button::create('sum 1')->value('sum'),
- ]);
- $this->ask($question, function () {
- $this->simpleCallback();
- });
- }
- public function keyboard()
- {
- $keyboard = [
- 'inline_keyboard' => array(
- array( ['text' => 'minus 1', 'callback_data' => 'minus']),
- array( ['text' => "$this->cont", 'callback_data' => "$this->cont"]),
- array( ['text' => 'sum 1', 'callback_data' => 'sum']),
- ),
- ];
- return json_encode($keyboard);
- }
- private function simpleCallback()
- {
- $value = $this->bot->getConversationAnswer()->getValue();
- switch ($value) {
- case "minus":
- $text='Minus 1, now cont='.$this->cont;
- $this->cont-=1;
- break;
- case "sum":
- $text='Sum 1, now cont='.$this->cont;
- $this->cont+=1;
- break;
- default:
- $text='cont='.$this->cont;
- $this->bot->reply($value);
- }
- $parameters = [
- 'text' => $text,
- 'message_id' => $this->bot->getConversationAnswer()->getMessage()->getPayload()['message_id'],
- 'parse_mode' => 'HTML',
- 'reply_markup' => $this->keyboard()
- ];
- $this->bot->sendRequest('editMessageText', $parameters);
- $this->bot->storeConversation($this,$this->simpleCallback(),
- $text,['reply_markup' => $this->keyboard()]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement