25

I am trying to create a Kik Messenger bot according to their API using Firebase Cloud Functions. I am using Blaze Plan. I am trying to reply to a message that my bot received. I can receive messages on my API but when I try to reply to them I get an error. An error is not from the request callback. I see the error on Firebase Console.

Error: connect ECONNREFUSED 72.14.246.44:443

at Object.exports._errnoException (util.js:1018:11)
at exports._exceptionWithHostPort (util.js:1041:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1086:14)
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect',
address: '72.14.246.44',
port: 443

Requests to the Kik Messenger API works on local and remote node/express app. I tried to use kik-node on Cloud Functions but it gave the same result. What I have discovered so far is that https://auth.kik.com resolves to Amazon and https://api.kik.com resolves to Google Hosting. I think they are also using Firebase Cloud Functions for their API. Can it be possible that they are blocked inbound requests? Here is the sample code of what I tried.

exports.messagepost = functions.https.onRequest((req, res) => {
  // Gives the error below
  // {
  //  Error: connect ECONNREFUSED 72.14.246.44:443
  //   at Object.exports._errnoException (util.js:1018:11)
  //   at exports._exceptionWithHostPort (util.js:1041:20)
  //   at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1086:14)
  //   code: 'ECONNREFUSED',
  //   errno: 'ECONNREFUSED',
  //   syscall: 'connect',
  //   address: '72.14.246.44',
  //   port: 443
  // }
  request.post({
    uri: 'https://api.kik.com/v1/message',
    body: JSON.stringify({
      foo: 'bar'
    }),
    json: true,
    auth:{
      user:'{API_USER}',
      pass:'{API_KEY}'
    },
    headers: {
      'Content-Type'   : 'application/json'
    }
  }, (error, response) => {
    if (error) console.error(error);
    else console.log('Response: ', response.headers);
    res.status(200).end('OK');
  });
});

exports.messageget = functions.https.onRequest((req, res) => {
  // Gives the error below
  // {
  //  Error: connect ECONNREFUSED 72.14.246.44:443
  //   at Object.exports._errnoException (util.js:1018:11)
  //   at exports._exceptionWithHostPort (util.js:1041:20)
  //   at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1086:14)
  //   code: 'ECONNREFUSED',
  //   errno: 'ECONNREFUSED',
  //   syscall: 'connect',
  //   address: '72.14.246.44',
  //   port: 443
  // }
  request.get({
    uri: 'https://api.kik.com/v1/message',
    auth:{
      user:'{API_USER}',
      pass:'{API_KEY}'
    }
  }, (error, response) => {
    if (error) console.error(error);
    else console.log('Response: ', response.headers);
    res.status(200).end('OK');
  });
});

exports.verificationget = functions.https.onRequest((req, res) => {
  // Runs with no errors
  request.get({
    uri: 'https://auth.kik.com/verification/v1/check',
    qs: {
      u: 'username',
      d: 'hostname',
      debug: true
    },
    body: JSON.stringify({ data: 'debugsigneddata' }),
    headers: {
      'Content-Type'   : 'application/json' ,
      'Content-Length' : JSON.stringify({ data: 'debugsigneddata' }).length
    },
    auth:{
      user:'{API_USER}',
      pass:'{API_KEY}'
    }
  }, (error, response) => {
    if (error) console.error(error);
    else console.log('Response: ', response.headers);
    res.status(200).end('OK');
  });
});

exports.verificationpost = functions.https.onRequest((req, res) => {
  // Runs with no errors
  request.post({
    uri: 'https://auth.kik.com/verification/v1/check',
    qs: {
      u: 'username',
      d: 'hostname',
      debug: true
    },
    body: JSON.stringify({ data: 'debugsigneddata' }),
    headers: {
      'Content-Type'   : 'application/json' ,
      'Content-Length' : JSON.stringify({ data: 'debugsigneddata' }).length
    },
    auth:{
      user:'{API_USER}',
      pass:'{API_KEY}'
    }
  }, (error, response) => {
    if (error) console.error(error);
    else console.log('Response: ', response.headers);
    res.status(200).end('OK');
  });
});
p u
  • 1,395
  • 1
  • 17
  • 30
bennygenel
  • 23,896
  • 6
  • 65
  • 78
  • Do other outbound (non-Google) API calls work? They should be OK on the blaze plan, but possibly worth a sanity check. – Ian Barber Sep 07 '17 at 16:04
  • Yes they are working. As you can see in code there is 2 different domains and as I explained they both look to different IPs. Other than that I also tried different API calls too and they all worked. – bennygenel Sep 07 '17 at 16:06
  • I am hitting this same issue when trying to use a cloud function to create an access token in google apis. Could it be possible that using port :80 instead of port :443 is causing the error? – William Chou Mar 11 '19 at 16:06

1 Answers1

0

I ran into a similar issue while implementing an OAuth2 token exchange using cloud functions instead of running a dedicated server.

This might not help the OP but to fix this error in my case, I had to add the https:// protocol to my post URL as it was missing.

If others run into this issue it might be worth checking your POST url is written correctly.

William Chou
  • 752
  • 5
  • 16