SlideShare a Scribd company logo
1 of 39
Creating chatbots
with BotMan
Adam Matysiak
CTO / Team Leader
adam@highsolutions.pl
What is chatbot?
Definition:
“A conversational
user interface
used for interaction
with application”
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
- … ?
Examples
https://highsolutions.pl/blog/wpis/7-zastosowan-chatbota-
o-ktorych-musisz-wiedziec-prowadzac-biznes
The time is now?
“Chatbot Market Size Is About To
Reach $1.25 Billion By 2025”
GrandViewResearch, August 2017
Efficiency
Data source: https://neilpatel.com/blog/open-rates-facebook-messenger
BotMan
composer create-project --prefer-dist botman/studio your-awesome-bot
Requirements: PHP >= 7.0
● https://botman.io/ - Documentation / Demo
● https://buildachatbot.io/ - Video course
● https://playground.botman.io/ - On-line IDE
● https://christoph-rumpel.com/build-chatbots-with-php - E-book
Available services
- Amazon Alexa
- Cisco Spark
- Facebook Messenger
- HipChat
- Kik
- Microsoft Bot Framework
- Nexmo
- Slack
- Telegram
- Twilio
- WeChat
How chatbots work
1. Listening 🙉
2. Processing 🌀
3. Responding 📢
How chatbots work
Hear and respond...
File botman.php in routes directory
$botman->hears('Hi', function ($bot) {
$bot->reply('Hello World!');
});
// Process incoming message
$botman->listen();
Sending to controller...
$botman->hears('Hi', 'SomeNamespaceCommandController@respond');
class CommandController {
public function respond($bot) {
$bot->reply('Hello World!');
}
}
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!’);
});
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
}
});
Responding
$botman->hears('Hi!', function (BotMan $bot) {
$bot->reply("Foo");
$bot->reply("Bar");
$bot->typesAndWaits(2); // It shows typing icon for 2 seconds...
$bot->reply("Baz!");
});
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);
});
Conversations
$botman->hears('I want to create an account', function($bot) {
$bot->startConversation(new AccountRegisterConversation);
});
Conversations
class AccountRegisterConversation extends Conversation
{
protected $name;
protected $email;
public function run()
{
$this->askName();
}
public function askName()
{
$this->ask('What is your name?', function(Answer $answer) {
$this->name = $answer->getText();
$this->say('Nice to meet you, '. $this->name);
$this->askEmail();
});
}
public function askEmail()
{
$this->ask('Please provide your e-mail address:', function(Answer $answer) {
$this->email = $answer->getText();
// ... sending e-mail
$this->say('Thank you. We send confirmation e-mail to: '. $this->email);
});
}
}
Questions
public function askWhoWillWinNextMatch()
{
$this->ask('Who will win next match?', function (Answer $response) {
$this->say('Great, your answer is - ' . $response->getText());
});
}
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'
}
});
}
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!');
}
]
]);
}
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();
Cache
$storage = $botman->userStorage();
$storage = $botman->channelStorage();
$storage = $botman->driverStorage();
$bot->userStorage()->save([
'name' => $name
]);
$bot->userStorage()->all();
$userInformation = $bot->userStorage()->find($id);
$name = $userInformation->get('name');
$bot->userStorage()->delete();
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"
}
}
Middleware
Testing
/** @test */
public function test_simple_reply()
{
$this->bot
->receives('Hi')
->assertReply('Hello World!');
}
/** @test */
public function test_image_reply()
{
$this->bot
->receivesImage(['https://highsolutions.pl/images/logo-image.png'])
->assertReply('This is our logo!');
}
Testing
/** @test */
public function test_conversation()
{
$this->bot
->receives('Hi')
->assertReplies([
'Foo',
'Bar',
])->receives('And?')
->assertReply('Baz');
}
Web driver
Web widget
NLP model
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'))
);
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')
),
])
);
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')
)
)
);
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/'))));
Messenger Demo Viewer
Questions?
adam@highsolutions.pl
@AdamMatysiak
chatbot.highsolutions.pl

More Related Content

Similar to Laravel Poznań Meetup #2 - Creating chatbots with BotMan

Implementation of GUI Framework part3
Implementation of GUI Framework part3Implementation of GUI Framework part3
Implementation of GUI Framework part3masahiroookubo
 
JavaOne Brasil 2016: JavaEE e HTML5: da web/desktop ao mobile
JavaOne Brasil 2016: JavaEE e HTML5: da web/desktop ao mobileJavaOne Brasil 2016: JavaEE e HTML5: da web/desktop ao mobile
JavaOne Brasil 2016: JavaEE e HTML5: da web/desktop ao mobileLoiane Groner
 
SULTHAN's - PHP MySQL programs
SULTHAN's - PHP MySQL programsSULTHAN's - PHP MySQL programs
SULTHAN's - PHP MySQL programsSULTHAN BASHA
 
Client side development with knockout.js
Client side development with knockout.jsClient side development with knockout.js
Client side development with knockout.jsValdis Iljuconoks
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For BeginnersJonathan Wage
 
How to Leverage APIs for SEO #TTTLive2019
How to Leverage APIs for SEO #TTTLive2019How to Leverage APIs for SEO #TTTLive2019
How to Leverage APIs for SEO #TTTLive2019Paul Shapiro
 
Bag Of Tricks From Iusethis
Bag Of Tricks From IusethisBag Of Tricks From Iusethis
Bag Of Tricks From IusethisMarcus Ramberg
 
Can WordPress really do that? A case study of vierderduer.no
Can WordPress really do that? A case study of vierderduer.noCan WordPress really do that? A case study of vierderduer.no
Can WordPress really do that? A case study of vierderduer.noMorten Rand-Hendriksen
 
HTML5 New and Improved
HTML5   New and ImprovedHTML5   New and Improved
HTML5 New and ImprovedTimothy Fisher
 
[WLDN] Supercharging word press development in 2018
[WLDN] Supercharging word press development in 2018[WLDN] Supercharging word press development in 2018
[WLDN] Supercharging word press development in 2018Adam Tomat
 
[PHP 也有 Day] 垃圾留言守城記 - 用 Laravel 阻擋 SPAM 留言的奮鬥史
[PHP 也有 Day] 垃圾留言守城記 - 用 Laravel 阻擋 SPAM 留言的奮鬥史[PHP 也有 Day] 垃圾留言守城記 - 用 Laravel 阻擋 SPAM 留言的奮鬥史
[PHP 也有 Day] 垃圾留言守城記 - 用 Laravel 阻擋 SPAM 留言的奮鬥史Shengyou Fan
 
Tidy Up Your Code
Tidy Up Your CodeTidy Up Your Code
Tidy Up Your CodeAbbas Ali
 
Message Passing vs. Data Synchronization
Message Passing vs. Data SynchronizationMessage Passing vs. Data Synchronization
Message Passing vs. Data SynchronizationAnant Narayanan
 
Create a res tful services api in php.
Create a res tful services api in php.Create a res tful services api in php.
Create a res tful services api in php.Adeoye Akintola
 
inventory mangement project.pdf
inventory mangement project.pdfinventory mangement project.pdf
inventory mangement project.pdfMeenakshiThakur86
 
Rails GUI Development with Ext JS
Rails GUI Development with Ext JSRails GUI Development with Ext JS
Rails GUI Development with Ext JSMartin Rehfeld
 
Dart : one language to rule them all - MixIT 2013
Dart : one language to rule them all - MixIT 2013Dart : one language to rule them all - MixIT 2013
Dart : one language to rule them all - MixIT 2013Sébastien Deleuze
 
Spca2014 hillier 3rd party_javascript_libraries
Spca2014 hillier 3rd party_javascript_librariesSpca2014 hillier 3rd party_javascript_libraries
Spca2014 hillier 3rd party_javascript_librariesNCCOMMS
 
How to implement email functionalities with Mailjet api
How to implement email functionalities with Mailjet apiHow to implement email functionalities with Mailjet api
How to implement email functionalities with Mailjet apiE Boisgontier
 
"Full Stack frameworks or a story about how to reconcile Front (good) and Bac...
"Full Stack frameworks or a story about how to reconcile Front (good) and Bac..."Full Stack frameworks or a story about how to reconcile Front (good) and Bac...
"Full Stack frameworks or a story about how to reconcile Front (good) and Bac...Fwdays
 

Similar to Laravel Poznań Meetup #2 - Creating chatbots with BotMan (20)

Implementation of GUI Framework part3
Implementation of GUI Framework part3Implementation of GUI Framework part3
Implementation of GUI Framework part3
 
JavaOne Brasil 2016: JavaEE e HTML5: da web/desktop ao mobile
JavaOne Brasil 2016: JavaEE e HTML5: da web/desktop ao mobileJavaOne Brasil 2016: JavaEE e HTML5: da web/desktop ao mobile
JavaOne Brasil 2016: JavaEE e HTML5: da web/desktop ao mobile
 
SULTHAN's - PHP MySQL programs
SULTHAN's - PHP MySQL programsSULTHAN's - PHP MySQL programs
SULTHAN's - PHP MySQL programs
 
Client side development with knockout.js
Client side development with knockout.jsClient side development with knockout.js
Client side development with knockout.js
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For Beginners
 
How to Leverage APIs for SEO #TTTLive2019
How to Leverage APIs for SEO #TTTLive2019How to Leverage APIs for SEO #TTTLive2019
How to Leverage APIs for SEO #TTTLive2019
 
Bag Of Tricks From Iusethis
Bag Of Tricks From IusethisBag Of Tricks From Iusethis
Bag Of Tricks From Iusethis
 
Can WordPress really do that? A case study of vierderduer.no
Can WordPress really do that? A case study of vierderduer.noCan WordPress really do that? A case study of vierderduer.no
Can WordPress really do that? A case study of vierderduer.no
 
HTML5 New and Improved
HTML5   New and ImprovedHTML5   New and Improved
HTML5 New and Improved
 
[WLDN] Supercharging word press development in 2018
[WLDN] Supercharging word press development in 2018[WLDN] Supercharging word press development in 2018
[WLDN] Supercharging word press development in 2018
 
[PHP 也有 Day] 垃圾留言守城記 - 用 Laravel 阻擋 SPAM 留言的奮鬥史
[PHP 也有 Day] 垃圾留言守城記 - 用 Laravel 阻擋 SPAM 留言的奮鬥史[PHP 也有 Day] 垃圾留言守城記 - 用 Laravel 阻擋 SPAM 留言的奮鬥史
[PHP 也有 Day] 垃圾留言守城記 - 用 Laravel 阻擋 SPAM 留言的奮鬥史
 
Tidy Up Your Code
Tidy Up Your CodeTidy Up Your Code
Tidy Up Your Code
 
Message Passing vs. Data Synchronization
Message Passing vs. Data SynchronizationMessage Passing vs. Data Synchronization
Message Passing vs. Data Synchronization
 
Create a res tful services api in php.
Create a res tful services api in php.Create a res tful services api in php.
Create a res tful services api in php.
 
inventory mangement project.pdf
inventory mangement project.pdfinventory mangement project.pdf
inventory mangement project.pdf
 
Rails GUI Development with Ext JS
Rails GUI Development with Ext JSRails GUI Development with Ext JS
Rails GUI Development with Ext JS
 
Dart : one language to rule them all - MixIT 2013
Dart : one language to rule them all - MixIT 2013Dart : one language to rule them all - MixIT 2013
Dart : one language to rule them all - MixIT 2013
 
Spca2014 hillier 3rd party_javascript_libraries
Spca2014 hillier 3rd party_javascript_librariesSpca2014 hillier 3rd party_javascript_libraries
Spca2014 hillier 3rd party_javascript_libraries
 
How to implement email functionalities with Mailjet api
How to implement email functionalities with Mailjet apiHow to implement email functionalities with Mailjet api
How to implement email functionalities with Mailjet api
 
"Full Stack frameworks or a story about how to reconcile Front (good) and Bac...
"Full Stack frameworks or a story about how to reconcile Front (good) and Bac..."Full Stack frameworks or a story about how to reconcile Front (good) and Bac...
"Full Stack frameworks or a story about how to reconcile Front (good) and Bac...
 

More from HighSolutions Sp. z o.o.

Laravel Poland Meetup #22 - "Kilka slajdów o castowaniu atrybutów w Eloquent"
Laravel Poland Meetup #22 - "Kilka slajdów o castowaniu atrybutów w Eloquent"Laravel Poland Meetup #22 - "Kilka slajdów o castowaniu atrybutów w Eloquent"
Laravel Poland Meetup #22 - "Kilka slajdów o castowaniu atrybutów w Eloquent"HighSolutions Sp. z o.o.
 
Laravel Poznań Meetup #16 - "Action-based Laravel"
Laravel Poznań Meetup #16 - "Action-based Laravel" Laravel Poznań Meetup #16 - "Action-based Laravel"
Laravel Poznań Meetup #16 - "Action-based Laravel" HighSolutions Sp. z o.o.
 
Laravel Poznań Meetup #12 - "Speed up web API with Laravel and Swoole using ...
 Laravel Poznań Meetup #12 - "Speed up web API with Laravel and Swoole using ... Laravel Poznań Meetup #12 - "Speed up web API with Laravel and Swoole using ...
Laravel Poznań Meetup #12 - "Speed up web API with Laravel and Swoole using ...HighSolutions Sp. z o.o.
 
Laravel Poznań Meetup #12 - "Laravel 6.0 - co nowego?"
Laravel Poznań Meetup #12 - "Laravel 6.0 - co nowego?"Laravel Poznań Meetup #12 - "Laravel 6.0 - co nowego?"
Laravel Poznań Meetup #12 - "Laravel 6.0 - co nowego?"HighSolutions Sp. z o.o.
 
Dni Kariery - "Turkusowe organizacje. Nowoczesny styl zarządzania"
Dni Kariery - "Turkusowe organizacje. Nowoczesny styl zarządzania"Dni Kariery - "Turkusowe organizacje. Nowoczesny styl zarządzania"
Dni Kariery - "Turkusowe organizacje. Nowoczesny styl zarządzania"HighSolutions Sp. z o.o.
 
Laravel Poznań Meetup #8 - "Laravel czy lumen, oto jest pytanie"
Laravel Poznań Meetup #8 - "Laravel czy lumen, oto jest pytanie"Laravel Poznań Meetup #8 - "Laravel czy lumen, oto jest pytanie"
Laravel Poznań Meetup #8 - "Laravel czy lumen, oto jest pytanie"HighSolutions Sp. z o.o.
 
Laravel Poznań Meetup #8 - "Laravel Telescope - niezastąpione narzędzie do de...
Laravel Poznań Meetup #8 - "Laravel Telescope - niezastąpione narzędzie do de...Laravel Poznań Meetup #8 - "Laravel Telescope - niezastąpione narzędzie do de...
Laravel Poznań Meetup #8 - "Laravel Telescope - niezastąpione narzędzie do de...HighSolutions Sp. z o.o.
 
Laravel Poznań Meetup #7 - "Praktyczne użycie Repository Pattern w Laravel cz...
Laravel Poznań Meetup #7 - "Praktyczne użycie Repository Pattern w Laravel cz...Laravel Poznań Meetup #7 - "Praktyczne użycie Repository Pattern w Laravel cz...
Laravel Poznań Meetup #7 - "Praktyczne użycie Repository Pattern w Laravel cz...HighSolutions Sp. z o.o.
 
Laravel Poznań Meetup #7 - "PWA - Progressive Web App"
Laravel Poznań Meetup #7 - "PWA - Progressive Web App"Laravel Poznań Meetup #7 - "PWA - Progressive Web App"
Laravel Poznań Meetup #7 - "PWA - Progressive Web App"HighSolutions Sp. z o.o.
 
Laravel Poznań Meetup #7 - "Laravel nova - czy to się w ogóle opłaca"
Laravel Poznań Meetup #7 - "Laravel nova - czy to się w ogóle opłaca"Laravel Poznań Meetup #7 - "Laravel nova - czy to się w ogóle opłaca"
Laravel Poznań Meetup #7 - "Laravel nova - czy to się w ogóle opłaca"HighSolutions Sp. z o.o.
 
Laravel Poznań Meetup #6 - "Nowości w Laravel 5.7"
Laravel Poznań Meetup #6 - "Nowości w Laravel 5.7"Laravel Poznań Meetup #6 - "Nowości w Laravel 5.7"
Laravel Poznań Meetup #6 - "Nowości w Laravel 5.7"HighSolutions Sp. z o.o.
 
Laravel Poznań Meetup #4 - EloquentSequence - Historia pewnej biblioteki Open...
Laravel Poznań Meetup #4 - EloquentSequence - Historia pewnej biblioteki Open...Laravel Poznań Meetup #4 - EloquentSequence - Historia pewnej biblioteki Open...
Laravel Poznań Meetup #4 - EloquentSequence - Historia pewnej biblioteki Open...HighSolutions Sp. z o.o.
 
Laravel Poznań Meetup #3 - Uruchomienie i praca z Laravel w wirtualnym konten...
Laravel Poznań Meetup #3 - Uruchomienie i praca z Laravel w wirtualnym konten...Laravel Poznań Meetup #3 - Uruchomienie i praca z Laravel w wirtualnym konten...
Laravel Poznań Meetup #3 - Uruchomienie i praca z Laravel w wirtualnym konten...HighSolutions Sp. z o.o.
 
How business and IT should cooperate with each other to verify business model...
How business and IT should cooperate with each other to verify business model...How business and IT should cooperate with each other to verify business model...
How business and IT should cooperate with each other to verify business model...HighSolutions Sp. z o.o.
 
Jak Biznes i IT powinny współpracować ze sobą by zweryfikować model biznesowy...
Jak Biznes i IT powinny współpracować ze sobą by zweryfikować model biznesowy...Jak Biznes i IT powinny współpracować ze sobą by zweryfikować model biznesowy...
Jak Biznes i IT powinny współpracować ze sobą by zweryfikować model biznesowy...HighSolutions Sp. z o.o.
 
Laravel Poznań Meetup #2 - Koniec CSS? Jest Tailwind!
Laravel Poznań Meetup #2 - Koniec CSS? Jest Tailwind!Laravel Poznań Meetup #2 - Koniec CSS? Jest Tailwind!
Laravel Poznań Meetup #2 - Koniec CSS? Jest Tailwind!HighSolutions Sp. z o.o.
 
Laravel Poznań Meetup #2 - Wykorzystanie FormRequest w Laravelu
Laravel Poznań Meetup #2 - Wykorzystanie FormRequest w LaraveluLaravel Poznań Meetup #2 - Wykorzystanie FormRequest w Laravelu
Laravel Poznań Meetup #2 - Wykorzystanie FormRequest w LaraveluHighSolutions Sp. z o.o.
 
Laravel Poznań Meetup #2 - Tworzenie chatbotów z BotMan
Laravel Poznań Meetup #2 - Tworzenie chatbotów z BotManLaravel Poznań Meetup #2 - Tworzenie chatbotów z BotMan
Laravel Poznań Meetup #2 - Tworzenie chatbotów z BotManHighSolutions Sp. z o.o.
 
Jak błędów unikać prowadząc własną firmę i jak ją rozwijać
Jak błędów unikać prowadząc własną firmę i jak ją rozwijaćJak błędów unikać prowadząc własną firmę i jak ją rozwijać
Jak błędów unikać prowadząc własną firmę i jak ją rozwijaćHighSolutions Sp. z o.o.
 

More from HighSolutions Sp. z o.o. (19)

Laravel Poland Meetup #22 - "Kilka slajdów o castowaniu atrybutów w Eloquent"
Laravel Poland Meetup #22 - "Kilka slajdów o castowaniu atrybutów w Eloquent"Laravel Poland Meetup #22 - "Kilka slajdów o castowaniu atrybutów w Eloquent"
Laravel Poland Meetup #22 - "Kilka slajdów o castowaniu atrybutów w Eloquent"
 
Laravel Poznań Meetup #16 - "Action-based Laravel"
Laravel Poznań Meetup #16 - "Action-based Laravel" Laravel Poznań Meetup #16 - "Action-based Laravel"
Laravel Poznań Meetup #16 - "Action-based Laravel"
 
Laravel Poznań Meetup #12 - "Speed up web API with Laravel and Swoole using ...
 Laravel Poznań Meetup #12 - "Speed up web API with Laravel and Swoole using ... Laravel Poznań Meetup #12 - "Speed up web API with Laravel and Swoole using ...
Laravel Poznań Meetup #12 - "Speed up web API with Laravel and Swoole using ...
 
Laravel Poznań Meetup #12 - "Laravel 6.0 - co nowego?"
Laravel Poznań Meetup #12 - "Laravel 6.0 - co nowego?"Laravel Poznań Meetup #12 - "Laravel 6.0 - co nowego?"
Laravel Poznań Meetup #12 - "Laravel 6.0 - co nowego?"
 
Dni Kariery - "Turkusowe organizacje. Nowoczesny styl zarządzania"
Dni Kariery - "Turkusowe organizacje. Nowoczesny styl zarządzania"Dni Kariery - "Turkusowe organizacje. Nowoczesny styl zarządzania"
Dni Kariery - "Turkusowe organizacje. Nowoczesny styl zarządzania"
 
Laravel Poznań Meetup #8 - "Laravel czy lumen, oto jest pytanie"
Laravel Poznań Meetup #8 - "Laravel czy lumen, oto jest pytanie"Laravel Poznań Meetup #8 - "Laravel czy lumen, oto jest pytanie"
Laravel Poznań Meetup #8 - "Laravel czy lumen, oto jest pytanie"
 
Laravel Poznań Meetup #8 - "Laravel Telescope - niezastąpione narzędzie do de...
Laravel Poznań Meetup #8 - "Laravel Telescope - niezastąpione narzędzie do de...Laravel Poznań Meetup #8 - "Laravel Telescope - niezastąpione narzędzie do de...
Laravel Poznań Meetup #8 - "Laravel Telescope - niezastąpione narzędzie do de...
 
Laravel Poznań Meetup #7 - "Praktyczne użycie Repository Pattern w Laravel cz...
Laravel Poznań Meetup #7 - "Praktyczne użycie Repository Pattern w Laravel cz...Laravel Poznań Meetup #7 - "Praktyczne użycie Repository Pattern w Laravel cz...
Laravel Poznań Meetup #7 - "Praktyczne użycie Repository Pattern w Laravel cz...
 
Laravel Poznań Meetup #7 - "PWA - Progressive Web App"
Laravel Poznań Meetup #7 - "PWA - Progressive Web App"Laravel Poznań Meetup #7 - "PWA - Progressive Web App"
Laravel Poznań Meetup #7 - "PWA - Progressive Web App"
 
Laravel Poznań Meetup #7 - "Laravel nova - czy to się w ogóle opłaca"
Laravel Poznań Meetup #7 - "Laravel nova - czy to się w ogóle opłaca"Laravel Poznań Meetup #7 - "Laravel nova - czy to się w ogóle opłaca"
Laravel Poznań Meetup #7 - "Laravel nova - czy to się w ogóle opłaca"
 
Laravel Poznań Meetup #6 - "Nowości w Laravel 5.7"
Laravel Poznań Meetup #6 - "Nowości w Laravel 5.7"Laravel Poznań Meetup #6 - "Nowości w Laravel 5.7"
Laravel Poznań Meetup #6 - "Nowości w Laravel 5.7"
 
Laravel Poznań Meetup #4 - EloquentSequence - Historia pewnej biblioteki Open...
Laravel Poznań Meetup #4 - EloquentSequence - Historia pewnej biblioteki Open...Laravel Poznań Meetup #4 - EloquentSequence - Historia pewnej biblioteki Open...
Laravel Poznań Meetup #4 - EloquentSequence - Historia pewnej biblioteki Open...
 
Laravel Poznań Meetup #3 - Uruchomienie i praca z Laravel w wirtualnym konten...
Laravel Poznań Meetup #3 - Uruchomienie i praca z Laravel w wirtualnym konten...Laravel Poznań Meetup #3 - Uruchomienie i praca z Laravel w wirtualnym konten...
Laravel Poznań Meetup #3 - Uruchomienie i praca z Laravel w wirtualnym konten...
 
How business and IT should cooperate with each other to verify business model...
How business and IT should cooperate with each other to verify business model...How business and IT should cooperate with each other to verify business model...
How business and IT should cooperate with each other to verify business model...
 
Jak Biznes i IT powinny współpracować ze sobą by zweryfikować model biznesowy...
Jak Biznes i IT powinny współpracować ze sobą by zweryfikować model biznesowy...Jak Biznes i IT powinny współpracować ze sobą by zweryfikować model biznesowy...
Jak Biznes i IT powinny współpracować ze sobą by zweryfikować model biznesowy...
 
Laravel Poznań Meetup #2 - Koniec CSS? Jest Tailwind!
Laravel Poznań Meetup #2 - Koniec CSS? Jest Tailwind!Laravel Poznań Meetup #2 - Koniec CSS? Jest Tailwind!
Laravel Poznań Meetup #2 - Koniec CSS? Jest Tailwind!
 
Laravel Poznań Meetup #2 - Wykorzystanie FormRequest w Laravelu
Laravel Poznań Meetup #2 - Wykorzystanie FormRequest w LaraveluLaravel Poznań Meetup #2 - Wykorzystanie FormRequest w Laravelu
Laravel Poznań Meetup #2 - Wykorzystanie FormRequest w Laravelu
 
Laravel Poznań Meetup #2 - Tworzenie chatbotów z BotMan
Laravel Poznań Meetup #2 - Tworzenie chatbotów z BotManLaravel Poznań Meetup #2 - Tworzenie chatbotów z BotMan
Laravel Poznań Meetup #2 - Tworzenie chatbotów z BotMan
 
Jak błędów unikać prowadząc własną firmę i jak ją rozwijać
Jak błędów unikać prowadząc własną firmę i jak ją rozwijaćJak błędów unikać prowadząc własną firmę i jak ją rozwijać
Jak błędów unikać prowadząc własną firmę i jak ją rozwijać
 

Recently uploaded

GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noidabntitsolutionsrishis
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 

Recently uploaded (20)

GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in NoidaBuds n Tech IT Solutions: Top-Notch Web Services in Noida
Buds n Tech IT Solutions: Top-Notch Web Services in Noida
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 

Laravel Poznań Meetup #2 - Creating chatbots with BotMan

  • 2. Adam Matysiak CTO / Team Leader adam@highsolutions.pl
  • 3. What is chatbot? Definition: “A conversational user interface used for interaction with application”
  • 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 - … ?
  • 6. The time is now? “Chatbot Market Size Is About To Reach $1.25 Billion By 2025” GrandViewResearch, August 2017
  • 8.
  • 9. BotMan composer create-project --prefer-dist botman/studio your-awesome-bot Requirements: PHP >= 7.0 ● https://botman.io/ - Documentation / Demo ● https://buildachatbot.io/ - Video course ● https://playground.botman.io/ - On-line IDE ● https://christoph-rumpel.com/build-chatbots-with-php - E-book
  • 10. Available services - Amazon Alexa - Cisco Spark - Facebook Messenger - HipChat - Kik - Microsoft Bot Framework - Nexmo - Slack - Telegram - Twilio - WeChat
  • 11. How chatbots work 1. Listening 🙉 2. Processing 🌀 3. Responding 📢
  • 13. Hear and respond... File botman.php in routes directory $botman->hears('Hi', function ($bot) { $bot->reply('Hello World!'); }); // Process incoming message $botman->listen();
  • 14. Sending to controller... $botman->hears('Hi', 'SomeNamespaceCommandController@respond'); class CommandController { public function respond($bot) { $bot->reply('Hello World!'); } }
  • 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 } });
  • 17. Responding $botman->hears('Hi!', function (BotMan $bot) { $bot->reply("Foo"); $bot->reply("Bar"); $bot->typesAndWaits(2); // It shows typing icon for 2 seconds... $bot->reply("Baz!"); });
  • 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); });
  • 19. Conversations $botman->hears('I want to create an account', function($bot) { $bot->startConversation(new AccountRegisterConversation); });
  • 20. Conversations class AccountRegisterConversation extends Conversation { protected $name; protected $email; public function run() { $this->askName(); } public function askName() { $this->ask('What is your name?', function(Answer $answer) { $this->name = $answer->getText(); $this->say('Nice to meet you, '. $this->name); $this->askEmail(); }); } public function askEmail() { $this->ask('Please provide your e-mail address:', function(Answer $answer) { $this->email = $answer->getText(); // ... sending e-mail $this->say('Thank you. We send confirmation e-mail to: '. $this->email); }); } }
  • 21. Questions public function askWhoWillWinNextMatch() { $this->ask('Who will win next match?', function (Answer $response) { $this->say('Great, your answer is - ' . $response->getText()); }); }
  • 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();
  • 25. Cache $storage = $botman->userStorage(); $storage = $botman->channelStorage(); $storage = $botman->driverStorage(); $bot->userStorage()->save([ 'name' => $name ]); $bot->userStorage()->all(); $userInformation = $bot->userStorage()->find($id); $name = $userInformation->get('name'); $bot->userStorage()->delete();
  • 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" } }
  • 28. Testing /** @test */ public function test_simple_reply() { $this->bot ->receives('Hi') ->assertReply('Hello World!'); } /** @test */ public function test_image_reply() { $this->bot ->receivesImage(['https://highsolutions.pl/images/logo-image.png']) ->assertReply('This is our logo!'); }
  • 29. Testing /** @test */ public function test_conversation() { $this->bot ->receives('Hi') ->assertReplies([ 'Foo', 'Bar', ])->receives('And?') ->assertReply('Baz'); }
  • 33.
  • 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/'))));