Instantly share code, notes, and snippets.

Embed
What would you like to do?
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]));
}
});
function buildFactResponse(factToQuery) {
return new Promise((resolve, reject) => {
if (factToQuery.toString().trim() === 'random') {
factToQuery = selectRandomFact();
}
const query = datastore
.createQuery('AzureFact')
.filter('__key__', '=', datastore.key(['AzureFact', factToQuery]));
datastore
.runQuery(query)
.then(results => {
resolve(results[0][0]);
})
.catch(err => {
console.log(`Error: ${err}`);
reject(`Sorry, I don't know the fact, ${factToQuery}.`);
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment