public async Task SendMessageToChannel(MessageToChannelMode message) { try { await prepareRequestToSendMessageToChannel(message); } catch (Exception) { throw; } }
private async Task <MessageToChannelMode> prepareMessageToChannelModel(string message, string channel) { var token = (await _context.Configurations.FirstOrDefaultAsync()).BotAccessToken; var messageModel = new MessageToChannelMode() { token = token, channel = channel, text = message }; return(messageModel); }
public async Task SendMessage(string message, string channel) { try { MessageToChannelMode messageModel = await prepareMessageToChannelModel(message, channel); await _slackApiHelper.SendMessageToChannel(messageModel); } catch (System.Exception) { throw; } }
public async Task SendMessage(SlackEventRequestModel quote, string quoteVoteUid) { try { var message = $"Nova quote: '{quote.text}'; User para votar o id: {quoteVoteUid}!"; MessageToChannelMode messageModel = await prepareMessageToChannelModel(message, quote.channel_id); await _slackApiHelper.SendMessageToChannel(messageModel); } catch (System.Exception e) { throw; } }
private async Task prepareRequestToSendMessageToChannel(MessageToChannelMode message) { UriBuilder builder = new UriBuilder("https://slack.com/api/chat.postMessage"); var request = new HttpRequestMessage(HttpMethod.Post, builder.Uri); StringContent content = new StringContent(JsonConvert.SerializeObject(message), Encoding.UTF8, "application/json"); request.Content = content; var client = _clientFactory.CreateClient(); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", message.token); var sent = await client.SendAsync(request); var contents = sent.Content; var responseMessage = await contents.ReadAsStringAsync(); }