message: Add support for new location of team info in incoming slack messages
diff: @@ -3,6 +3,7 @@ var request = require('request');
  var express = require('express');
  var bodyParser = require('body-parser');
  var querystring = require('querystring');
  +var async = require('async');
  function Slackbot(configuration) {
  @@ -141,6 +142,38 @@ function Slackbot(configuration) {
  return slack_botkit;
  };
  +
  + slack_botkit.findAppropriateTeam = function(payload, cb) {
  +
  + var found_team = null;
  +
  + var team_id = payload.team_id || (payload.team && payload.team.id) || null;
  + slack_botkit.findTeamById(team_id, function(err, team) {
  + if (team) {
  + cb(err, team);
  + } else {
  + if (payload.authed_teams) {
  + async.eachSeries(payload.authed_teams, function(team_id, next) {
  + slack_botkit.findTeamById(team_id, function(err, team) {
  + if (team) {
  + found_team = team;
  + next();
  + } else {
  + next(err);
  + }
  + });
  + }, function(err) {
  + if (!found_team) {
  + cb(err);
  + } else {
  + cb(null, found_team);
  + }
  + });
  + }
  + }
  + });
  + }
  +
  slack_botkit.handleWebhookPayload = function(req, res) {
  // is this an events api url handshake?
  @@ -154,8 +187,8 @@ function Slackbot(configuration) {
  if (payload.payload) {
  payload = JSON.parse(payload.payload);
  }
  - var team_id = payload.team_id || (payload.team && payload.team.id) || null;
  - slack_botkit.findTeamById(team_id, function(err, team) {
  +
  + slack_botkit.findAppropriateTeam(payload, function(err, team) {
  if (err) {
  slack_botkit.log.error('Could not load team while processing webhook: ', err);
  return;
  