Skip to content

Instantly share code, notes, and snippets.

@molbal
Created July 25, 2019 14:32
Show Gist options
  • Save molbal/3078c5cb881d420e51b72f2f60611b42 to your computer and use it in GitHub Desktop.
Save molbal/3078c5cb881d420e51b72f2f60611b42 to your computer and use it in GitHub Desktop.
Trait example
<?php
namespace App\Conversations;
use BotMan\BotMan\Messages\Conversations\Conversation;
use BotMan\BotMan\Messages\Incoming\Answer;
use BotMan\BotMan\Messages\Outgoing\Question;
use SundayIT\ChatbotAdmin\Botman\Middleware\PropertyLoggingTrait;
class TestConversation extends Conversation
{
use PropertyLoggingTrait;
/** @var string */
private $name;
/**
* @return mixed
*/
public function run()
{
$this->greet();
}
private function greet(): TestConversation
{
$question = Question::create("What is your name?")
->callbackId('ask_name');
return $this->ask($question, function (Answer $response) {
$this->name = $response->getText();
$this->logProperty("name", $this->name, $this->bot->getUser()->getId());
$this->say('Nice to meet you, ' . $response->getText());
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment