Esempio n. 1
0
        public async Task<IHttpActionResult> Execute(Entities.Slack.SlashCommand command)
        {
            if (string.IsNullOrWhiteSpace(slackToken))
            {
                throw new ArgumentNullException("No token provided.");
            }

            if (string.IsNullOrWhiteSpace(endpoint))
            {
                throw new ArgumentNullException("No endpoint provided.");
            }

            if(command.token != slackToken)
            {
                throw new AuthenticationException("Authorization failed.");
            }

            Entities.Merge merge;

            try
            {
                merge = command.ToMerge();

                using(var client = new HttpClient())
                {
                    await client.PostAsJsonAsync<Entities.Slack.SlashCommand>(endpoint, command);
                }
            }
            catch
            {
                return Json("An error ouccured while scheduling your command. Command: " + command.text);
            }

            return Json("Your command has been scheduled successfully. Merging " + merge.HumanReadable());
        }
Esempio n. 2
0
 public static Entities.Merge ForMerge(Entities.Slack.SlashCommand command)
 {
     return command.ToMerge();
 }