protected async Task <bool> Respond(SlackRequest request, SlackResponse response) { var httpResponse = await HttpClient.SendAsync(new HttpRequestMessage { RequestUri = new Uri(request.ResponseUrl), Method = HttpMethod.Post, Content = new StringContent(JsonConvert.SerializeObject(response), Encoding.UTF8, "application/json") }); return(httpResponse.StatusCode == HttpStatusCode.OK); }
protected async Task <bool> Respond(SlackRequest request, SlackResponse response) { using (var stream = new MemoryStream()) { JsonSerializer.Serialize(response, stream); stream.Position = 0; var httpResponse = await HttpClient.SendAsync(new HttpRequestMessage { RequestUri = new Uri(request.ResponseUrl), Method = HttpMethod.Post, Content = new StreamContent(stream) }); return(httpResponse.StatusCode == HttpStatusCode.OK); } }
//--- Abstract Methods --- protected abstract Task HandleSlackRequestAsync(SlackRequest request);
protected Task <bool> RespondEphemeral(SlackRequest request, string text, params SlackResponseAttachment[] attachments) => Respond(request, SlackResponse.Ephemeral(text, attachments));
protected Task <bool> RespondInChannel(SlackRequest request, string text, params SlackResponseAttachment[] attachments) => Respond(request, SlackResponse.InChannel(text, attachments));