message: Properly trigger security session events from facebook workplace
diff: @@ -275,8 +275,17 @@ function Facebookbot(configuration) {
  // we split these up into multiple message objects for ingestion
  if (payload.entry) {
  for (var e = 0; e < payload.entry.length; e++) {
  - for (var m = 0; m < payload.entry[e].messaging.length; m++) {
  - facebook_botkit.ingest(bot, payload.entry[e].messaging[m], res);
  +
  + var payload_entry = '';
  +
  + if (payload.entry[e].changes) {
  + payload_entry = payload.entry[e].changes;
  + } else {
  + payload_entry = payload.entry[e].messaging;
  + }
  +
  + for (var m = 0; m < payload_entry.length; m++) {
  + facebook_botkit.ingest(bot, payload_entry[m], res);
  }
  }
  }
  @@ -287,6 +296,17 @@ function Facebookbot(configuration) {
  // handle normal messages from users (text, stickers, files, etc count!)
  facebook_botkit.middleware.normalize.use(function normalizeMessage(bot, message, next) {
  + // handle normalization for sessions events
  + if (message.field && message.field == 'sessions') {
  + message.user = message.value.actor_id;
  + message.channel = message.value.actor_id;
  +
  + // copy facebook specific features
  + message.page = message.value;
  +
  + // set the event type 'log-in' or 'log-out'
  + message.type = message.value.event.toLowerCase();
  + } else {
  // capture the user ID
  message.user = message.sender.id;
  @@ -295,8 +315,9 @@ function Facebookbot(configuration) {
  // copy over some facebook specific features
  message.page = message.recipient.id;
  - next();
  + }
  + next();
  });
  // handle normal messages from users (text, stickers, files, etc count!)
  