Dialogflow Tutorials: Integrate Your Dialogflow Agent with External APIs

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Laughter] [Music] hello friends in this video tutorial I am going to show you how to integrate your dialogue flow with external API this will be a series of video tutorials on dialogue flow tips and tricks so please like and share our video and also please subscribe to our channel hello friends in this video tutorial I am going to show you how to create a chat pod using dialogue flow which can connect to external eBay's external eps could be anything like search Hotel API weather API or flight search API or any external service so if you want to build a chat bot which can tell you the current weather or which can book a hotel or which can search flight then you need to connect your chat bot with the external API s so today we are going to see how to create a dialogue flow chat bot which can be connected to the external api's so let's go to the console and let's create our new agent for the external API demo so let us call it external so while it's creating the agent let's see which API we are going to use so we are going to use this datum use a PI it is a free API which provides words and similar words so for example words with meaning similar to ringing in the ears or words that sound like elephant or words that rhyme with forgetful so let's use this API so if we click on this you can see that it is showing all the words which are rhyming with this word forgetful so let's say we change this to music so this API will return all the words which rhymes with this word music music music let's say if we do something like teacher so this API is returning all the words like feature VHL feature which are rhyming with this word so let's use this API and see how can we connect this API with our chat board all right so our agent is created you have whatever welcome intent and the fallback intent if you don't know how how these intents works and if you want to know more about basics of dialogue flow then you can see my other videos so for this now I am going to create a new intent let's call it rhyming word so we are going to use this API words that rhyme with a given word so let's call it rhyming word and we need to provide some training phrase over here so let's give some training phrases such as words that rhyme with music and let's create this music of parameter give the entity SS cottony and parameter name is word okay similarly rhyming word for teacher the teacher is our parameter so we can try it now if we say rhyming word for book it should be booked as a parameter and then if you see yeah we got the value book parameter word so we can extract all the parameters from the given sentence now we can extract the parameter value but now we need to pass this value to the API here and get the response back and then show it to the user so to do that we need to enable the fulfillment so you can scroll down and click on enable fulfillment this is very important otherwise this intent won't go to the external service so make sure you enable this we have a book call for this intent and save it now after that go to the fulfillment section and enable this in line editor so there's some default code there which is the very useful just remove this commented code you don't need this okay leave everything as it is and here just remove one of them and uncomment the other one so intent map set and then here we need to give the name of the intent so whatever name you have given I think we have given rhyming word and here you can give any name so let us call it okay and this right now is giving an error that this handler is not defined so all you need to do is just define this handler like this and in the bracket just say agent as a parameter so now this is fine okay cool so now whenever this intent is called this function will be executed so we can try that if we say agent got add and called and click on the deploy button so when we say rhyming word for anything this function should be called and then we should see a message saying intent called okay the code has been deployed successfully now let's try this so rhyming word for book and you can see this the default response intent cord that means this function is working fine and it is responding with whatever message we clear where now we need to extract this parameter book in our code so let's try to do that create our variable called word and its value value will be aging dot parameters dot word so this word so H n dot parameters that word will extract the parameter value and it will be stored in this word variable and then we can just print that value so let's see if we are getting the value back in the core in the default response we should see the parameter here okay let's try that so rhyming word for book okay we got the word book here as a response let's try something else rhyming word for sure because the word teacher here so that means our code is working fine we got the parameter as well now all we need to do is pass this parameter in this API get the response back and frame that response in the default response so how to make the API call and how to get the response back so for that we need to use a node.js library called Axios so you can just do a Google search Axios NPM okay and yeah that's the library that we are going to use so to use this library you need to go to package dot jason and in the dependency section just right exhales like this and the version number so you can copy the version number from this NPM J s.com website and paste the version here all right and deploy so this will install the Axios package in our code so that we can use it here all right so we have caught the exes packet in store not just to clear the excuse variable here Const X Y is equal to require X Y so this X cos variable will be used to make the call to the API now here we need to write x ce o--'s dot ket and then in this get function takes the parameter is the URL that we want to call Axios dog cat will make a get request or basically it will get or it will call the URL and it will return the response so what is the URL the URL is this so x yours dot get this URL now we don't want to hard-code this value so instead of this we use templating skin cosmetics and ask the word variable word parameter here so that means whatever word is coming from the text that word will be passed to the URL and then Axios will make a call and to get the response we do something like this this is called promise so when the result is risen and we will receive the result then execute this function so let's define our function this is called es esta es six style function and then this is end result will be received after we get the result from Axios and [Music] let's try to just console dot log the result to see if we are actually getting the result or not okay so what we are doing here is making a call to exia library and x0 start get this URL and then when the result comes just console dot clock the result let's see if that works so click on apply all right so this is deployed successfully you can click on this link here which will open the firebase console so if you see any kind of problem or errors make sure you are logged in with the correct account so here we can see all the locks right now let's try to invoke this intent so if you say rhyming word for teacher it says intent called teacher which is this one let's see what we get in the locks so you can see there is some error here get address info Enoch phone and here it says billing account not configured sternal Network is not accessible so and you can see the same error here as well basically our firebase which we used to write the code does not allow access to external API is in there free free plan so we need to upgrade to the paid plan and yes so you need to enter your card details but they won't charge you anything for for up to million queries or something like that so you don't need to worry about paying something to them but yes you need to add your credit card details so you can just click on this upgrade button here make sure you are logged in with the correct account and you can see by default it is subscribed to free plan but if you want access external API then you need to select this blaze plan so you can just click on select plan now you for selecting this plan you need to create something called billing account I have already created this billing account but if you don't have billing account then all you need to do is go to console dot cloud.google.com slash billing [Music] and once you are here you can simply click on this button and follow those steps to create a new billing account it will asks for your country currency your payment details car details and then you can create the billing account it won't charge you anything for a reasonable number of usage but yeah you need to provide those details so I have already created the billing account so I am going to close this and just click on purchase it is upgraded to the blaze plan now I can try the same thing again and if I check the logs cool so you can see we got the response back from the service you can see the URL API tour determines calm and parameter passed here is teacher which we mentioned here cool so that means our API is working fine we are getting the response back now the question is how do we display the response here in the default response section so if you see the response is actually in the data so what we need to do is print result or data so let's try that and see what data we get back ok timing word for teacher teacher is passed here check in the locks great for logs to appear it take few seconds for log to appear cool and now you can see we got the response back and these are the word which rhymes similar to the teacher so we can say this is an array of objects right this is the first object this is the second object and it is an array of objects so we can look through this array of objects and then we can use the words to display the response so in the code back here once we get the result that we can write something like this the result or data dot map dot map is a function which loops so elements of an array so we 4/4 so this area has got objects word objects so let's call it an order object so each word what object will have properties like word score num slippers so we can just do something like this word object dot word so that will print this word this word this word and we will extract the word from the word object so let's quickly try this as well so say again same thing rhyming word for teacher go back to the logs and let's see what we get here now cool so you can see we have got the words teacher creature all the rhyming words so that looks good now all we need to do is use these words in the response so instead of just doing the console.log just remove the console box and instead of doing console dog we can do aging dotted agent dot ads basically shows as a response so you can just write a gen dot ad order just awkward so that will display the response here and I bought this and we can say something like here are the here are the priming words or whatever user says make sure you type it after the word variable so that what variable is available here so here are the world here are the rhyming words for given word whatever user types and then make the call to Axios just make sure to type return before egg zeros this is important so don't forget this and Ageing dot edward object let's deploy this and see if it works okay so deployment is successful now you can try it here so rhyming word for teacher and there you go you can see here are the rhyming words for teacher feature creator creature rhyming word for yeah you can see it here are the rhyming word for honey money honey and so on so it's coming from the API so we have successfully connected the dialogue flow edge into the external guy and we managed to read the data from the external API and show it in our chat bot so hope you like this video thank you
Info
Channel: AxleWeb Technologies
Views: 48,511
Rating: 4.8996415 out of 5
Keywords: Dialogflow, Connect with API, Chatbot, Messenger, Dialogflow with api, Chatbot with api
Id: n4IPOeFCDxI
Channel Id: undefined
Length: 22min 32sec (1352 seconds)
Published: Sat Mar 30 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.