Error Trying To Send Messages Using Facebook Messenger Platform From A Firebase Function

I'm trying to send messages using the Messenger Platform from my firebase function. Reference:

Anyway, the part of my function which handles this is the following:

const functions = require('firebase-functions');
const admin = require('firebase-admin');
const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
const app = express();
app.use(bodyParser.urlencoded({ extended: true }))
app.use(cors({ origin: true }));'/send-message', (req, res) => {
    var accessToken = <PAGE_ACCESS_TOKEN>; // Getting it from environment variable
    var url = ''+accessToken;, {
        messaging_type: 'text',
        recipient: {
        message: {
            text: 'hello, world!'
    .then(function (response) {
    .catch(function (error) {

exports.main = functions.https.onRequest(app);

The error thats being printed in my logs is the following:

 Error: getaddrinfo EAI_AGAIN
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:67:26)
  errno: 'EAI_AGAIN',
  code: 'EAI_AGAIN',
  syscall: 'getaddrinfo',
  hostname: '',
  host: '',
  port: 443,
   { adapter: [Function: httpAdapter],
     transformRequest: { '0': [Function: transformRequest] },
     transformResponse: { '0': [Function: transformResponse] },
     timeout: 0,
     xsrfCookieName: 'XSRF-TOKEN',
     xsrfHeaderName: 'X-XSRF-TOKEN',
     maxContentLength: -1,
     validateStatus: [Function: validateStatus],
      { Accept: 'application/json, text/plain, */*',
        'Content-Type': 'application/json;charset=utf-8',
        'User-Agent': 'axios/0.18.0',
        'Content-Length': 98 },
     method: 'post',
     url: '<PAGE_ACCESS_TOKEN>',
     data: '{"messaging_type":"text","recipient":{"id":"2251519781590874"},"message":{"text":"hello, world!"}}' },
   Writable {
      WritableState {
        objectMode: false,
        highWaterMark: 16384,
        finalCalled: false,
        needDrain: false,
        ending: false,
        ended: false,
        finished: false,
        destroyed: false,
        decodeStrings: true,
        defaultEncoding: 'utf8',
        length: 0,
        writing: false,
        corked: 0,
        sync: true,
        bufferProcessing: false,
        onwrite: [Function: bound onwrite],
        writecb: null,
        writelen: 0,
        bufferedRequest: null,
        lastBufferedRequest: null,
        pendingcb: 0,
        prefinished: false,
        errorEmitted: false,
        bufferedRequestCount: 0,
        corkedRequestsFree: [Object] },
     writable: true,
      Domain {
        domain: null,
        _events: [Object],
        _eventsCount: 1,
        _maxListeners: undefined,
        members: [] },
      { response: [Function: handleResponse],
        error: [Function: handleRequestError] },
     _eventsCount: 2,
     _maxListeners: undefined,
      { maxRedirects: 21,
        maxBodyLength: 10485760,
        protocol: 'https:',
        path: '/v3.3/me/messages?access_token=<PAGE_ACCESS_TOKEN>',
        method: 'post',
        headers: [Object],
        agent: undefined,
        auth: undefined,
        hostname: '',
        port: null,
        nativeProtocols: [Object],
        pathname: '/v3.3/me/messages',
        search: '?access_token=<PAGE_ACCESS_TOKEN>' },
     _ended: false,
     _ending: true,
     _redirectCount: 0,
     _redirects: [],
     _requestBodyLength: 98,
     _requestBodyBuffers: [ [Object] ],
     _onNativeResponse: [Function],
      ClientRequest {
        domain: [Object],
        _events: [Object],
        _eventsCount: 6,
        _maxListeners: undefined,
        output: [],
        outputEncodings: [],
        outputCallbacks: [],
        outputSize: 0,
        writable: true,
        _last: true,
        upgrading: false,
        chunkedEncoding: false,
        shouldKeepAlive: false,
        useChunkedEncodingByDefault: true,
        sendDate: false,
        _removedConnection: false,
        _removedContLen: false,
        _removedTE: false,
        _contentLength: null,
        _hasBody: true,
        _trailer: '',
        finished: false,
        _headerSent: true,
        socket: [Object],
        connection: [Object],
        _header: 'POST /v3.3/me/messages?access_token=<PAGE_ACCESS_TOKEN> HTTP/1.1\r\nAccept: application/json, text/plain, */*\r\nContent-Type: application/json;charset=utf-8\r\nUser-Agent: axios/0.18.0\r\nContent-Length: 98\r\nHost:\r\nConnection: close\r\n\r\n',
        _onPendingData: [Function: noopPendingOutput],
        agent: [Object],
        socketPath: undefined,
        timeout: undefined,
        method: 'POST',
        path: '/v3.3/me/messages?access_token=<PAGE_ACCESS_TOKEN>',
        _ended: false,
        res: null,
        aborted: undefined,
        timeoutCb: null,
        upgradeOrConnect: false,
        parser: null,

What exactly is going on? I have never seen an error that looks like this. Any help is greatly appreciated.


  • My page is subscribed to my app.
  • Webhooks have been set up successfully. My app can receive messages.


EAI_AGAIN is caused by a network timeout and not related to the Messenger Platform API. If you are on Free (Spark Plan) tier, you need to upgrade your firebase plan.