Created
August 19, 2020 14:59
-
-
Save revooms/3071697f8af453fdedf9691493107173 to your computer and use it in GitHub Desktop.
Botman Conversation Setup
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 | |
use BotMan\BotMan\Messages\Conversations\Conversation; | |
use BotMan\BotMan\Messages\Incoming\Answer; | |
class AskName extends Conversation | |
{ | |
protected $firstname; | |
public function askFirstname() | |
{ | |
$this->ask('Hello! What is your firstname?', function (Answer $answer) { | |
// Save result | |
$this->firstname = $answer->getText(); | |
$this->say('Nice to meet you ' . $this->firstname); | |
}); | |
} | |
public function run() | |
{ | |
// This will be called immediately | |
$this->askFirstname(); | |
} | |
} |
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
<!doctype html> | |
<html> | |
<head> | |
<title>BotMan Widget</title> | |
<meta charset="UTF-8"> | |
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/botman-web-widget@0/build/assets/css/chat.min.css"> | |
</head> | |
<body> | |
<script id="botmanWidget" src='https://cdn.jsdelivr.net/npm/botman-web-widget@0/build/js/chat.js'></script> | |
</body> | |
</html> |
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 | |
require_once 'vendor/autoload.php'; | |
require_once 'AskName.php'; | |
use BotMan\BotMan\BotMan; | |
use BotMan\BotMan\BotManFactory; | |
use BotMan\BotMan\Drivers\DriverManager; | |
use BotMan\Drivers\Web\WebDriver; | |
use BotMan\BotMan\Cache\SymfonyCache; | |
use Symfony\Component\Cache\Adapter\FilesystemAdapter; | |
$config = []; | |
DriverManager::loadDriver(WebDriver::class); | |
$adapter = new FilesystemAdapter; | |
$botman = BotManFactory::create($config, new SymfonyCache($adapter)); | |
// Give the bot something to listen for. | |
$botman->hears('Hello', function (BotMan $bot) { | |
$bot->startConversation(new AskName); | |
}); | |
$botman->hears('Hi', function ($bot) { | |
$bot->reply('Hello!'); | |
}); | |
$botman->fallback(function ($bot) { | |
$bot->reply('Sorry, I did not understand these commands. Here is a list of commands I understand: ...'); | |
}); | |
// Start listening | |
$botman->listen(); |
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
<script> | |
var botmanWidget = { | |
frameEndpoint: '/chat.html', | |
introMessage: 'Hello, I am a Chatbot', | |
chatServer : 'chat.php', | |
title: 'My Chatbot', | |
mainColor: '#456765', | |
bubbleBackground: '#ff76f4', | |
aboutText: '', | |
bubbleAvatarUrl: '', | |
}; | |
</script> | |
<script src='https://cdn.jsdelivr.net/npm/botman-web-widget@0/build/js/widget.js'></script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment