<commit_before>'use strict';

const Wit = require('node-wit').Wit;
const myActions = require('./my-wit-actions');

/**
 * Handles wit.ai integration
 * @param event
 */
const init = event => new Promise((resolveMessage, rejectMessage) => {
  if (event.sender && event.sender.id && event.message && event.message.text) {
    const sessionId = `${event.id}-${event.updated}`;
    const context0 = {};
    const actions = {
      send: (request, response) => new Promise(() => {
        resolveMessage(response);
      })
    };
    // Copy custom actions to actions
    Object.keys(myActions).map((value) => {
      actions[value] = myActions[value];
    });
    const client = new Wit({
      accessToken: process.env.WIT_AI_TOKEN,
      actions: actions
    });
    client.runActions(sessionId, event.message.text, context0)
    .then(result => resolveMessage(result))
    .catch(error => rejectMessage(error));
  } else {
    rejectMessage('wit ai failed');
  }
});

module.exports = init;<commit_msg>Add debugContext action for wit.ai<commit_after>'use strict';

const Wit = require('node-wit').Wit;
const myActions = require('./my-wit-actions');

/**
 * Handles wit.ai integration
 * @param event
 */
const init = event => new Promise((resolveMessage, rejectMessage) => {
  if (event.sender && event.sender.id && event.message && event.message.text) {
    const sessionId = `${event.id}-${event.updated}`;
    const context0 = {};
    const actions = {
      send: (request, response) => new Promise(() => {
        resolveMessage(response);
      }),
      debugContext: (data) => new Promise((resolve, reject) => {
        const context = data.context;
        console.log('WIT.AI DEBUG:')
        console.log(JSON.stringify(data, null, 2));
        resolve(context);
      })
    };
    // Copy custom actions to actions
    Object.keys(myActions).map((value) => {
      actions[value] = myActions[value];
    });
    const client = new Wit({
      accessToken: process.env.WIT_AI_TOKEN,
      actions: actions
    });
    client.runActions(sessionId, event.message.text, context0)
    .then(result => resolveMessage(result))
    .catch(error => rejectMessage(error));
  } else {
    rejectMessage('wit ai failed');
  }
});

module.exports = init;
{'fraction_non_alphanumeric': 0.16245006657789615, 'fraction_numerical': 0.0022192632046160675, 'mean_word_length': 3.1433823529411766, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2188475', 'n_tokens_mistral': 679, 'n_tokens_neox': 675, 'n_words': 149}