Created
May 11, 2020 15:39
-
-
Save saurav28/9f09a0e605b3369e15d5c18edc4316a0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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