Advertisement
Guest User

Untitled

a guest
Mar 25th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. <?php
  2. namespace App\Bot\Conversations;
  3.  
  4. use Mpociot\BotMan\Button;
  5. use Mpociot\BotMan\Conversation;
  6. use Mpociot\BotMan\Question;
  7.  
  8. class SimpleEditConversation extends Conversation
  9. {
  10. protected $cont;
  11.  
  12. /**
  13. * Start the conversation
  14. */
  15. public function run()
  16. {
  17. $this->cont=0;
  18. $this->askAccion();
  19. }
  20.  
  21.  
  22. public function askAccion()
  23. {
  24. $question = Question::create('cont = '.$this->cont)
  25. ->fallback('Unable to create a new database')
  26. ->callbackId('create_database')
  27. ->addButtons([
  28. Button::create('minus 1')->value('minus'),
  29. Button::create( $this->cont)->value($this->cont),
  30. Button::create('sum 1')->value('sum'),
  31. ]);
  32. $this->ask($question, function () {
  33. $this->simpleCallback();
  34. });
  35. }
  36.  
  37.  
  38. public function keyboard()
  39. {
  40. $keyboard = [
  41. 'inline_keyboard' => array(
  42. array( ['text' => 'minus 1', 'callback_data' => 'minus']),
  43. array( ['text' => "$this->cont", 'callback_data' => "$this->cont"]),
  44. array( ['text' => 'sum 1', 'callback_data' => 'sum']),
  45. ),
  46. ];
  47.  
  48. return json_encode($keyboard);
  49. }
  50.  
  51. private function simpleCallback()
  52. {
  53. $value = $this->bot->getConversationAnswer()->getValue();
  54. switch ($value) {
  55. case "minus":
  56. $text='Minus 1, now cont='.$this->cont;
  57. $this->cont-=1;
  58. break;
  59. case "sum":
  60. $text='Sum 1, now cont='.$this->cont;
  61. $this->cont+=1;
  62. break;
  63. default:
  64. $text='cont='.$this->cont;
  65. $this->bot->reply($value);
  66. }
  67. $parameters = [
  68. 'text' => $text,
  69. 'message_id' => $this->bot->getConversationAnswer()->getMessage()->getPayload()['message_id'],
  70. 'parse_mode' => 'HTML',
  71. 'reply_markup' => $this->keyboard()
  72. ];
  73. $this->bot->sendRequest('editMessageText', $parameters);
  74. $this->bot->storeConversation($this,$this->simpleCallback(),
  75. $text,['reply_markup' => $this->keyboard()]);
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement