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

What's hot

How Women Rise PDF - Sally Helgesen
How Women Rise PDF - Sally Helgesen  How Women Rise PDF - Sally Helgesen
How Women Rise PDF - Sally Helgesen robofune43950
 
Concevoir, développer et sécuriser des micro-services avec Spring Boot
Concevoir, développer et sécuriser des micro-services avec Spring BootConcevoir, développer et sécuriser des micro-services avec Spring Boot
Concevoir, développer et sécuriser des micro-services avec Spring BootDNG Consulting
 
Spring Meetup Paris - Back to the basics of Spring (Boot)
Spring Meetup Paris - Back to the basics of Spring (Boot)Spring Meetup Paris - Back to the basics of Spring (Boot)
Spring Meetup Paris - Back to the basics of Spring (Boot)Eric SIBER
 
Web Programming - DB Galeri Foto
Web Programming - DB Galeri FotoWeb Programming - DB Galeri Foto
Web Programming - DB Galeri FotoDoni Andriansyah
 
[네전따 27회] 네트워크 자동화 어렵지 않아요
[네전따 27회] 네트워크 자동화 어렵지 않아요[네전따 27회] 네트워크 자동화 어렵지 않아요
[네전따 27회] 네트워크 자동화 어렵지 않아요Jo Hoon
 
Codetainer: a Docker-based browser code 'sandbox'
Codetainer: a Docker-based browser code 'sandbox'Codetainer: a Docker-based browser code 'sandbox'
Codetainer: a Docker-based browser code 'sandbox'Jen Andre
 
Un exemple élémentaire d'application MVC en PHP
Un exemple élémentaire d'application MVC en PHPUn exemple élémentaire d'application MVC en PHP
Un exemple élémentaire d'application MVC en PHPKristen Le Liboux
 
GraphQL vs BFF: A critical perspective
GraphQL vs BFF: A critical perspectiveGraphQL vs BFF: A critical perspective
GraphQL vs BFF: A critical perspectivePronovix
 
Imposto de Renda para o produtor rural - Perguntas e respostas da Receita Fed...
Imposto de Renda para o produtor rural - Perguntas e respostas da Receita Fed...Imposto de Renda para o produtor rural - Perguntas e respostas da Receita Fed...
Imposto de Renda para o produtor rural - Perguntas e respostas da Receita Fed...Portal Canal Rural
 
Cours java avance débutant facile l'essentiel swing ,events
Cours java avance débutant facile l'essentiel swing ,events Cours java avance débutant facile l'essentiel swing ,events
Cours java avance débutant facile l'essentiel swing ,events Houssem Hamrouni
 
DTraceによるMySQL解析ことはじめ
DTraceによるMySQL解析ことはじめDTraceによるMySQL解析ことはじめ
DTraceによるMySQL解析ことはじめMikiya Okuno
 

What's hot (11)

How Women Rise PDF - Sally Helgesen
How Women Rise PDF - Sally Helgesen  How Women Rise PDF - Sally Helgesen
How Women Rise PDF - Sally Helgesen
 
Concevoir, développer et sécuriser des micro-services avec Spring Boot
Concevoir, développer et sécuriser des micro-services avec Spring BootConcevoir, développer et sécuriser des micro-services avec Spring Boot
Concevoir, développer et sécuriser des micro-services avec Spring Boot
 
Spring Meetup Paris - Back to the basics of Spring (Boot)
Spring Meetup Paris - Back to the basics of Spring (Boot)Spring Meetup Paris - Back to the basics of Spring (Boot)
Spring Meetup Paris - Back to the basics of Spring (Boot)
 
Web Programming - DB Galeri Foto
Web Programming - DB Galeri FotoWeb Programming - DB Galeri Foto
Web Programming - DB Galeri Foto
 
[네전따 27회] 네트워크 자동화 어렵지 않아요
[네전따 27회] 네트워크 자동화 어렵지 않아요[네전따 27회] 네트워크 자동화 어렵지 않아요
[네전따 27회] 네트워크 자동화 어렵지 않아요
 
Codetainer: a Docker-based browser code 'sandbox'
Codetainer: a Docker-based browser code 'sandbox'Codetainer: a Docker-based browser code 'sandbox'
Codetainer: a Docker-based browser code 'sandbox'
 
Un exemple élémentaire d'application MVC en PHP
Un exemple élémentaire d'application MVC en PHPUn exemple élémentaire d'application MVC en PHP
Un exemple élémentaire d'application MVC en PHP
 
GraphQL vs BFF: A critical perspective
GraphQL vs BFF: A critical perspectiveGraphQL vs BFF: A critical perspective
GraphQL vs BFF: A critical perspective
 
Imposto de Renda para o produtor rural - Perguntas e respostas da Receita Fed...
Imposto de Renda para o produtor rural - Perguntas e respostas da Receita Fed...Imposto de Renda para o produtor rural - Perguntas e respostas da Receita Fed...
Imposto de Renda para o produtor rural - Perguntas e respostas da Receita Fed...
 
Cours java avance débutant facile l'essentiel swing ,events
Cours java avance débutant facile l'essentiel swing ,events Cours java avance débutant facile l'essentiel swing ,events
Cours java avance débutant facile l'essentiel swing ,events
 
DTraceによるMySQL解析ことはじめ
DTraceによるMySQL解析ことはじめDTraceによるMySQL解析ことはじめ
DTraceによるMySQL解析ことはじめ
 

Similar to Creating Chatbots with Botman - English

My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I thinkWim Godden
 
Pengenalan AngularJS
Pengenalan AngularJSPengenalan AngularJS
Pengenalan AngularJSEdi Santoso
 
Building Conversational Experiences with Actions on Google
Building Conversational Experiences with Actions on Google Building Conversational Experiences with Actions on Google
Building Conversational Experiences with Actions on Google Peter Friese
 
Virtual Madness @ Etsy
Virtual Madness @ EtsyVirtual Madness @ Etsy
Virtual Madness @ EtsyNishan Subedi
 
User authentication module using php
User authentication module using phpUser authentication module using php
User authentication module using phpRishabh Srivastava
 
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
 

Similar to Creating Chatbots with Botman - English (20)

WordCamp Praga 2015
WordCamp Praga 2015WordCamp Praga 2015
WordCamp Praga 2015
 
My app is secure... I think
My app is secure... I thinkMy app is secure... I think
My app is secure... I think
 
Pengenalan AngularJS
Pengenalan AngularJSPengenalan AngularJS
Pengenalan AngularJS
 
Building Conversational Experiences with Actions on Google
Building Conversational Experiences with Actions on Google Building Conversational Experiences with Actions on Google
Building Conversational Experiences with Actions on Google
 
Virtual Madness @ Etsy
Virtual Madness @ EtsyVirtual Madness @ Etsy
Virtual Madness @ Etsy
 
User authentication module using php
User authentication module using phpUser authentication module using php
User authentication module using php
 
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.
 

More from Laravel Poland MeetUp

WebRTC+Websockety - Jak stworzyłem aplikację do kamerek internetowych w Larav...
WebRTC+Websockety - Jak stworzyłem aplikację do kamerek internetowych w Larav...WebRTC+Websockety - Jak stworzyłem aplikację do kamerek internetowych w Larav...
WebRTC+Websockety - Jak stworzyłem aplikację do kamerek internetowych w Larav...Laravel Poland MeetUp
 
xD bug - Jak debugować PHP-owe aplikacje (Xdebug)
xD bug - Jak debugować PHP-owe aplikacje (Xdebug) xD bug - Jak debugować PHP-owe aplikacje (Xdebug)
xD bug - Jak debugować PHP-owe aplikacje (Xdebug) Laravel Poland MeetUp
 
Kilka slajdów o castowaniu atrybutów w Eloquent
Kilka slajdów o castowaniu atrybutów w EloquentKilka slajdów o castowaniu atrybutów w Eloquent
Kilka slajdów o castowaniu atrybutów w EloquentLaravel Poland MeetUp
 
Jak przyspieszyłem aplikację produkcyjną o ponad 40%
Jak przyspieszyłem aplikację produkcyjną o ponad 40%Jak przyspieszyłem aplikację produkcyjną o ponad 40%
Jak przyspieszyłem aplikację produkcyjną o ponad 40%Laravel Poland MeetUp
 
Cykl życia zapytania HTTP (pod maską)
Cykl życia zapytania HTTP (pod maską)Cykl życia zapytania HTTP (pod maską)
Cykl życia zapytania HTTP (pod maską)Laravel Poland MeetUp
 
Enumy w Laravelu - dlaczego warto stosować?
Enumy w Laravelu - dlaczego warto stosować?Enumy w Laravelu - dlaczego warto stosować?
Enumy w Laravelu - dlaczego warto stosować?Laravel Poland MeetUp
 
Laravelowe paczki do uwierzytelniania
Laravelowe paczki do uwierzytelnianiaLaravelowe paczki do uwierzytelniania
Laravelowe paczki do uwierzytelnianiaLaravel Poland MeetUp
 
Przegląd najciekawszych wtyczek do Laravela
Przegląd najciekawszych wtyczek do LaravelaPrzegląd najciekawszych wtyczek do Laravela
Przegląd najciekawszych wtyczek do LaravelaLaravel Poland MeetUp
 
Laravel Dusk - prosty przepis na testy E2E
Laravel Dusk - prosty przepis na testy E2ELaravel Dusk - prosty przepis na testy E2E
Laravel Dusk - prosty przepis na testy E2ELaravel Poland MeetUp
 
Laravel Octane - czy na pewno taki szybki?
Laravel Octane - czy na pewno taki szybki?Laravel Octane - czy na pewno taki szybki?
Laravel Octane - czy na pewno taki szybki?Laravel Poland MeetUp
 
Automatyzacja utrzymania jakości w środowisku PHP
Automatyzacja utrzymania jakości w środowisku PHPAutomatyzacja utrzymania jakości w środowisku PHP
Automatyzacja utrzymania jakości w środowisku PHPLaravel Poland MeetUp
 
Wstęp do Gitlab CI/CD w aplikacjach napisanych w Laravel
Wstęp do Gitlab CI/CD w aplikacjach napisanych w LaravelWstęp do Gitlab CI/CD w aplikacjach napisanych w Laravel
Wstęp do Gitlab CI/CD w aplikacjach napisanych w LaravelLaravel Poland MeetUp
 

More from Laravel Poland MeetUp (20)

WebRTC+Websockety - Jak stworzyłem aplikację do kamerek internetowych w Larav...
WebRTC+Websockety - Jak stworzyłem aplikację do kamerek internetowych w Larav...WebRTC+Websockety - Jak stworzyłem aplikację do kamerek internetowych w Larav...
WebRTC+Websockety - Jak stworzyłem aplikację do kamerek internetowych w Larav...
 
xD bug - Jak debugować PHP-owe aplikacje (Xdebug)
xD bug - Jak debugować PHP-owe aplikacje (Xdebug) xD bug - Jak debugować PHP-owe aplikacje (Xdebug)
xD bug - Jak debugować PHP-owe aplikacje (Xdebug)
 
Kilka slajdów o castowaniu atrybutów w Eloquent
Kilka slajdów o castowaniu atrybutów w EloquentKilka slajdów o castowaniu atrybutów w Eloquent
Kilka slajdów o castowaniu atrybutów w Eloquent
 
Licencje otwartego oprogramowania
Licencje otwartego oprogramowaniaLicencje otwartego oprogramowania
Licencje otwartego oprogramowania
 
Jak przyspieszyłem aplikację produkcyjną o ponad 40%
Jak przyspieszyłem aplikację produkcyjną o ponad 40%Jak przyspieszyłem aplikację produkcyjną o ponad 40%
Jak przyspieszyłem aplikację produkcyjną o ponad 40%
 
Jak przemycić Shape Up do Scruma?
Jak przemycić Shape Up do Scruma?Jak przemycić Shape Up do Scruma?
Jak przemycić Shape Up do Scruma?
 
Cykl życia zapytania HTTP (pod maską)
Cykl życia zapytania HTTP (pod maską)Cykl życia zapytania HTTP (pod maską)
Cykl życia zapytania HTTP (pod maską)
 
Enumy w Laravelu - dlaczego warto stosować?
Enumy w Laravelu - dlaczego warto stosować?Enumy w Laravelu - dlaczego warto stosować?
Enumy w Laravelu - dlaczego warto stosować?
 
Laravelowe paczki do uwierzytelniania
Laravelowe paczki do uwierzytelnianiaLaravelowe paczki do uwierzytelniania
Laravelowe paczki do uwierzytelniania
 
Przegląd najciekawszych wtyczek do Laravela
Przegląd najciekawszych wtyczek do LaravelaPrzegląd najciekawszych wtyczek do Laravela
Przegląd najciekawszych wtyczek do Laravela
 
Walidacja w Laravelu
Walidacja w LaraveluWalidacja w Laravelu
Walidacja w Laravelu
 
(prawie) Wszystko o Tinkerze
(prawie) Wszystko o Tinkerze(prawie) Wszystko o Tinkerze
(prawie) Wszystko o Tinkerze
 
Laravel Dusk - prosty przepis na testy E2E
Laravel Dusk - prosty przepis na testy E2ELaravel Dusk - prosty przepis na testy E2E
Laravel Dusk - prosty przepis na testy E2E
 
Laravel Octane - czy na pewno taki szybki?
Laravel Octane - czy na pewno taki szybki?Laravel Octane - czy na pewno taki szybki?
Laravel Octane - czy na pewno taki szybki?
 
Laravel Jobs i PHP8
Laravel Jobs i PHP8Laravel Jobs i PHP8
Laravel Jobs i PHP8
 
Wszystko o Laravel Livewire
Wszystko o Laravel Livewire Wszystko o Laravel Livewire
Wszystko o Laravel Livewire
 
Laravel/PHP - zderzenie z PDFami
Laravel/PHP - zderzenie z PDFamiLaravel/PHP - zderzenie z PDFami
Laravel/PHP - zderzenie z PDFami
 
Action-based Laravel
Action-based LaravelAction-based Laravel
Action-based Laravel
 
Automatyzacja utrzymania jakości w środowisku PHP
Automatyzacja utrzymania jakości w środowisku PHPAutomatyzacja utrzymania jakości w środowisku PHP
Automatyzacja utrzymania jakości w środowisku PHP
 
Wstęp do Gitlab CI/CD w aplikacjach napisanych w Laravel
Wstęp do Gitlab CI/CD w aplikacjach napisanych w LaravelWstęp do Gitlab CI/CD w aplikacjach napisanych w Laravel
Wstęp do Gitlab CI/CD w aplikacjach napisanych w Laravel
 

Recently uploaded

Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
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
 
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
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
software engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxsoftware engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxnada99848
 
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
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 

Recently uploaded (20)

Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
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
 
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
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
software engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxsoftware engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptx
 
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
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 

Creating Chatbots with Botman - English

  • 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/'))));