<commit_before>'use strict'

const express = require('express');
const Slapp = require('slapp');
const ConvoStore = require('slapp-convo-beepboop');
const Context = require('slapp-context-beepboop');

// use `PORT` env var on Beep Boop - default to 3000 locally
var port = process.env.PORT || 3000;

var slapp = Slapp({
  // Beep Boop sets the SLACK_VERIFY_TOKEN env var
  verify_token: process.env.SLACK_VERIFY_TOKEN,
  convo_store: ConvoStore(),
  context: Context()
});

var HELP_TEXT = `
I will respond to the following messages:
\`help\` - to see this message.
\The only tool available in this app right now is the messagemany slash command 1 second timeout
`;

//*********************************************
// Setup different handlers for messages
//*********************************************

// response to the user typing "help"
slapp.message('help', ['mention', 'direct_message'], (msg) => {
  msg.say(HELP_TEXT);
});

slapp.command('/messagemany', '(.*)', (msg, text, question) => {
  msg.say('Which channel(s) would you like to post to?').route('handleWhichChannels',{ message: text }, 1);
  return;
});

slapp.route('handleWhichChannels', (msg, state) => {
    var arr = msg.channelsMentioned();

    if (arr.length === 0) {
      msg.say('Invalid response. Please give me a list of channel(s) to message.').route('handleWhichChannels', state, 1);
      return;
    }

    for (var i = 0; i < arr.length; i++) {
      msg.say({
      text: state.message,
        channel: arr[i]
      });
    }  
});

// attach Slapp to express server<commit_msg>added custom timeout<commit_after>'use strict'

const express = require('express');
const Slapp = require('slapp');
const ConvoStore = require('slapp-convo-beepboop');
const Context = require('slapp-context-beepboop');

// use `PORT` env var on Beep Boop - default to 3000 locally
var port = process.env.PORT || 3000;

var slapp = Slapp({
  // Beep Boop sets the SLACK_VERIFY_TOKEN env var
  verify_token: process.env.SLACK_VERIFY_TOKEN,
  convo_store: ConvoStore(),
  context: Context()
});

var HELP_TEXT = `
I will respond to the following messages:
\`help\` - to see this message.
\The only tool available in this app right now is the messagemany slash command 1 second timeout
`;

//*********************************************
// Setup different handlers for messages
//*********************************************

// response to the user typing "help"
slapp.message('help', ['mention', 'direct_message'], (msg) => {
  msg.say(HELP_TEXT);
});

slapp.command('/messagemany', '(.*)', (msg, text, question) => {
  msg.say('Which channel(s) would you like to post to?').route('handleWhichChannels',{ message: text, requested: Date.now() });
});

slapp.route('handleWhichChannels', (msg, state) => {
    var elapsed = Date.now() - state.requested;
    if (elapsed / 1000 > 10) {
      msg.say('Conversation timed out')
      return;
    }
    
    var arr = msg.channelsMentioned();
  
    if (arr.length === 0) {
      msg.say('Invalid response. Please give me a list of channel(s) to message.').route('handleWhichChannels', state);
    }

    for (var i = 0; i < arr.length; i++) {
      msg.say({
      text: state.message,
        channel: arr[i]
      });
    }  
});

// attach Slapp to express server
{'fraction_non_alphanumeric': 0.19719169719169719, 'fraction_numerical': 0.009157509157509158, 'mean_word_length': 3.804985337243402, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 10, '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': '849201', 'n_tokens_mistral': 1060, 'n_tokens_neox': 1014, 'n_words': 307}