old_contents: const utils = require('./utils/Utils.js');
  const config = require('../config/Config.js');
  const uuidV4 = require('uuid/v4');
  
  /** @module aggregate */
  /**
   * Takes a conversation and extracts:
   * - facebook messenger id
   * - a conversation metadata object that has metadata and the conversation
   * @param {object} conversation - A conversation object generated by botkit.
   * @return {object} Messenger id and submission metadata from the conversation.
   */
  function aggregate(conversation) {
    const {startTime, lastActive, responses, context} = conversation;
    const times = extractTimeStamps(responses);
    const metadata = {
      start: startTime,
      stop: lastActive,
      bot_identifier: context,
      responses: utils.mergeObjects(responses, times) ,
      conversation,
    };
  
    return {
      userId: context.user,
      submission_metadata: metadata,
    };
  }
  
  /**
  * @param {object} responses - value of the responses key in the conversation
  * object
  * @return {array} - An array of objects with question + TimeStamp and timestamps
  */
  function extractTimeStamps(responses) {
    return Object.keys(responses)
      .reduce((x, key) => {
        const obj = {};
        obj[key + 'TimeStamp'] = {text: responses[key].timestamp};
        return Object.assign(x, obj);
      }, {});
  }
  
  /**
  * Generate an ona submission from a completed conversation
  * @param {object} conversation the conversation with the bot
  * @return {object} a valid Ona submission object
  */
  function genOnaSubmission(conversation) {
    const submission = {};
    submission.id = config.onaFormIdString;
    const responses = conversation.submission_metadata.responses;
    const names = Object.keys(responses);
  
    const subb = names.map((name) => {
      const kv = {};
      if (name === 'repeat') {
        kv.spoken = responses.repeat.spoken;
        kv.with_whom = responses.repeat.with_whom;
        return kv;
      }
      kv[name] = responses[name].text;
      return kv;
    });
  
    const sub = subb.reduce((x = {}, kv) => Object.assign(x, kv));
    submission.submission = sub;
    submission.submission.meta = {instanceID: `uuid:${uuidV4()}`};
    return submission;
  }
  
  module.exports = {
    aggregate,
    genOnaSubmission
  };
  
new_contents: /** @module aggregate */
  
  const utils = require('./utils/Utils.js');
  const config = require('../config/Config.js');
  const uuidV4 = require('uuid/v4');
  
  /**
   * Takes a conversation and extracts:
   * - facebook messenger id
   * - a conversation metadata object that has metadata and the conversation
   * @param {object} conversation - A conversation object generated by botkit.
   * @return {object} Messenger id and submission metadata from the conversation.
   */
  function aggregate(conversation) {
    const {startTime, lastActive, responses, context} = conversation;
    const times = extractTimeStamps(responses);
    const metadata = {
      start: startTime,
      stop: lastActive,
      bot_identifier: context,
      responses: utils.mergeObjects(responses, times),
      conversation,
    };
  
    return {
      userId: context.user,
      submission_metadata: metadata,
    };
  }
  
  /**
  * @param {object} responses - value of the responses key in the conversation
  * object
  * @return {object} - An object of question and ISO 8601 timestamps with the
  * structure {question+'TimeStamp': {text: <timestamp in ISO 8601>}}
  */
  function extractTimeStamps(responses) {
    return Object.keys(responses)
      .reduce((accum, key) => {
        const obj = {};
        const date = new Date(responses[key].timestamp);
        obj[key + 'TimeStamp'] = {text: date};
        return Object.assign(accum, obj);
      }, {});
  }
  
  /**
  * Generate an ona submission from a completed conversation
  * @param {object} conversation the conversation with the bot
  * @return {object} a valid Ona submission object
  */
  function genOnaSubmission(conversation) {
    const submission = {};
    submission.id = config.onaFormIdString;
    const responses = conversation.submission_metadata.responses;
    const names = Object.keys(responses);
  
    const subb = names.map((name) => {
      const kv = {};
      if (name === 'repeat') {
        kv.spoken = responses.repeat.spoken;
        kv.with_whom = responses.repeat.with_whom;
        return kv;
      }
      kv[name] = responses[name].text;
      return kv;
    });
  
    const sub = subb.reduce((x = {}, kv) => Object.assign(x, kv));
    submission.submission = sub;
    submission.submission.meta = {instanceID: `uuid:${uuidV4()}`};
    return submission;
  }
  
  module.exports = {
    aggregate,
    genOnaSubmission,
  };
  
subject: Use ISO date format