Presentation that took place in Poznań, 07.03.2018. Why chatbots are interesting? How to start develop chatbots in PHP, Laravel? What is possible in Messenger?
4. Where we can use it?
- Automatic/interactive deployments
- DevOps
- Sales support (E-commerce)
- Customer service support
- Brand marketing
- Blog/content promotion
- Self-service (e.g. weather forecast, bus timetable etc.)
- Fun
- … ?
15. Parameters and regular expressions
$botman->hears('I like {team}', function ($bot, $team) {
$bot->reply('You like: '. $team);
});
$botman->hears('.*(hi|hey|hello).*', function ($bot) {
$bot->reply('Hello World!');
});
$botman->hears('I want to buy ([0-9]+) tickets', function ($bot, $number) {
$bot->reply('I am ordering ’. $number .’ tickets for you!’);
});
16. Attachments (images, videos, localization etc.)
$bot->receivesImages(function($bot, $images) {
foreach ($images as $image) {
$url = $image->getUrl(); // The direct url
$title = $image->getTitle(); // The title, if available
$payload = $image->getPayload(); // The original payload
}
});
18. Responding with an image
use BotManBotManMessagesAttachmentsImage;
use BotManBotManMessagesOutgoingOutgoingMessage;
$botman->hears('Show me your logo', function (BotMan $bot) {
// Create attachment
$attachment = new Image('https://highsolutions.pl/images/logo-image.png');
// Build message object
$message = OutgoingMessage::create('Our logo')
->withAttachment($attachment);
// Reply message object
$bot->reply($message);
});
22. Questions with predefined options
public function askForNextMatchWinner()
{
$question = Question::create('Who will win next match?')
->fallback(“Can’t say...”)
->callbackId('who_will_win_next_match')
->addButtons([
Button::create('Team A')->value('a'),
Button::create('Team B')->value('b'),
]);
$this->ask($question, function (Answer $answer) {
// Detect if button was clicked:
if ($answer->isInteractiveMessageReply()) {
$selectedValue = $answer->getValue(); // will be either 'a' or 'b'
$selectedText = $answer->getText(); // will be either 'Team A' or 'Team B'
}
});
}
23. Questions with patterns
public function askWhoWillWinNextMatch()
{
$this->ask('Who will win next match? [Real - Barca]', [
[
'pattern' => 'real|madrid|hala',
'callback' => function () {
$this->say('In Cristiano you trust!');
}
],
[
'pattern' => 'barca|barcelona|fcb',
'callback' => function () {
$this->say('In Messi you trust!');
}
]
]);
}
24. User information
/**
* Retrieve User information.
* @param IncomingMessage $matchingMessage
* @return UserInterface
*/
public function getUser(IncomingMessage $matchingMessage)
{
return new User($matchingMessage->getSender());
}
// Access user
$user = $bot->getUser();
26. NLP
Hey, I am going to match Real - Barca on Sunday at 15:00 with Suzy.
{
"intent": "create_meeting",
"entities": {
"name" : "Match Real - Barca",
"invitees" : [‘Suzy’],
"time": "2017-03-11 15:00:00"
}
}
34. Messenger / Button Template
$bot->reply(ButtonTemplate::create('How do you like BotMan so far?')
->addButton(ElementButton::create('Quite good')->type('postback')->payload('quite-good'))
->addButton(ElementButton::create('Love it!')->url('https://botman.io'))
);
35. Messenger / Generic Template
$bot->reply(GenericTemplate::create()
->addElements([
Element::create('BotMan Documentation')
->subtitle('All about BotMan')
->image('http://botman.io/img/botman-body.png')
->addButton(ElementButton::create('visit')
->url('http://botman.io')
)
->addButton(ElementButton::create('tell me more')
->payload('tellmemore')
->type('postback')
),
Element::create('BotMan Laravel Starter')
->subtitle('This is the best way to start...')
->image('http://botman.io/img/botman-body.png')
->addButton(ElementButton::create('visit')
->url('https://github.com/botman/botman')
),
])
);
36. Messenger / List Template
$bot->reply(ListTemplate::create()
->useCompactView()
->addGlobalButton(ElementButton::create('view more')->url('http://buildachatbot.io'))
->addElement(
Element::create('BotMan Documentation')
->subtitle('All about BotMan')
->image('http://botman.io/img/botman-body.png')
->addButton(ElementButton::create('tell me more')
->payload('tellmemore')->type('postback'))
)
->addElement(
Element::create('BotMan Laravel Starter')
->subtitle('This is the best way to start...')
->image('http://botman.io/img/botman-body.png')
->addButton(ElementButton::create('visit')
->url('http://botman.io')
)
)
);
37. Messenger / Media Template
$bot->reply(MediaTemplate::create()
->element(MediaAttachmentElement::create('image')
->addButton(ElementButton::create('Tell me more')
->type('postback')
->payload('Tell me more'))
->addButton(ElementButton::create('Documentation')
->url('https://botman.io/'))));