Skip to content

Instantly share code, notes, and snippets.

@garystafford
Last active August 12, 2018 12:23
Show Gist options
  • Save garystafford/fd5f8e14ba669669443d418a49155289 to your computer and use it in GitHub Desktop.
Save garystafford/fd5f8e14ba669669443d418a49155289 to your computer and use it in GitHub Desktop.
/* INTENT HANDLERS */
app.intent('Welcome Intent', conv => {
const WELCOME_TEXT_SHORT = 'What would you like to know about Microsoft Azure?';
const WELCOME_TEXT_LONG = `What would you like to know about Microsoft Azure? ` +
`You can say things like: \n` +
` _'tell me about Azure certifications'_ \n` +
` _'when was Azure released'_ \n` +
` _'give me a random fact'_`;
const WELCOME_IMAGE = 'image-16.png';
conv.ask(new SimpleResponse({
speech: WELCOME_TEXT_SHORT,
text: WELCOME_TEXT_SHORT,
}));
if (conv.hasScreen) {
conv.ask(new BasicCard({
text: WELCOME_TEXT_LONG,
title: 'Azure Tech Facts',
image: new Image({
url: `${IMAGE_BUCKET}/${WELCOME_IMAGE}`,
alt: 'Azure Tech Facts',
}),
display: 'WHITE',
}));
conv.ask(new Suggestions([SUGGESTION_1, SUGGESTION_2, SUGGESTION_3]));
}
});
app.intent('Fallback Intent', conv => {
const FACTS_LIST = "Certifications, Cognitive Services, Competition, Compliance, First Offering, Functions, " +
"Geographies, Global Infrastructure, Platforms, Categories, Products, Regions, and Release Date";
const WELCOME_TEXT_SHORT = 'Need a little help?';
const WELCOME_TEXT_LONG = `Current facts include: ${FACTS_LIST}.`;
const WELCOME_IMAGE = 'image-15.png';
conv.ask(new SimpleResponse({
speech: WELCOME_TEXT_LONG,
text: WELCOME_TEXT_SHORT,
}));
if (conv.hasScreen) {
conv.ask(new BasicCard({
text: WELCOME_TEXT_LONG,
title: 'Azure Tech Facts Help',
image: new Image({
url: `${IMAGE_BUCKET}/${WELCOME_IMAGE}`,
alt: 'Azure Tech Facts',
}),
display: 'WHITE',
}));
conv.ask(new Suggestions([SUGGESTION_1, SUGGESTION_2, SUGGESTION_3]));
}
});
app.intent('Azure Facts Intent', async (conv, {facts}) => {
let factToQuery = facts.toString();
let fact = await buildFactResponse(factToQuery);
const AZURE_TEXT_SHORT = `Sure, here's a fact about ${fact.title}`;
conv.ask(new SimpleResponse({
speech: fact.response,
text: AZURE_TEXT_SHORT,
}));
if (conv.hasScreen) {
conv.ask(new BasicCard({
text: fact.response,
title: fact.title,
image: new Image({
url: `${IMAGE_BUCKET}/${fact.image}`,
alt: fact.title,
}),
display: 'WHITE',
}));
conv.ask(new Suggestions([SUGGESTION_1, SUGGESTION_2, SUGGESTION_3]));
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment