Last active
August 12, 2018 12:07
Star
You must be signed in to star a gist
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
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