SlideShare a Scribd company logo
1 of 88
Download to read offline
HOW I TAUGHT * TO TELL LAME JOKES?HOW I TAUGHT * TO TELL LAME JOKES?
 
* FACEBOOK MESSENGER* FACEBOOK MESSENGER
GitHub: @kkoscielniak
HELLO THERE!HELLO THERE!
This talk will be about bots.
(If you didn’t nd out yet)
BOTS?BOTS?
services which can be interacted with by chat
powered by speci c rules set
sometimes utilizing AI
working on the Messenger Platform
BOTS!BOTS!
Poncho - ask bot about the weather
KrEdytka - take a loan via Messenger
Pizza Hut - pizza orders
Pismo Święte - no need to describe this one
endless possibilities
to create useless stuff
they just didn’t take control over the world yet
WHY EVEN BOTHER?WHY EVEN BOTHER?
Satya Nadella, Microsoft CEO
Bots are the new Apps
Peter Rojas, Betaworks
People are now spending more time in
messaging apps than in social media and
that is a huge turning point
Matt Schmidt, Chatbots Magazine
It’s potentially a huge business
opportunity for anyone willing to jump
head rst and build something people
want
Some random at DevDuck, BrainHub
Bots are fun, because I tell so
STOP! DEMO TIMESTOP! DEMO TIME
LET’S BUILD A BOTLET’S BUILD A BOT
Create Facebook App
https://developers.facebook.com/
Add the Messenger product
Select a fan page and generate access token
Run into the wall
THE WALL?THE WALL?
THE CODETHE CODE
// Create Express app
const app = require('express')();
// set up webhook routing
app.get('/webhook', (req, res) => {
if (req.query['hub.verify_token'] === 'super_token') {
res.send(req.query['hub.challenge']);
}
res.send('Error, wrong token');
});
// run the app
app.listen(app.get('port'));
Get back to the wall
Subscribe the access token
$ curl -X POST 
"https://graph.facebook.com/v2.6/me/subscribed_apps? 
access_token=<PAGE_ACCESS_TOKEN>"
# response
{"success": true}
PINGPING
Create POST endpoint for /webhook
router.post('/webhook', async(req, res) => {
const messagingEvents = req.body.entry[0].messaging;
for (let i = 0; i < messagingEvents.length; i++) {
const event = req.body.entry[0].messaging[i];
const senderId = event.id;
const greeting = getRandomMessage(predefined.greetings);
if (event.message && event.message.text) {
await sendTextMessage(senderId, joke.question);
await sendTextMessage(senderId, joke.answer);
}
}
res.sendStatus(200);
});
Create sendTextMessage function
const sendTextMessage = (id, text) => {
request({
method: 'POST',
url: constants.FACEBOOK_GRAPH_URL, // Facebook Graph URL
qs: { access_token: config.accessToken }, // Facebook Access
json: {
recipient: { id },
message: { text },
},
},
(err, res) => {
// [...]
});
};
Assign prede ned joke
const joke = {
question: 'Jaki jest magik gdy straci magię?',
answer: 'Rozczarowany ',
}
Pong
screenshot
ADD MORE JOKESADD MORE JOKES
Create array of objects
const jokes = [
{
question: 'Jaki jest magik gdy straci magię?',
answer: 'Rozczarowany',
},
{
question: 'Jakie jest imię greckiego boga czystosci?',
answer: 'Domestos',
},
{
question: 'Dlaczego klatka piersiowa ma grosze?',
answer: 'Bo żebra',
},
// [...]
];
Create getRandomMessage function
getRandomMessage = array =>
array[Math.floor(Math.random() * array.length)];
const joke = getRandomMessage(jokes);
// [...]
await sendTextMessage(senderId, joke.question);
await sendTextMessage(senderId, joke.answer);
BUT THIS BOT IS SILLYBUT THIS BOT IS SILLY
it is not interactive
it does not conversate
it feels like a bot
it does not understand intents
LET’S IMPROVE IT A LITTLELET’S IMPROVE IT A LITTLE
HOW TO MAKE THE BOT MORE INTERACTIVE?HOW TO MAKE THE BOT MORE INTERACTIVE?
Generic postback template
Button template
List template
Media template
Order receipt template
Open Graph template
LET’S ADD A POSTBACKLET’S ADD A POSTBACK
Create message with generic template
const message = {
attachment: {
type: 'template',
payload: {
template_type: 'generic',
elements: [{
title: 'Podoba Ci się?',
buttons: [
{ type: 'postback', title: `Dobre`, payload: 'good' },
{ type: 'postback', title: `Słabe`, payload: 'bad' }],
}],
},
},
};
Create askAboutFeedback function
const askAboutFeedback = (id, text) => {
request({
method: 'POST',
url: constants.FACEBOOK_GRAPH_URL, // Facebook Graph URL
qs: { access_token: config.accessToken }, // Facebook Access
json: {
recipient: { id },
message,
},
},
(err, res) => {
// [...]
});
};
Use askAboutFeedback function
if (event.message && event.message.text) {
await sendTextMessage(senderId, joke.question);
await sendTextMessage(senderId, joke.answer);
await askAboutFeedback(senderId);
}
Handle the postback
if (event.message && event.message.text) {
// [...]
} else if (event.postback && event.postback.payload) {
switch (event.postback.payload) {
case 'good':
await askAboutNewJoke(senderId);
break;
case 'bad':
await sendTextMessage(senderId, 'Buu');
break;
// [...]
}
}
The postback
it is not interactive
it does not conversate
it feels like a bot
it does not understand messages and intents
LET’S MAKE IT MORE… HUMAN?LET’S MAKE IT MORE… HUMAN?
BUT… HOW?BUT… HOW?
Add a delay for responses
Create sendTypingIndicator function
const sendTypingIndicator = async id => {
await request({
...requestParams,
json: {
recipient: {
id,
},
sender_action: 'typing_on', // instead of message object
},
});
};
Add some delay to sendTextMessage function
const delay = require('delay');
const sendTextMessage = (id, text) => {
await delay(text.length * 100);
request({
// [...]
},
(err, res) => {
// [...]
});
};
WHAT ELSE?WHAT ELSE?
Add random positive and negative emoji
const emotion = require('emoji-emotion');
const happyEmojiList =
emotion.filter(emoji => emoji.polarity > 1);
getHappyEmoji = () =>
happyEmojiList[Math.floor(
Math.random() * happyEmojiList.length
)].emoji;
// the same goes for sad emoji
Use it whenever you need it
await sendTextMessage(senderId, `Okej ${getHappyEmoji()}`);
await sendTextMessage(senderId, `Buu ${getSadEmoji()}`);
OKAY, WE’RE GETTING THERE…OKAY, WE’RE GETTING THERE…
it is not interactive
it does not conversate
it feels like a bot… this much
it does not understand messages and intents
ONE THING MISSINGONE THING MISSING
LET’S MAKE IT TALKATIVELET’S MAKE IT TALKATIVE
Wit.ai service
Create getIntent function
const { Wit } = require('node-wit');
const wit = new Wit({
accessToken: config.witAccessToken,
});
const getIntent = async message => {
const mostPropbableIntent = await wit.message(message)
.then(data => {
if (data.entities.intent) {
const mostProbableIntent = data.entities.intent.reduce(
(prev, current) =>
(prev.confidence > current.confidence)
? prev : current
);
Handle the intents
if (event.message && event.message.text) {
const intent = await getIntent(event.message.text);
switch (intent) {
case 'greet':
await sendAGreeting(senderId);
break;
case 'get_joke':
await sendAJoke(senderId);
break;
default:
sender.sendTextMessage(senderId, `Niestety nie rozumiem ${g
break;
}
}
it is not interactive
it does not conversate
it feels like a bot… this much
it does not understand messages and intents
WE HAVE A BOT!WE HAVE A BOT!
WHAT NEXT? ⏭WHAT NEXT? ⏭
add more intents, for example “Tell me something
about you”
add “Message read” indicator
add more sophisticated AI
create bot ordering french fries and doing a massage
when he knows you’re upset
SOME TAKEAWAYS FOR YOU GUYSSOME TAKEAWAYS FOR YOU GUYS
do stupid, redundant things
you never know where will it get you
you might even give talk about it
QUESTIONS ❓QUESTIONS ❓
THANKSTHANKS
http://kkoscielniak.github.io/kawalarz-slides
http://github.com/kkoscielniak/kawalarz

More Related Content

Similar to How I Taught a Bot to Tell Lame Jokes

Creating Chatbots with Botman - English
Creating Chatbots with Botman - EnglishCreating Chatbots with Botman - English
Creating Chatbots with Botman - EnglishLaravel Poland MeetUp
 
Laravel Poznań Meetup #2 - Creating chatbots with BotMan
Laravel Poznań Meetup #2 - Creating chatbots with BotManLaravel Poznań Meetup #2 - Creating chatbots with BotMan
Laravel Poznań Meetup #2 - Creating chatbots with BotManHighSolutions Sp. z o.o.
 
Desafios do Profissionalismo Ágil
Desafios do Profissionalismo ÁgilDesafios do Profissionalismo Ágil
Desafios do Profissionalismo ÁgilVictor Hugo Germano
 
Writing a slack chatbot DrupalCampLA
Writing a slack chatbot DrupalCampLAWriting a slack chatbot DrupalCampLA
Writing a slack chatbot DrupalCampLAJesus Manuel Olivas
 
CHATBOT using Facebook Messenger
CHATBOT using Facebook MessengerCHATBOT using Facebook Messenger
CHATBOT using Facebook MessengerNavjyotsinh Jadeja
 
How To Build A Telegram Bot Using NodeJS, Express and MongoDB
How To Build A Telegram Bot Using NodeJS, Express and MongoDBHow To Build A Telegram Bot Using NodeJS, Express and MongoDB
How To Build A Telegram Bot Using NodeJS, Express and MongoDBLouis Nel
 
Coffeescript: No really, it's just Javascript
Coffeescript: No really, it's just JavascriptCoffeescript: No really, it's just Javascript
Coffeescript: No really, it's just JavascriptBrian Mann
 
Bots: Basics @ Javascript Tonight, 2017.09.22
Bots: Basics @ Javascript Tonight, 2017.09.22Bots: Basics @ Javascript Tonight, 2017.09.22
Bots: Basics @ Javascript Tonight, 2017.09.22Andrii Sierkov
 
4Developers: Michał Szczepanik- Kotlin - Let’s ketchup it
4Developers: Michał Szczepanik- Kotlin - Let’s ketchup it4Developers: Michał Szczepanik- Kotlin - Let’s ketchup it
4Developers: Michał Szczepanik- Kotlin - Let’s ketchup itPROIDEA
 

Similar to How I Taught a Bot to Tell Lame Jokes (11)

Windows Phone Launchers and Choosers
Windows Phone Launchers and ChoosersWindows Phone Launchers and Choosers
Windows Phone Launchers and Choosers
 
Creating Chatbots with Botman - English
Creating Chatbots with Botman - EnglishCreating Chatbots with Botman - English
Creating Chatbots with Botman - English
 
Laravel Poznań Meetup #2 - Creating chatbots with BotMan
Laravel Poznań Meetup #2 - Creating chatbots with BotManLaravel Poznań Meetup #2 - Creating chatbots with BotMan
Laravel Poznań Meetup #2 - Creating chatbots with BotMan
 
Desafios do Profissionalismo Ágil
Desafios do Profissionalismo ÁgilDesafios do Profissionalismo Ágil
Desafios do Profissionalismo Ágil
 
Writing a slack chatbot DrupalCampLA
Writing a slack chatbot DrupalCampLAWriting a slack chatbot DrupalCampLA
Writing a slack chatbot DrupalCampLA
 
CHATBOT using Facebook Messenger
CHATBOT using Facebook MessengerCHATBOT using Facebook Messenger
CHATBOT using Facebook Messenger
 
How To Build A Telegram Bot Using NodeJS, Express and MongoDB
How To Build A Telegram Bot Using NodeJS, Express and MongoDBHow To Build A Telegram Bot Using NodeJS, Express and MongoDB
How To Build A Telegram Bot Using NodeJS, Express and MongoDB
 
Coffeescript: No really, it's just Javascript
Coffeescript: No really, it's just JavascriptCoffeescript: No really, it's just Javascript
Coffeescript: No really, it's just Javascript
 
Bots: Basics @ Javascript Tonight, 2017.09.22
Bots: Basics @ Javascript Tonight, 2017.09.22Bots: Basics @ Javascript Tonight, 2017.09.22
Bots: Basics @ Javascript Tonight, 2017.09.22
 
Day 5
Day 5Day 5
Day 5
 
4Developers: Michał Szczepanik- Kotlin - Let’s ketchup it
4Developers: Michał Szczepanik- Kotlin - Let’s ketchup it4Developers: Michał Szczepanik- Kotlin - Let’s ketchup it
4Developers: Michał Szczepanik- Kotlin - Let’s ketchup it
 

More from Brainhub

AWS – jak rozpocząć przygodę z chmurą?
AWS – jak rozpocząć przygodę z chmurą?AWS – jak rozpocząć przygodę z chmurą?
AWS – jak rozpocząć przygodę z chmurą?Brainhub
 
Konfiguracja GitLab CI/CD pipelines od podstaw
Konfiguracja GitLab CI/CD pipelines od podstawKonfiguracja GitLab CI/CD pipelines od podstaw
Konfiguracja GitLab CI/CD pipelines od podstawBrainhub
 
tRPC - czy to koniec GraphQL?
tRPC - czy to koniec GraphQL?tRPC - czy to koniec GraphQL?
tRPC - czy to koniec GraphQL?Brainhub
 
Solid.js - następca Reacta?
Solid.js - następca Reacta?Solid.js - następca Reacta?
Solid.js - następca Reacta?Brainhub
 
Struktury algebraiczne w JavaScripcie
Struktury algebraiczne w JavaScripcieStruktury algebraiczne w JavaScripcie
Struktury algebraiczne w JavaScripcieBrainhub
 
WebAssembly - czy dzisiaj mi się to przyda do pracy?
WebAssembly - czy dzisiaj mi się to przyda do pracy?WebAssembly - czy dzisiaj mi się to przyda do pracy?
WebAssembly - czy dzisiaj mi się to przyda do pracy?Brainhub
 
Ewoluowanie neuronowych mózgów w JavaScript, wielowątkowo!
Ewoluowanie neuronowych mózgów w JavaScript, wielowątkowo!Ewoluowanie neuronowych mózgów w JavaScript, wielowątkowo!
Ewoluowanie neuronowych mózgów w JavaScript, wielowątkowo!Brainhub
 
Go home TypeScript, you're drunk!
Go home TypeScript, you're drunk!Go home TypeScript, you're drunk!
Go home TypeScript, you're drunk!Brainhub
 
The hunt of the unicorn, to capture productivity
The hunt of the unicorn, to capture productivityThe hunt of the unicorn, to capture productivity
The hunt of the unicorn, to capture productivityBrainhub
 
TDD in the wild
TDD in the wildTDD in the wild
TDD in the wildBrainhub
 
WebAssembly - kolejny buzzword, czy (r)ewolucja?
WebAssembly - kolejny buzzword, czy (r)ewolucja?WebAssembly - kolejny buzzword, czy (r)ewolucja?
WebAssembly - kolejny buzzword, czy (r)ewolucja?Brainhub
 
React performance
React performanceReact performance
React performanceBrainhub
 
Introduction to RxJS
Introduction to RxJSIntroduction to RxJS
Introduction to RxJSBrainhub
 
React Native in a nutshell
React Native in a nutshellReact Native in a nutshell
React Native in a nutshellBrainhub
 
Ant Colony Optimization (Heuristic algorithms & Swarm intelligence)
Ant Colony Optimization (Heuristic algorithms & Swarm intelligence)Ant Colony Optimization (Heuristic algorithms & Swarm intelligence)
Ant Colony Optimization (Heuristic algorithms & Swarm intelligence)Brainhub
 
Technologia, a Startup - Brainhub
Technologia, a Startup - BrainhubTechnologia, a Startup - Brainhub
Technologia, a Startup - BrainhubBrainhub
 
Introduction to GraphQL
Introduction to GraphQLIntroduction to GraphQL
Introduction to GraphQLBrainhub
 
How should you React to Redux
How should you React to ReduxHow should you React to Redux
How should you React to ReduxBrainhub
 
Wprowadzenie do React
Wprowadzenie do ReactWprowadzenie do React
Wprowadzenie do ReactBrainhub
 
JavaScript and Desktop Apps - Introduction to Electron
JavaScript and Desktop Apps - Introduction to ElectronJavaScript and Desktop Apps - Introduction to Electron
JavaScript and Desktop Apps - Introduction to ElectronBrainhub
 

More from Brainhub (20)

AWS – jak rozpocząć przygodę z chmurą?
AWS – jak rozpocząć przygodę z chmurą?AWS – jak rozpocząć przygodę z chmurą?
AWS – jak rozpocząć przygodę z chmurą?
 
Konfiguracja GitLab CI/CD pipelines od podstaw
Konfiguracja GitLab CI/CD pipelines od podstawKonfiguracja GitLab CI/CD pipelines od podstaw
Konfiguracja GitLab CI/CD pipelines od podstaw
 
tRPC - czy to koniec GraphQL?
tRPC - czy to koniec GraphQL?tRPC - czy to koniec GraphQL?
tRPC - czy to koniec GraphQL?
 
Solid.js - następca Reacta?
Solid.js - następca Reacta?Solid.js - następca Reacta?
Solid.js - następca Reacta?
 
Struktury algebraiczne w JavaScripcie
Struktury algebraiczne w JavaScripcieStruktury algebraiczne w JavaScripcie
Struktury algebraiczne w JavaScripcie
 
WebAssembly - czy dzisiaj mi się to przyda do pracy?
WebAssembly - czy dzisiaj mi się to przyda do pracy?WebAssembly - czy dzisiaj mi się to przyda do pracy?
WebAssembly - czy dzisiaj mi się to przyda do pracy?
 
Ewoluowanie neuronowych mózgów w JavaScript, wielowątkowo!
Ewoluowanie neuronowych mózgów w JavaScript, wielowątkowo!Ewoluowanie neuronowych mózgów w JavaScript, wielowątkowo!
Ewoluowanie neuronowych mózgów w JavaScript, wielowątkowo!
 
Go home TypeScript, you're drunk!
Go home TypeScript, you're drunk!Go home TypeScript, you're drunk!
Go home TypeScript, you're drunk!
 
The hunt of the unicorn, to capture productivity
The hunt of the unicorn, to capture productivityThe hunt of the unicorn, to capture productivity
The hunt of the unicorn, to capture productivity
 
TDD in the wild
TDD in the wildTDD in the wild
TDD in the wild
 
WebAssembly - kolejny buzzword, czy (r)ewolucja?
WebAssembly - kolejny buzzword, czy (r)ewolucja?WebAssembly - kolejny buzzword, czy (r)ewolucja?
WebAssembly - kolejny buzzword, czy (r)ewolucja?
 
React performance
React performanceReact performance
React performance
 
Introduction to RxJS
Introduction to RxJSIntroduction to RxJS
Introduction to RxJS
 
React Native in a nutshell
React Native in a nutshellReact Native in a nutshell
React Native in a nutshell
 
Ant Colony Optimization (Heuristic algorithms & Swarm intelligence)
Ant Colony Optimization (Heuristic algorithms & Swarm intelligence)Ant Colony Optimization (Heuristic algorithms & Swarm intelligence)
Ant Colony Optimization (Heuristic algorithms & Swarm intelligence)
 
Technologia, a Startup - Brainhub
Technologia, a Startup - BrainhubTechnologia, a Startup - Brainhub
Technologia, a Startup - Brainhub
 
Introduction to GraphQL
Introduction to GraphQLIntroduction to GraphQL
Introduction to GraphQL
 
How should you React to Redux
How should you React to ReduxHow should you React to Redux
How should you React to Redux
 
Wprowadzenie do React
Wprowadzenie do ReactWprowadzenie do React
Wprowadzenie do React
 
JavaScript and Desktop Apps - Introduction to Electron
JavaScript and Desktop Apps - Introduction to ElectronJavaScript and Desktop Apps - Introduction to Electron
JavaScript and Desktop Apps - Introduction to Electron
 

Recently uploaded

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
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
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
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
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
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfLivetecs LLC
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
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
 
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
 
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
 
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
 
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.
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
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
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 

Recently uploaded (20)

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
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
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...
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
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....
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdf
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
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
 
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
 
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...
 
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
 
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
 
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
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
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
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 

How I Taught a Bot to Tell Lame Jokes

  • 1. HOW I TAUGHT * TO TELL LAME JOKES?HOW I TAUGHT * TO TELL LAME JOKES?   * FACEBOOK MESSENGER* FACEBOOK MESSENGER
  • 4. This talk will be about bots. (If you didn’t nd out yet)
  • 6. services which can be interacted with by chat powered by speci c rules set sometimes utilizing AI working on the Messenger Platform
  • 8. Poncho - ask bot about the weather
  • 9.
  • 10. KrEdytka - take a loan via Messenger
  • 11.
  • 12. Pizza Hut - pizza orders
  • 13.
  • 14. Pismo Święte - no need to describe this one
  • 15.
  • 16. endless possibilities to create useless stuff they just didn’t take control over the world yet
  • 17. WHY EVEN BOTHER?WHY EVEN BOTHER?
  • 18. Satya Nadella, Microsoft CEO Bots are the new Apps
  • 19. Peter Rojas, Betaworks People are now spending more time in messaging apps than in social media and that is a huge turning point
  • 20. Matt Schmidt, Chatbots Magazine It’s potentially a huge business opportunity for anyone willing to jump head rst and build something people want
  • 21. Some random at DevDuck, BrainHub Bots are fun, because I tell so
  • 22. STOP! DEMO TIMESTOP! DEMO TIME
  • 23. LET’S BUILD A BOTLET’S BUILD A BOT
  • 25. Add the Messenger product
  • 26. Select a fan page and generate access token
  • 27. Run into the wall
  • 28.
  • 29. THE WALL?THE WALL? THE CODETHE CODE
  • 30. // Create Express app const app = require('express')(); // set up webhook routing app.get('/webhook', (req, res) => { if (req.query['hub.verify_token'] === 'super_token') { res.send(req.query['hub.challenge']); } res.send('Error, wrong token'); }); // run the app app.listen(app.get('port'));
  • 31. Get back to the wall
  • 32. Subscribe the access token $ curl -X POST "https://graph.facebook.com/v2.6/me/subscribed_apps? access_token=<PAGE_ACCESS_TOKEN>" # response {"success": true}
  • 34. Create POST endpoint for /webhook router.post('/webhook', async(req, res) => { const messagingEvents = req.body.entry[0].messaging; for (let i = 0; i < messagingEvents.length; i++) { const event = req.body.entry[0].messaging[i]; const senderId = event.id; const greeting = getRandomMessage(predefined.greetings); if (event.message && event.message.text) { await sendTextMessage(senderId, joke.question); await sendTextMessage(senderId, joke.answer); } } res.sendStatus(200); });
  • 35. Create sendTextMessage function const sendTextMessage = (id, text) => { request({ method: 'POST', url: constants.FACEBOOK_GRAPH_URL, // Facebook Graph URL qs: { access_token: config.accessToken }, // Facebook Access json: { recipient: { id }, message: { text }, }, }, (err, res) => { // [...] }); };
  • 36. Assign prede ned joke const joke = { question: 'Jaki jest magik gdy straci magię?', answer: 'Rozczarowany ', }
  • 38.
  • 39. ADD MORE JOKESADD MORE JOKES
  • 40. Create array of objects const jokes = [ { question: 'Jaki jest magik gdy straci magię?', answer: 'Rozczarowany', }, { question: 'Jakie jest imię greckiego boga czystosci?', answer: 'Domestos', }, { question: 'Dlaczego klatka piersiowa ma grosze?', answer: 'Bo żebra', }, // [...] ];
  • 41. Create getRandomMessage function getRandomMessage = array => array[Math.floor(Math.random() * array.length)]; const joke = getRandomMessage(jokes); // [...] await sendTextMessage(senderId, joke.question); await sendTextMessage(senderId, joke.answer);
  • 42. BUT THIS BOT IS SILLYBUT THIS BOT IS SILLY
  • 43. it is not interactive it does not conversate it feels like a bot it does not understand intents
  • 44. LET’S IMPROVE IT A LITTLELET’S IMPROVE IT A LITTLE
  • 45. HOW TO MAKE THE BOT MORE INTERACTIVE?HOW TO MAKE THE BOT MORE INTERACTIVE?
  • 49.
  • 52.
  • 54. LET’S ADD A POSTBACKLET’S ADD A POSTBACK
  • 55. Create message with generic template const message = { attachment: { type: 'template', payload: { template_type: 'generic', elements: [{ title: 'Podoba Ci się?', buttons: [ { type: 'postback', title: `Dobre`, payload: 'good' }, { type: 'postback', title: `Słabe`, payload: 'bad' }], }], }, }, };
  • 56. Create askAboutFeedback function const askAboutFeedback = (id, text) => { request({ method: 'POST', url: constants.FACEBOOK_GRAPH_URL, // Facebook Graph URL qs: { access_token: config.accessToken }, // Facebook Access json: { recipient: { id }, message, }, }, (err, res) => { // [...] }); };
  • 57. Use askAboutFeedback function if (event.message && event.message.text) { await sendTextMessage(senderId, joke.question); await sendTextMessage(senderId, joke.answer); await askAboutFeedback(senderId); }
  • 58. Handle the postback if (event.message && event.message.text) { // [...] } else if (event.postback && event.postback.payload) { switch (event.postback.payload) { case 'good': await askAboutNewJoke(senderId); break; case 'bad': await sendTextMessage(senderId, 'Buu'); break; // [...] } }
  • 60.
  • 61. it is not interactive it does not conversate it feels like a bot it does not understand messages and intents
  • 62. LET’S MAKE IT MORE… HUMAN?LET’S MAKE IT MORE… HUMAN?
  • 64. Add a delay for responses
  • 65.
  • 66. Create sendTypingIndicator function const sendTypingIndicator = async id => { await request({ ...requestParams, json: { recipient: { id, }, sender_action: 'typing_on', // instead of message object }, }); };
  • 67. Add some delay to sendTextMessage function const delay = require('delay'); const sendTextMessage = (id, text) => { await delay(text.length * 100); request({ // [...] }, (err, res) => { // [...] }); };
  • 69.
  • 70. Add random positive and negative emoji const emotion = require('emoji-emotion'); const happyEmojiList = emotion.filter(emoji => emoji.polarity > 1); getHappyEmoji = () => happyEmojiList[Math.floor( Math.random() * happyEmojiList.length )].emoji; // the same goes for sad emoji
  • 71. Use it whenever you need it await sendTextMessage(senderId, `Okej ${getHappyEmoji()}`); await sendTextMessage(senderId, `Buu ${getSadEmoji()}`);
  • 72. OKAY, WE’RE GETTING THERE…OKAY, WE’RE GETTING THERE…
  • 73. it is not interactive it does not conversate it feels like a bot… this much it does not understand messages and intents
  • 74. ONE THING MISSINGONE THING MISSING
  • 75. LET’S MAKE IT TALKATIVELET’S MAKE IT TALKATIVE
  • 76.
  • 78. Create getIntent function const { Wit } = require('node-wit'); const wit = new Wit({ accessToken: config.witAccessToken, }); const getIntent = async message => { const mostPropbableIntent = await wit.message(message) .then(data => { if (data.entities.intent) { const mostProbableIntent = data.entities.intent.reduce( (prev, current) => (prev.confidence > current.confidence) ? prev : current );
  • 79. Handle the intents if (event.message && event.message.text) { const intent = await getIntent(event.message.text); switch (intent) { case 'greet': await sendAGreeting(senderId); break; case 'get_joke': await sendAJoke(senderId); break; default: sender.sendTextMessage(senderId, `Niestety nie rozumiem ${g break; } }
  • 80. it is not interactive it does not conversate it feels like a bot… this much it does not understand messages and intents
  • 81. WE HAVE A BOT!WE HAVE A BOT!
  • 82. WHAT NEXT? ⏭WHAT NEXT? ⏭
  • 83. add more intents, for example “Tell me something about you” add “Message read” indicator add more sophisticated AI create bot ordering french fries and doing a massage when he knows you’re upset
  • 84. SOME TAKEAWAYS FOR YOU GUYSSOME TAKEAWAYS FOR YOU GUYS
  • 85. do stupid, redundant things you never know where will it get you you might even give talk about it