Peter McAree
UI Engineer @ Flexera
@PMc_A
@PMc_A
@PMc_A
5 Year Trend
@PMc_A
~90% of mobile users time is spent on messaging & email apps
2016
@PMc_A
@PMc_A
@PMc_A
@PMc_A
MS Bot Framework
Wit.ai
Amazon Lex
@PMc_A
const express = require('express');
const app = express();
// Listen for incoming messages.
app.post('/api/messages', (req, res) => {
});
app.listen(3978, () => console.log(`Listening on 3978.`));
Node.js typical web service
@PMc_A
const { BotFrameworkAdapter } = require('botbuilder');
// Create adapter to facilitate communication
const adapter = new BotFrameworkAdapter({
appId: process.env.MicrosoftAppId,
appPassword: process.env.MicrosoftAppPassword
});
// Listen for incoming requests.
app.post('/api/messages', (req, res) => {
adapter.processActivity(req, res, async(turnContext) => {
// TODO: Include bot handler
});
});
Setup BotFrameworkAdapter
@PMc_A
NLP Concepts
@PMc_A
@PMc_A
const { LuisRecognizer } = require('botbuilder-ai');
class LuisBot {
constructor(application, luisPredictionOptions) {
this.luisRecognizer = new LuisRecognizer(application, luisPredicationOptions);
}
async onTurn(turnContext) {
}
}
Create LuisBot class
@PMc_A
async onTurn(turnContext) {
// Make API call to LUIS with turnContext (containing user message)
const results = await this.luisRecognizer.recognize(turnContext);
// Extract top intent from results
const topIntent = results.luisResult.topScoringIntent;
switch(topIntent.intent) {
case 'Greeting':
await turnContext.sendActivity('Hey! Ask me something to get started.');
break;
case 'GetMeetupInfo':
await getMeetupInfoIntent.handleIntent(turnContext);
break;
}
}
Create LUIS handler
@PMc_A
const bot = new LuisBot(luisApplication, luisPredictionOptions);
// Listen for incoming requests.
app.post('/api/messages', (req, res) => {
adapter.processActivity(req, res, async(turnContext) => {
await bot.onTurn(turnContext);
});
});
Create bot class & init handler
@PMc_A
Bot Framework Emulator
@PMc_A
Conversational & User State
@PMc_A
const greetingIntent = require('../greetingIntent');
describe('greetingIntent', () => {
let intent;
beforeEach(() => {
intent = greetingIntent.handleIntent;
});
it('should call sendActivity with the correct greeting message', async () => {
const greetingMessage = 'Hey!';
const mockTurnContext = { sendActivity: jest.fn() };
await intent(mockTurnContext);
expect(mockTurnContext.sendActivity).toHaveBeenCalledWith(greetingMessage);
});
});
Simple Greeting intent test
@PMc_A
@PMc_A
Versatile
Loads of Cognitive Services
Integration
Simple deployments
Node!
@PMc_A
pmc-a
@PMc_A
https://github.com/pmc-a/meetup-chatbot
https://dev.botframework.com/
https://github.com/Microsoft/BotBuilder-Samples