public async Task Handle(ShowAnswersSlackActionParams actionParams) { if (actionParams == null) { throw new ArgumentNullException(nameof(actionParams)); } if (actionParams.ButtonParams == null) { throw new ArgumentNullException(nameof(actionParams.ButtonParams)); } _logger.LogInformation( "User {User} with id {UserId} looked at the answers to the question {QuestionId}", actionParams.User.Name, actionParams.User.Id, actionParams.ButtonParams.QuestionId); var question = await _questionService.GetQuestionAsync(actionParams.ButtonParams.QuestionId); var bestAnswer = question.Answers.OrderByDescending(r => r.Rank).FirstOrDefault(); var attachment = CreateAttachment(question, bestAnswer); var attachments = actionParams.OriginalMessage.Attachments; attachments[actionParams.AttachmentId] = attachment; await _slackClient.UpdateMessageAsync( actionParams.OriginalMessage.TimeStamp, actionParams.Channel.Id, actionParams.OriginalMessage.Text, attachments); }
public async void UpdateMessageAsync_CorrectParametres_ShouldCallPostAsync() { //arange _httpClientMock .Setup(m => m.PostAsync(It.IsAny <string>(), It.IsAny <StringContent>())) .ReturnsAsync(new HttpResponseMessage() { Content = new StringContent("{\"ok\":\"true\"}") }); //act await _slackHttpClient.UpdateMessageAsync(Ts, ChannelId, Message); //assert _httpClientMock.Verify( m => m.PostAsync(It.Is <string>(x => x == "chat.update"), It.IsAny <StringContent>()), Times.Once); }
private Task UpdateMessageForUser(string answerText, string questionText, InvocationPayloadRequest request) { var message = $"{SpeechBalloon}\n" + $"*Your answer:* _{answerText}_\n" + $"*On question:* _{questionText}_\n" + "*Your answer will be recorded in a moment. Thank you!*"; return(_slackClient.UpdateMessageAsync( request.State, request.Channel.Id, message)); }
private Task UpdateMessage(AskExpertsSlackActionParams actionParams) { var attachments = actionParams.OriginalMessage.Attachments; var updateAttachment = attachments[actionParams.AttachmentId]; updateAttachment.Text += $"\n{Phrases.SendToExperts}"; updateAttachment.Actions = updateAttachment.Actions .Where(t => t.Name != AskExpertsButtonAttachmentAction.ActionName) .ToList(); attachments[actionParams.AttachmentId] = updateAttachment; return(_slackClient.UpdateMessageAsync( actionParams.OriginalMessage.TimeStamp, actionParams.Channel.Id, actionParams.OriginalMessage.Text, attachments)); }
private Task UpdateMessage(StopNotificationsSlackActionParams actionParams) { var attachments = actionParams.OriginalMessage.Attachments; var updateAttachment = attachments[actionParams.AttachmentId]; updateAttachment.Text = "_You have unsubscribed from the notifications for this question._"; updateAttachment.Actions = updateAttachment.Actions .Where(t => t.Name != StopNotificationsButtonAttachmentAction.ActionName) .ToList(); attachments[actionParams.AttachmentId] = updateAttachment; return(_slackClient.UpdateMessageAsync( actionParams.OriginalMessage.TimeStamp, actionParams.Channel.Id, actionParams.OriginalMessage.Text, attachments)); }
private Task UpdateMessage(NotHelpedSlackActionParams actionParams) { var attachments = actionParams.OriginalMessage.Attachments; var updateAttachment = attachments[actionParams.AttachmentId]; updateAttachment.Text += $"\n:heavy_multiplication_x: {Phrases.ThanksForOpinion}"; updateAttachment.Actions = updateAttachment.Actions .Where(t => t.Name != HelpedButtonAttachmentAction.ActionName && t.Name != NotHelpedButtonAttachmentAction.ActionName) .ToList(); attachments[actionParams.AttachmentId] = updateAttachment; return(_slackClient.UpdateMessageAsync(actionParams.OriginalMessage.TimeStamp, actionParams.Channel.Id, actionParams.OriginalMessage.Text, attachments)); }