Slide 18
Slide 18 text
Create WebHook Fulfillment
let request = require('request');
let moment = require(‘moment');
const QUERY_CONTENT_ACTION = 'query_content';
const ARGUMENT_PROGRAM_NAME = 'program_name';
app.post('/', function (req, res) {
const assistant = new Assistant({request: req, response: res});
function getNextAiringOfProgram(assistant){
let showName = assistant.getArgument(ARGUMENT_PROGRAM_NAME);
request(‘https://gook.com;searchTerm='+ showName, function (error, response,
body) {
})
}
if (!error && response.statusCode == 200) {
var event = JSON.parse(body);
var dateTimeFormatted = new moment(event.startDateTime);
assistant.tell(event.title + ' will air on '
+ dateTimeFormatted.format('dddd Do [at] hh:mm a'));
} else {
assistant.tell('I\'m sorry, there was an error trying to process your
request.’);
let actionMap = new Map();
actionMap.set(QUERY_CONTENT_ACTION, getNextAiringOfProgram);
assistant.handleRequest(actionMap);