Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,
I'm building a chatbot that retrieves a youtube link based on what the user has asked.
I'm using Dialogflow for the bot and using nodejs for the coding.
Right now, everything works perfectly but my problem is retrieving the link from the API response.
using console.dir(results), shows the following:
This is how the response looks like:
[ { id: 'gWNUg_v25dw',
    link: 'https://www.youtube.com/watch?v=gWNUg_v25dw',
    kind: 'youtube#video',
    publishedAt: '2017-08-24T14:00:11.000Z',
    channelId: 'UCDZ56yQ05d_ikcwcTG9bAiA',
    channelTitle: 'Code to Create',
    title: 'How to make a Chatbot with Dialogflow - API.ai',
    description: 'In this video, Google Developer Expert, Faisal Abid will show us how to create a chatbot with Google\'s latest API.ai API.ai can be integrated with multiple chat ...',
    thumbnails: { default: [Object], medium: [Object], high: [Object] } } ]


What I have tried:

I have tried using results.link to retrieve the link but Im getting undefined, so my question is how to retrieve the link from the response block?
search(txt1, opts, function(err, results) {
  //var data1 = JSON.parse(results);
  //srchRes = data1.link;
  if(err) return console.log(err);
 
  
  console.dir(results);
});


uncommenting the 2 lines above and console.dir(srchRes) returns this error:
SyntaxError: Unexpected token u in JSON at position 0
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900