public HttpResponseMessage Endpoint(SlackMessage message)
        {
            try
            {
                var slackTeamToken = ConfigurationManager.AppSettings["Slack_team_token"];

                if (message.token != slackTeamToken)
                {
                    return this.Request.CreateErrorResponse(HttpStatusCode.Forbidden, "Invalid team token");
                }

                var commandParser = new CommandParser();
                var command = commandParser.ParseCommand(message);
                var response = command.Execute();
                return new HttpResponseMessage { Content = new StringContent(response) };
            }
            catch (Exception exception)
            {
                var errorMessage = new StringBuilder();
                errorMessage.AppendLine("Message: " + exception.Message);
                errorMessage.AppendLine();
                errorMessage.AppendLine("Stack Trace:");
                errorMessage.AppendLine(exception.StackTrace);
                errorMessage.AppendLine();
                return this.Request.CreateErrorResponse(HttpStatusCode.InternalServerError, errorMessage.ToString());
            }
        }
        public ICommand ParseCommand(SlackMessage message)
        {
            var commandParts = GetCommandParts(message.text);
            var mainCommand = commandParts.Item1;
            var commandArguments = commandParts.Item2;

            if (string.IsNullOrWhiteSpace(mainCommand))
            {
                return new ListAllSponsorsCommand(message, commandArguments);
            }

            var matchingCommands = FindAllCommandTypes().Where(t => MatchesCommandText(t, mainCommand)).ToList();

            if (!matchingCommands.Any())
            {
                throw new Exception("Unknown command: " + mainCommand);
            }

            if (matchingCommands.Count > 1)
            {
                throw new Exception("Multiple possible commands found: " + mainCommand);
            }

            var command = (ICommand)Activator.CreateInstance(matchingCommands.Single(), message, commandArguments);
            return command;
        }
 protected CommandBase(SlackMessage message, string[] commandArguments)
 {
     this.message = message;
     this.commandArguments = commandArguments;
 }
 public ListAllSponsorsCommand(SlackMessage message, string[] commandArguments)
     : base(message, commandArguments)
 {
 }
 public DeleteSponsorCommand(SlackMessage message, string[] commandArguments)
     : base(message, commandArguments)
 {
 }
 public HelpCommand(SlackMessage message, string[] commandArguments)
     : base(message, commandArguments)
 {
 }