Skip to content

Instantly share code, notes, and snippets.

@saurav28
Created May 11, 2020 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saurav28/9f09a0e605b3369e15d5c18edc4316a0 to your computer and use it in GitHub Desktop.
Save saurav28/9f09a0e605b3369e15d5c18edc4316a0 to your computer and use it in GitHub Desktop.
function askMusicPreferences(answer, convo, bot) {
myDialog.ask('What would like to hear?', [
{
pattern: '.*',
handler: async (response, convo, bot, message) => {
try {
var channels = await YoutubeHelper.getChannel(response);
if (channels.length == 0) {
await bot.say('No items found.');
}
else {
for (i = 0; i < channels.length; i++) {
var videoURL = "https://www.youtube.com/watch?v=" + channels[i].id.videoId;
//facebook template formed as per https://developers.facebook.com/docs/messenger-platform/send-messages/template/generic
await bot.say({
channelData: { //need to send attachments with channeldata https://dev4slack.slack.com/archives/C0AV5N8NA/p1563790610005000
attachment: {
"type": "template",
"payload": {
"template_type": "generic",
"elements": [
{
"title": "Youtube Video!",
"image_url": "https://petersfancybrownhats.com/company_image.png",
"subtitle": "Your choice of video",
"default_action": {
"type": "web_url",
"url": videoURL,
"webview_height_ratio": "tall",
},
}
]
}
}
}
});
}
}
} catch (error) {
console.log('error occurred ', error);
}
}
}
], { key: 'name' });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment