Search code examples
dialogflow-esactions-on-googledialogflow-es-fulfillmentfulfillment

How to fire POST request using inline editor in dialogflow?


Code:

var rp = require('request-promise');
var options = {
                method: 'POST',
                uri: 'http://c663fe13.ngrok.io/ap/lighton',
                body: {"color": 'white'},
                json: true // Automatically stringifies the body to JSON
            };

            rp(options)
                .then(function (parsedBody) {
                    // POST succeeded...+
                    console.log("parsedBody", parsedBody);
                })
                .catch(function (err) {
                    // POST failed...
                    console.log("err", err);
                });

but this gives me the following error:

{ RequestError: Error: getaddrinfo EAI_AGAIN c663fe13.ngrok.io:80 at new RequestError (/srv/node_modules/request-promise-core/lib/errors.js:14:15) at Request.plumbing.callback (/srv/node_modules/request-promise-core/lib/plumbing.js:87:29) at Request.RP$callback [as _callback] (/srv/node_modules/request-promise-core/lib/plumbing.js:46:31)

. . .

name: 'RequestError', message: 'Error: getaddrinfo EAI_AGAIN c663fe13.ngrok.io:80',
cause: { Error: getaddrinfo EAI_AGAIN c663fe13.ngrok.io:80 at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:67:26) errno: 'EAI_AGAIN', code: 'EAI_AGAIN', syscall: 'getaddrinfo', hostname: 'c663fe13.ngrok.io', host: 'c663fe13.ngrok.io', port: 80 },

I trie to call that API with postman and it's working fine.


Solution

  • If you are using a free account you will not be able to hit any 3rd party services from Firebase cloud functions. It would be better if you write down your own webhook code and using fulfillment integrate that webhook with your Dialogflow agent if you are going to use the free account.

    UPDATE Check out the code snippets I have shared here. You can use that to integrate ExpressJS and then add your POST code and host it locally. Expose the local server using ngrok and then put that URL in fulfillment.