I'm trying to fetch the youtube video id from the complete url. When i try the following function in codepen.io or in my browser, it works perfectly.
But when i use the same in dialogflow fulfilment it shows the error that match() is not defined where actually it's an inbuilt function.
(Took this solution from here : https://stackoverflow.com/a/8260383/12029508)
Code:
var yt_link = 'https://www.youtube.com/watch?v=GtQstf_sGr4';
function youtube_parser(yt_link) {
var regExp = `/^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#&?]*).*/`;
var match = yt_link.match(regExp);
return (match && match[7].length == 11) ? match[7] : false;
}
var videoID = youtube_parser(yt_link);
console.log(videoID);
Error:
dialogflowFirebaseFulfillment
TypeError: Cannot read property 'match' of undefined at youtube_parser (/srv/index.js:304:27) at
downloadYoutube (/srv/index.js:307:18) at
WebhookClient.handleRequest (/srv/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:303:44) at
exports.dialogflowFirebaseFulfillment.functions.https.onRequest (/srv/index.js:498:10) at cloudFunction
(/srv/node_modules/firebase-functions/lib/providers/https.js:57:9) at /worker/worker.js:783:7 at
/worker/worker.js:766:11 at _combinedTickCallback (internal/process/next_tick.js:132:7) at
process._tickDomainCallback (internal/process/next_tick.js:219:9)