public ActivateDeviceCommand(SlackSlashCommandRequest req) : base(req) { var args = req.Text?.Split(' '); if (args != null) { _code = args.FirstOrDefault(x => x.Length == RegisterDeviceCommand.CodeLength); } }
public static async Task <HttpResponseMessage> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = Path)] HttpRequestMessage req, TraceWriter log = null) { if (log == null) { log = new TraceMonitor(); } var slackRequest = new SlackSlashCommandRequest(await req.Content.ReadAsFormDataAsync()); if (slackRequest.Token != Config.Instance.SlackVerificationToken) { log.Warning($"Unauthorized call to command ({slackRequest.Token})"); return(req.CreateResponse(HttpStatusCode.Unauthorized)); } if (string.IsNullOrWhiteSpace(slackRequest.Command)) { log.Verbose($"Invalid Command {slackRequest.Command}"); return(req.CreateResponse(HttpStatusCode.OK, new SlackSlashCommandResponse { ResponseType = MessageResponseType.Ephemeral, Text = "Invalid Command" })); } try { var command = MusicBotCommandFactory.GetCommand(slackRequest); if (command == null) { return(req.CreateResponse(HttpStatusCode.OK, new SlackSlashCommandResponse() { Status = MessageResponseStatus.Failure, SubStatus = MessageResponseSubStatus.UnknownCommand, ResponseType = MessageResponseType.Ephemeral, Text = $"Unknown command {slackRequest.Text?.Split(' ').FirstOrDefault()}".Trim() })); } return(req.CreateResponse(await command.Execute(log))); } catch (Exception ex) { log.Error("Unexpected Error", ex); return(req.CreateResponse(HttpStatusCode.OK, new SlackSlashCommandResponse { ResponseType = MessageResponseType.Ephemeral, Text = "Oops, an unexpected error occurred. We'll look into it.", Status = MessageResponseStatus.Failure, SubStatus = MessageResponseSubStatus.Internal })); } }
public static MusicBotCommand GetCommand(SlackSlashCommandRequest req) { var key = RegisteredCommands.Keys.FirstOrDefault(x => x.Equals(req.Text?.Split(' ').FirstOrDefault(), StringComparison.OrdinalIgnoreCase)); if (key == null) { return(null); } return((MusicBotCommand)Activator.CreateInstance(RegisteredCommands[key], req)); }
public HttpRequestMessage GetStandardSlackHttpRequestMessage(SlackSlashCommandRequest requestIs = null, bool useDefaults = true) { if (requestIs == null && useDefaults) { requestIs = StandardSlackSlashCommandRequest; } var result = new HttpRequestMessage(HttpMethod.Post, new Uri("https://apihost/api/" + StandardSlackPath)) { Content = requestIs.GetFormContent(), }; result.SetConfiguration(new HttpConfiguration()); return(result); }
public static FormUrlEncodedContent GetFormContent(this SlackSlashCommandRequest req) { return(new FormUrlEncodedContent(new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("token", req.Token), new KeyValuePair <string, string>("team_id", req.TeamId), new KeyValuePair <string, string>("team_domain", req.TeamDomain), new KeyValuePair <string, string>("enterprise_id", req.EnterpriseId), new KeyValuePair <string, string>("enterprise_name", req.EnterpriseName), new KeyValuePair <string, string>("channel_id", req.ChannelId), new KeyValuePair <string, string>("channel_name", req.ChannelName), new KeyValuePair <string, string>("user_id", req.UserId), new KeyValuePair <string, string>("user_name", req.UserName), new KeyValuePair <string, string>("command", req.Command), new KeyValuePair <string, string>("text", req.Text), new KeyValuePair <string, string>("response_url", req.ResponseUrl) })); }
public PlayCommand(SlackSlashCommandRequest req) : base(req) { }
protected MusicBotCommand(SlackSlashCommandRequest req) { Request = req; Args = req.Text?.Split(' '); }