Skip to content

Instantly share code, notes, and snippets.

@surajsau
Created January 4, 2019 11:32
Show Gist options
  • Save surajsau/02ef48b3535a956b9aa3c349e9b34b2f to your computer and use it in GitHub Desktop.
Save surajsau/02ef48b3535a956b9aa3c349e9b34b2f to your computer and use it in GitHub Desktop.
Cases Request function (DailyRounds Assistant)
const casesRequest = (rounds, skipCount, conv) => {
const timestamp = new Date().getTime();
const options = {
method: 'GET',
url: `http://keanuisimmortal.com/v1/talk?topics=${rounds.id}&limit=${skipCount}`,
headers: {
'Content-Type': 'application/json',
...
}
};
return request(options)
.then((body) => {
const responseJson = JSON.parse(body);
const carouselItems = new Array();
for(var i=0; i<responseJson.data.data.length; i++) {
const caseObj = responseJson.data.data[i];
if(caseObj.talk_type !== "type10") {
carouselItems.push(talkToCarouselItem(caseObj));
}
}
if(rounds === rounds_map['best']) {
conv.ask(`Here are the top ${skipCount} for today`);
} else {
conv.ask(`Here are the ${skipCount} latest from ${rounds.title} for today`);
}
return conv.ask(new BrowseCarousel({items:carouselItems}));
})
.catch((error) => {
console.error(error);
conv.close(`Sorry but ${error}`);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment