<commit_before>// A sample chatbot app that listens to messages posted to a space in IBM
// Watson Workspace and echoes hello messages back to the space

import express from 'express';
import * as request from 'request';
import * as util from 'util';
import * as bparser from 'body-parser';
import { createHmac } from 'crypto';
import * as http from 'http';
import * as https from 'https';
import * as oauth from './oauth';
import * as ssl from './ssl';
import debug from 'debug';
import * as path from 'path';
import * as socket from 'socket.io';
import * as fs from 'fs';
import * as _ from 'lodash';
var io;
var openwhisk = require('openwhisk');
const options = {
  apihost: 'https://openwhisk.ng.bluemix.net',
  namespace: '<EMAIL>_dev',
  api_key: '<KEY>'
};
var ow = openwhisk(options);


// Debug log
const log = debug('watsonwork-echo-app');

// Echoes Watson Work chat messages containing 'hello' or 'hey' back
// to the space they were sent to
export const echo = (appId, token) => (req, res) => {
  // Respond to the Webhook right away, as the response message will
  // be sent asynchronously
  res.status(201).end();

  // Only handle message-created Webhook events, and ignore the app's
  // own messages
  // if(req.body.type !== 'message-annotation-added')
  if(req.body.type !== 'message-annotation-added') {
    console.log(JSON.stringify(req.body,null, "  "));
  }

  if (req.body.hasOwnProperty('annotationPayload'))
    req.body.annotationPayload = JSON.parse(req.body.annotationPayload);

	io.sockets.emit('webhook-event', {eventTime: new Date(), body: req.body});

  req.body.token = token();
  ow.triggers.invoke({
    name: 'WatsonWorkEvent',
    blocking: true,
    result: true,
    params: req.body}).then(result => console.log(result))
<commit_msg>add annotation expansion<commit_after>// A sample chatbot app that listens to messages posted to a space in IBM
// Watson Workspace and echoes hello messages back to the space

import express from 'express';
import * as request from 'request';
import * as util from 'util';
import * as bparser from 'body-parser';
import { createHmac } from 'crypto';
import * as http from 'http';
import * as https from 'https';
import * as oauth from './oauth';
import * as ssl from './ssl';
import debug from 'debug';
import * as path from 'path';
import * as socket from 'socket.io';
import * as fs from 'fs';
import * as _ from 'lodash';
var io;
var openwhisk = require('openwhisk');
const options = {
  apihost: 'https://openwhisk.ng.bluemix.net',
  namespace: '<EMAIL>_dev',
  api_key: '<KEY>'
};
var ow = openwhisk(options);


// Debug log
const log = debug('watsonwork-echo-app');

// Echoes Watson Work chat messages containing 'hello' or 'hey' back
// to the space they were sent to
export const echo = (appId, token) => (req, res) => {
  // Respond to the Webhook right away, as the response message will
  // be sent asynchronously
  res.status(201).end();

  if (req.body.hasOwnProperty('annotationPayload')) {
    req.body.annotationPayload = JSON.parse(req.body.annotationPayload);
    const messageQuery = util.format(`
  		query {
  			message(id: "%s") {
  				content
  		    id
  		    createdBy {
  		      displayName
  		      id
  		      emailAddresses
  		      photoUrl
  		    }
  		  }
  		}`, req.body.messageId);
    console.log('messageQuery: ' + messageQuery);
    graphQL(token(), messageQuery, (err,res) => {
      if(!err) {
        log('Got graphQL Response back! %o', res.body);
      	io.sockets.emit('webhook-event', {eventTime: new Date(), body: req.body});
      }
      else {
        log("Error with graphQL request... %o", err)
      }
    });

  }
  else {
  	io.sockets.emit('webhook-event', {eventTime: new Date(), body: req.body});
  }


  req.body.token = token();
  ow.triggers.invoke({
    name: 'WatsonWorkEvent',
    blocking: true,
    result: true,
    params: req.body}).then(result => console.log(result))

{'fraction_non_alphanumeric': 0.14140127388535031, 'fraction_numerical': 0.0015286624203821656, 'mean_word_length': 3.3964165733482643, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 14, 'https://': 2, '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': '3767095', 'n_tokens_mistral': 1279, 'n_tokens_neox': 1227, 'n_words': 404}