AnishKM
AnishKM

Reputation: 1

Not able to call external api's from google dialogflow web hook?

I tried calling an external api from inline editor of google dialogue flow. But not working. i am using the inline editor. Error i can see in the log is 'Error: Cannot find module 'request-promise-native'. Is there anywhere else i need to add this reference? package.JSON? if so how?

function AccountNumberHandler(agent) {
    const AccountNumber = agent.parameters.AccountNumber;

    if (AccountNumber) {
      //console.log(AccountNumber);
      const request = require('request-promise-native');
      agent.add('Unable to get result');
      const url = "xxxx";
      const data = "";
     return request.post(url, data)
          .then(jsonBody => {
              var body = JSON.parse(jsonBody);
              agent.add(body);
              return Promise.resolve(agent);
          })
          .catch(err => {
              console.error('Problem making network call', err);
              agent.add('Unable to get result');
              return Promise.resolve(agent);
          });      

        //agent.add(`Wow! I didn't know you knew ${AccountNumber}`);
    } 

Upvotes: 0

Views: 2167

Answers (2)

Anshul
Anshul

Reputation: 117

What @Prisoner answered above is correct, however, you may still see some problems while making calls to external APIs using inline editor. That's because inline editor uses firebase which blocks calls to external APIs in their free plan.

So you need to upgrade to their blaze plan which allows calls to external APIs. However, you will need to enter your card details so just keep this in mind.

I have created a video tutorial on how to connect your dialogflow agent to external APIs. Please have a look at this video. https://www.youtube.com/watch?v=n4IPOeFCDxI

Hope this helps.

Upvotes: 1

Prisoner
Prisoner

Reputation: 50701

Yes, you need to add it to your package.json file.

To do this using the Dialogflow inline editor, you'll see two filenames at the top of the editor: index.js and package.json. Just click on the "package.json" one and edit it to add what you need to the "dependencies" section.

enter image description here

Upvotes: 0

Related Questions