private MessageResponse BuildCreateTicketMessageResponse(string name, int count, long ticketId) { var mr = new MessageResponse(); mr.text = $"I'm sure {name} appreciates the ticket! They have {count} now! If it was an accident you can revoke the ticket below!"; var attachment = new Attachment(); attachment.color = "#3AA3A3"; attachment.attachment_type = "default"; attachment.fallback = "Cannot revoke ticket at this time"; attachment.callback_id = Guid.NewGuid().ToString(); var action = new SlackAction(); action.name = "revoke"; action.text = "Revoke"; action.value = ticketId.ToString(); action.type = "button"; var actionsList = new List <SlackAction>() { action }; attachment.actions = actionsList; var attachmentsList = new List <Attachment>() { attachment }; mr.attachments = attachmentsList; return(mr); }
public async Task <JObject> BuildSlackPayload(string header, string sourceId, ICloseClient closeApi, string jobPostCustomer = null) { Dictionary <string, Option> customers = await closeApi.GetListOfCustomers(); BlocksBuilder builder = new BlocksBuilder(); StaticSelect customerSelect = new StaticSelect("customer_select", customers.Values.ToList(), "Customer"); SlackAction actions = new SlackAction("actions") .AddElement(customerSelect); // check if we have detected a customer and if so set it as initial option if (!string.IsNullOrEmpty(jobPostCustomer)) { actions.AddElement(new Button("addToClose_btn", "Add to Close", ButtonStyle.PRIMARY)); if (customers.ContainsKey(jobPostCustomer)) { customerSelect.AddInitialOption(customers[jobPostCustomer]); } } // adding button in the proper place actions.AddElement(new Button("qualifyLead_btn", "Qualify Lead", string.IsNullOrEmpty(jobPostCustomer) ? ButtonStyle.PRIMARY : ButtonStyle.DEFAULT)); builder.AddBlock(new Section(new Text(" "))); builder.AddBlock(new Section(new Text(" "))); builder.AddBlock(new Section(new Text("*" + header + "*" + Environment.NewLine + sourceId, "mrkdwn"), "msg_header")); builder.AddBlock(actions); builder.AddBlock(new Divider()); return(builder.GetJObject()); }
public async Task HandlePageCallback(SlackAction slackAction) { PageCallbackId pageCallbackId = PageCallbackId.FromJson(slackAction.CallbackId); GetCacheItemResult result = await _mediator.Send(new GetCacheItem(pageCallbackId.CacheItemId)); int page = 1; page = Convert.ToInt32(pageCallbackId.Page); switch (slackAction.Actions.First().Value) { case "nextpage": page++; break; case "prevpage": page--; break; } dynamic notesAttachment = _attachmentGenerator.GenerateAttachment(result.Notes, pageCallbackId.CacheItemId, page); await _disappearingSlackMessageProvider.SendDisappearingSlackUpdate( channel : slackAction.Channel.Id, ts : slackAction.MessageTs, attachment : (string)notesAttachment, text : ""); }
public async Task Process(SlackAction payload) { if (Guid.TryParse(payload.Value, out var deploymentId)) { var deployment = await _deploymentService.GetDeployment(deploymentId); await _deploymentQueueService.EnqueueDeployment(deployment, TimeSpan.FromSeconds(5)); } }
public async Task Should_add_error_if_webhook_url_is_relative() { var action = new SlackAction { WebhookUrl = new Uri("/invalid", UriKind.Relative) }; var errors = await RuleActionValidator.ValidateAsync(action); Assert.NotEmpty(errors); }
public async Task Should_not_add_error_if_webhook_url_is_absolute() { var action = new SlackAction { WebhookUrl = new Uri("https://squidex.io", UriKind.Absolute) }; var errors = await RuleActionValidator.ValidateAsync(action); Assert.Empty(errors); }
public async Task Should_add_error_if_webhook_url_is_null() { var action = new SlackAction { WebhookUrl = null }; var errors = await RuleActionValidator.ValidateAsync(action); Assert.NotEmpty(errors); }
public Task <IEnumerable <ValidationError> > Visit(SlackAction action) { var errors = new List <ValidationError>(); if (action.WebhookUrl == null || !action.WebhookUrl.IsAbsoluteUri) { errors.Add(new ValidationError("Webhook Url is required and must be an absolute URL.", nameof(action.WebhookUrl))); } return(Task.FromResult <IEnumerable <ValidationError> >(errors)); }
public async Task ExecuteAction(SlackAction slackAction) { if (slackAction.CallbackId.Contains(Constants.Constants.CallbackIdTypeNote)) { HandleDeleteCallback(slackAction); } else if (slackAction.CallbackId.Contains(Constants.Constants.CallbackIdTypePage)) { HandlePageCallback(slackAction); } }
public async Task Should_add_error_if_webhook_url_is_relative() { var action = new SlackAction { WebhookUrl = new Uri("/invalid", UriKind.Relative) }; var errors = await RuleActionValidator.ValidateAsync(action); errors.Should().BeEquivalentTo( new List <ValidationError> { new ValidationError("Webhook URL is required and must be an absolute URL.", "WebhookUrl") }); }
public async Task <IActionResult> ActionAsync([FromForm] IFormCollection formCollection) { StringValues request; formCollection.TryGetValue("payload", out request); SlackAction action = SlackAction.FromJson(request.ToString()); if (action.Type == Constants.Constants.RequestTypeInteractiveMessage) { Hangfire.BackgroundJob.Enqueue(() => _commandStrategy.ExecuteAction(action)); } return(Ok()); }
public async Task HandleDeleteCallback(SlackAction slackAction) { DeleteCallbackId deleteCallbackId = DeleteCallbackId.FromJson(slackAction.CallbackId); DeleteNoteQueryResult result = await _mediator.Send(new DeleteNoteQuery(deleteCallbackId.DocumentId)); if (result.Result == QueryResult.Success) { await _disappearingSlackMessageProvider.SendDisappearingSlackUpdate( text : Constants.Constants.MessageNoteDeleted, channel : slackAction.Channel.Id, ts : slackAction.MessageTs, attachment : ""); } }
public async Task ExecuteAction(SlackAction slackAction) { string selectedTeam = slackAction.Actions[0].SelectedOptions[0].value; GetAuthorQueryResult result = await _mediator.Send(new GetAuthorQuery(slackAction.User.Id)); if (result.Result != QueryResult.NotFound) { await _mediator.Send(new DeleteAuthorQuery(result.Document.DocumentId)); } CreateAuthorQueryResult creationResult = await _mediator.Send(new CreateAuthorQuery(new Author(slackAction.User.Id, selectedTeam))); await _disappearingSlackMessageProvider.SendDisappearingSlackUpdate( text : Constants.Constants.GetTeamJoinMessage(selectedTeam), channel : slackAction.Channel.Id, ts : slackAction.MessageTs, attachment : ""); }
public static JObject BuildDefaultSlackPayload(string header, Option selectedOption, SlackPostState postState, string leadId = "", Dictionary <string, Option> customers = null) { BlocksBuilder builder = new BlocksBuilder(); SlackAction actions = new SlackAction("actions"); if (!(customers is null)) { StaticSelect customerSelect = new StaticSelect("customer_select", customers.Values.ToList(), "Customer"); actions.AddElement(customerSelect); if (!(selectedOption is null)) { customerSelect.AddInitialOption(selectedOption); } } actions.AddElement(new Button("addToClose_btn", "Add to Close", ButtonStyle.PRIMARY)); // adding button in the proper place actions.AddElement(new Button("qualifyLead_btn", "Qualify Lead")); builder.AddBlock(new Section(new Text(" "))); builder.AddBlock(new Section(new Text(" "))); builder.AddBlock(new Section(new Text(header, "mrkdwn"), "msg_header")); if (postState == SlackPostState.ACTIONS) { builder.AddBlock(actions); } else if (postState == SlackPostState.FINAL) { builder.AddBlock(new Section(new Text($":white_check_mark: *Opportunity added to <https://app.close.com/lead/{leadId}|Close.com>*", "mrkdwn"))); } builder.AddBlock(new Divider()); return(builder.GetJObject()); }
public string SlackAction(string payload) { SlackActionRequest actionRequest = JsonConvert.DeserializeObject <SlackActionRequest>(payload); SlackAction action = actionRequest.actions.First(); string actionName = action.name; switch (actionName) { case "revoke": int ticketId = Int32.Parse(action.value); Ticket ticketToDelete = context.Tickets.FirstOrDefault(t => t.ID == ticketId); if (ticketToDelete == null) { return("Oops, I cannot find that ticket."); } context.Tickets.Remove(ticketToDelete); context.SaveChanges(); return($"Deleted... Like taking candy from a high schooler..."); default: return("ERROR"); } }
/// <summary> /// Method to handle Redmine Slash command /// </summary> /// <param name="slashCommand">slash command</param> /// <returns>reply message</returns> public async Task SlackRequestAsync(SlashCommand slashCommand) { // Way to break string by spaces only if spaces are not between quotes var text = _attachmentRepository.SlackText(slashCommand.Text); // Get user details from SlackUserId var user = await _userDataRepository.FirstOrDefaultAsync(x => x.SlackUserId == slashCommand.UserId); if (user != null) { SlackAction action; if (SlackAction.TryParse(text[0], out action)) { if (action != SlackAction.apikey) { if (!string.IsNullOrEmpty(user.RedmineApiKey)) { switch (action) { // To get redmine project list #region Project list case SlackAction.projects: await GetRedmineProjectList(user); break; #endregion // Redmine issue related #region Issues case SlackAction.issues: { RedmineAction redmineAction; if (RedmineAction.TryParse(text[1], out redmineAction)) { switch (redmineAction) { // To get redmine issue list assignee to me #region Issues List case RedmineAction.list: await GetRedmineIssueList(user, text); break; #endregion // To create redmine issue #region Issue Create case RedmineAction.create: await CreateRedmineIssue(user, text); break; #endregion // To change assignee in redmine issue #region Change Assignee case RedmineAction.changeassignee: await UpdateChangeAssignee(user, text); break; #endregion // To close the issue of redmine #region Issue close case RedmineAction.close: await UpdateByPropertyAsync(true, 0, text[2], user.RedmineApiKey); break; #endregion // To add time entry in redmine issue #region Issue Time Entry case RedmineAction.timeentry: await AddTimeEntryToRedmineIssue(user, text); break; #endregion } } else { // If command action is not in format replyText = string.Format(_stringConstant.ProperRedmineIssueAction, RedmineAction.list.ToString(), RedmineAction.create.ToString(), RedmineAction.changeassignee.ToString(), RedmineAction.close.ToString(), RedmineAction.timeentry.ToString()); } } break; #endregion // To get help in redmine slash command #region Help case SlackAction.help: replyText = _stringConstant.RedmineHelp; break; #endregion } } else { // If user's redmine API key is not yet set replyText = _stringConstant.RedmineApiKeyIsNull; } } #region Api Key else { await AddRedmineAPIKey(user, text); } #endregion } else { // If command action is not in format replyText = string.Format(_stringConstant.RequestToEnterProperRedmineAction, SlackAction.list.ToString(), SlackAction.projects.ToString(), SlackAction.help.ToString()); } } else { // If user not found replyText = _stringConstant.SlackUserNotFound; } await _clientRepository.SendMessageAsync(slashCommand.ResponseUrl, replyText); }
public async Task Process(SlackAction payload) { await _slackApiClient.View.UpdateByViewId(payload.Payload.View.ID, ViewBuilder.BuildManageDeploymentView(_applicationService, payload.Payload.View.State, true, true, false) ); }
public async Task ExecuteAction(SlackAction slackAction) { await _commands.FirstOrDefault(x => slackAction.CallbackId.Contains((string)x.GetActionName))?.ExecuteAction(slackAction); }
public RuleActionDto Visit(SlackAction action) { return(SimpleMapper.Map(action, new SlackActionDto())); }
public async Task ExecuteAction(SlackAction slackAction) { throw new NotImplementedException(); }