How to fire POST request using inline editor in dialogflow? - dialogflow-es

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.

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.

Related

Getting the Error: getaddrinfo ENOTFOUND api.twitter.com api.twitter.com:443 using Node js for twitter posting

const Twitter = require('twitter');
const client = new Twitter({
consumer_key: 'XXXX',
consumer_secret: 'XXXX',
access_token_key: 'XXXX',
access_token_secret: 'XXXX'
});
client.post('statuses/update', {status: 'Posting via the Node is awesome!'}, function(
error,
tweet,
response
) {
if (error) throw error;
// console.log(tweet); // Tweet body.
// console.log(response); // Raw response object.
});
Please Find Below the error:
if (error) throw error;
^
Error: getaddrinfo ENOTFOUND api.twitter.com api.twitter.com:443
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:56:26)
Note : I was trying to hit the twitter api using the firewall application proxy. Actually by default api.twitter.com was blocked by firewall but I requested from env team to add the api.twitter.com in proxy application Link list and they added. Still I am getting the below error any idea how i can check this what is happening and how to solve this.

Can't make a POST request on Azure - EACCES

I have a Node application hosted in Azure as a Web App Bot. When I try to make a POST request with axios from that application, it gives me the following error:
{ Error: connect EACCES 172.30..etc etc
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1113:14)
errno: 'EACCES',
code: 'EACCES',
syscall: 'connect',
address: '172.30..etc,etc',
port: 443,
config:
...
Locally, testing with Bot Framework Emulator it works like a charm.
Request:
let reqConfig = {
headers: {
"Authorization": '123etc etc',
"Content-Type": "application/json"
}
}
axios.post("https://_______", body, reqConfig).then(r => {
console.log(r);
}).catch(e => {
console.log('ERR: ', e);
})

getaddrinfo EAI_AGAIN account-d.docusign.com account-d.docusign.com:443

I am using superagent to hit the docusign API with code received on the response of concent
const respo = await superagent
.post('https://account-d.docusign.com/oauth/token')
.set('Authorization', `${auth}`)
.send({
grant_type: 'authorization_code',
code: '.........'
})
err : { Error: getaddrinfo EAI_AGAIN account-d.docusign.com account-d.docusign.com:443
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:56:26)
errno: 'EAI_AGAIN',
code: 'EAI_AGAIN',
syscall: 'getaddrinfo',
hostname: 'account-d.docusign.com',
host: 'account-d.docusign.com',
port: 443,
response: undefined }
Based on Error: getaddrinfo EAI_AGAIN
"EAI_AGAIN is a DNS lookup timed out error, means it is a network connectivity error or proxy related error."
You may want to check if you have a proxy/firewall or other issues on the box making the API calls. This is a networking issue you need to fix that has nothing to do with DocuSign directly.
Thank you for the suggestion. But it was because I was not sending proper authentication.
I did use curl though for this :
curl
.setHeaders([
`Authorization: Basic ${auth}`,
"Content-Type: application/x-www-form-urlencoded"
])
.setBody({
grant_type: "authorization_code",
code: code
})
.post("https://account-d.docusign.com/oauth/token")
.then(({ statusCode, body, headers }) => {})
.catch(e => {});

Problem with Facebook Graph API in Node.js application

I've created the node.js application which is connected with Facebook Graph API. The problem is that when I am using request to get the data from the URL, sometimes I am not receiving the data but this error message:
{
Error: connect ETIMEDOUT 31.13.81.9:443
at Object._errnoException (util.js:992:11)
at _exceptionWithHostPort (util.js:1014:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1186:14)
code: 'ETIMEDOUT',
errno: 'ETIMEDOUT',
syscall: 'connect',
address: '31.13.81.9',
port: 443
}
When I paste the URL to the browser I am receiving the data from API without any problem.
The request which gets the Facebook API data
request({url:`https://graph.facebook.com/v3.2/me?fields=posts%7Bcomments%7Blike_count%7D%2Cshares%2Ccreated_time%2Csource%2Clikes.summary(true)%7D%2Cfan_count&period=day&since=${selectedDateFrom}&until=${selectedDateTo}&access_token=${accessToken}`,
json: true
}, (err, response, body) => {
if (err) {
console.log(err)
} else {console.log(body);}
I wonder why the problem is happening in my application, and why in the browser everything is fine?

HTTP 400: Bad Request error in ADFS HTTPS Request

I am writing a Node.js app and am trying to integrate an ADFS server to get authentication. For that, I am using wstrust-client, and using the ADFS Server URL as my endpoint. My code so far is:
app.get('/login', function(req, res) {
trustClient.requestSecurityToken({
scope: 'https://mycompany.com',
username: "username",
password: "password",
endpoint: 'https://[adfs server]/adfs/services/trust/13/usernamemixed'
}, function (rstr) {
// Access the token
var rawToken = rstr.token;
console.log('raw: ' + rawToken);
}, function(error) {
console.log(error)
});
});
I am requesting https through wstrust-client
My code in wstrustclient.js so far is:
var req = https.request(post_options, function(res) {
res.setEncoding('utf8');
res.on('data', function(data) {
console.log("Entered res")
var rstr = {
token: parseRstr(data),
response: res,
};
callback(rstr);
});
});
req.write(message);
req.end();
req.on('error', function (e) {
console.log("******************************");
console.log(e);
console.log("******************************");
However, it is throwing this error:
******************************
{ [Error: UNABLE_TO_VERIFY_LEAF_SIGNATURE]
stack: 'Error: UNABLE_TO_VERIFY_LEAF_SIGNATURE\n
at SecurePair.<anonymous> (tls.js:1253:32)\n
at SecurePair.EventEmitter.emit (events.js:91:17)\n
at SecurePair.maybeInitFinished (tls.js:865:10)\n
at CleartextStream.read [as _read] (tls.js:416:15)\n
at CleartextStream.Readable.read (_stream_readable.js:231:10)\n
at EncryptedStream.write [as _write] (tls.js:329:25)\n
at EncryptedStream.Writable.write (_stream_writable.js:176:8)\n
at write (_stream_readable.js:496:24)\n
at flow (_stream_readable.js:506:7)\n
at Socket.pipeOnReadable (_stream_readable.js:538:5)' }
******************************
******************************
{ [Error: read ECONNRESET]
stack: 'Error: read ECONNRESET\n
at errnoException (net.js:846:11)\n
at TCP.onread (net.js:508:19)',
code: 'ECONNRESET',
errno: 'ECONNRESET',
syscall: 'read' }
******************************
When I browse the same endpoint URL in a browser, it throws HTTP 400: Bad Request
I know that it's an SSL type error, and that it's from the server-side. However, I don't know why it's throwing the error and what might be wrong server-side. What do I need to change?
As per the OpenSSL manual here:
21 X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE: unable to verify the
first certificate no signatures could be verified because the chain
contains only one certificate and it is not self signed.
With that in mind, it seems that you may need to sign your certificate.

Resources