botman.php
<?php
use App\Http\Controllers\BotManController;
use App\Http\Controllers\MainConversation;
$botman = resolve('botman');
$botman->hears('/start', function ( $bot ) {
$bot->startConversation(new MainConversation());
});
MainConversation.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\User as UserDB;
use BotMan\BotMan\Messages\Outgoing\Actions\Button;
use BotMan\BotMan\Messages\Incoming\Answer as BotManAnswer;
use BotMan\BotMan\Messages\Outgoing\Question as BotManQuestion;
use BotMan\BotMan\Messages\Conversations\Conversation;
use BotMan\BotMan\Messages\Attachments\Image;
use BotMan\BotMan\Messages\Outgoing\OutgoingMessage;
class MainConversation extends Conversation
{
public $user;
public function run()
{
$this->getUserData();
$this->exit();
}
private function getUserData()
{
$this->user = $this->bot->getUser();
$lastname = $this->user->getLastName() ? $this->user->getLastName() : "Отсутсвует";
$message = "Имя: {$this->user->getFirstName()}\n".
"Фамилия: {$lastname}\n".
"UserName: {$this->user->getUsername()}\n".
"Id: {$this->user->getId()}";
return $this->say($message);
}
private function exit()
{
if (!UserDB::where('username', '=', $this->user->getUsername())->exists()) {
$db = new UserDB();
$db->firstname = $this->user->getFirstName();
$db->lastname = $this->user->getLastName();
$db->username = $this->user->getUsername();
$db->user_id = $this->user->getId();
$db->save();
$attachment = new Image("https://i.gifer.com/y4.gif");
$message = OutgoingMessage::create("Спасибо за то что нашли меня!")
->withAttachment($attachment);
$this->bot->reply($message);
}
return true;
}
}