Facebook Messenger

First, install botmeter-logger:

npm install --save botmeter-logger

Log the message inside the POST request callback made when the bot replies (the user message and bot response(s) must be logged in the same document) (see right pane).

See our sample bot

const BotmeterLogger = require('botmeter-logger');
const request = require('request');

const messengerLogger = new BotmeterLogger({
  appId: '<APP_ID>',
  appKey: '<APP_KEY>',
}).messenger;

// User message
const requestBody = 'Hello';

// Bot response
const responseJson = {
  recipient: {
    id: senderId,
  },
  message: {
    text: 'Hello World',
  },
};

// POST bot reponse to facebook
request(
  {
    uri: 'https://graph.facebook.com/v2.6/me/messages',
    qs: { access_token: process.env.PAGE_ACCESS_TOKEN },
    method: 'POST',
    json: responseJson,
  },
  () => {
    // The user message and bot response(s) must be logged in the same document
    messengerLogger.logDocument(requestBody, responseJson, (e, r) => {
      if (e) {
        console.log('Botmeter error: ', e);
      } else {
        console.log('Botmeter logging: ', r);
      }
    });
  }
);