helper.js
// If it's the clients first request, set up the web client, then respond
If it's the clients first request, set up the web client, then respond
If it ' s the clients first request set up the web client then respond
function respondToEvent(event) {
  if(event.subtype && event.subtype === "bot_message") {
    return;
  }
  if(!token) {
    Team.findOne({ users: event.user }, (err, currTeam) => {
      if(err) return console.log(err);
      if(!currTeam) {
        return console.log("user does not belong to any team");
      }
      token = currTeam.bot_access_token;
      web = new WebClient(token);
      team = currTeam;
      return eventToAction(event).then((response) => {
        actionToMessage(response);
      }, (error) => {
        if(error) console.log(error);
      });
    });
  } else {
    return eventToAction(event).then((response) => {
      actionToMessage(response);
    }, (error) => {
      if(error) console.log(error);
    });
  }
}
function respondToEvent ( event ) { if ( event . subtype && event . subtype === "bot_message" ) { return ; } if ( ! token ) { Team . findOne ( { users : event . user } , ( err , currTeam ) => { if ( err ) return console . log ( err ) ; if ( ! currTeam ) { return console . log ( "user does not belong to any team" ) ; } token = currTeam . bot_access_token ; web = new WebClient ( token ) ; team = currTeam ; return eventToAction ( event ) . then ( ( response ) => { actionToMessage ( response ) ; } , ( error ) => { if ( error ) console . log ( error ) ; } ) ; } ) ; } else { return eventToAction ( event ) . then ( ( response ) => { actionToMessage ( response ) ; } , ( error ) => { if ( error ) console . log ( error ) ; } ) ; } }
If it's the clients first request, set up the web client, then respond
If it ' s the clients first request set up the web client then respond
// Ignore if bot sends message