This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
exports.handler = (event, context, callback) => { | |
// when intent get fulfilled, inform lex to complete the state | |
let response = {sessionAttributes: event.sessionAttributes, | |
dialogAction: { | |
type: "Close", | |
fulfillmentState: "Fulfilled", | |
message: { | |
contentType: "PlainText", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
exports.handler = (event, context, callback) => { | |
const sessionAttributes = event.sessionAttributes; | |
const slots = event.currentIntent.slots; | |
const bookName = slots.bookName; | |
// predefined list of available books | |
const validBooks = ['harry potter', 'twilight', 'wings of fire']; | |
// negative check: if valid slot value is not obtained, inform lex that user is expected |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async fooBarBaz(arg) { | |
try { | |
const fooResponse = await foo(arg+1); | |
const barResponse = await bar(arg+2); | |
const bazResponse = await baz(arg+3); | |
return bazResponse; | |
} catch (error) { | |
return Error(error); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function asyncFun() { | |
try { | |
const result = await promise; | |
} catch(error) { | |
console.log(error); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function foo(arg, callback) { | |
if (arg < 0) { | |
callback('error'); | |
return; | |
} | |
callback(null, arg+1); | |
} | |
function bar(arg, callback) { | |
if (arg < 0) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var foo = function (arg) { | |
return new Promise((resolve, reject) => { | |
resolve(arg+1); | |
}); | |
} | |
var bar = function (arg) { | |
return new Promise((resolve, reject) => { | |
resolve(arg+2); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fileReadPromise = fs.readFile(filePath); | |
fileReadPromise.then(console.log, console.error) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fs.readFile(filePath, (err, result) => { | |
if (err) { console.log(err); } | |
console.log(data); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
foo(arg, (err, val) => { | |
if (err) { | |
console.log(err); | |
} else { | |
val += 1; | |
bar(val, (err1, val1) => { | |
if (err) { | |
console.log(err1); | |
} else { | |
val1 += 2; |