Exemplo n.º 1
0
        protected override async Task <ISlackActionResponse> Respond(SlackActionPayload payload, MemeMessage message)
        {
            if (payload == null)
            {
                throw new ArgumentNullException(nameof(payload));
            }
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            var response = await DatabaseRepo.InsertResponse(
                messageId : message.Id,
                responseUrl : payload.ResponseUrl,
                teamId : payload.Team.Id,
                teamDomain : payload.Team.Domain,
                channelId : payload.Channel.Id,
                channelName : payload.Channel.Name,
                userId : payload.User.Id,
                userName : payload.User.Name);

            var config = await _configService.GetConfig();

            var template = await _configService.GetTemplate(message.TemplateId, message.UserId);

            var boxes = template.Boxes ?? config.TemplateDefaults.Boxes;
            var lines = _textSplitter.SplitText(message.Message, boxes.Count);

            var elements = lines.SelectWithIndex((line, i) => new SlackDialogText
            {
                Label    = String.IsNullOrEmpty(boxes[i].Label) ? $"Line {i + 1}" : boxes[i].Label,
                Name     = $"line{i}",
                Optional = true,
                Value    = line,
            }).ToList <ISlackDialogElement>();

            elements.Add(new SlackDialogSelect
            {
                Label    = "Post anonymously",
                Name     = "isAnonymous",
                Optional = false,
                Value    = message.IsAnonymous.ToString(),
                Options  = new[]
                {
                    new SlackDialogOption
                    {
                        Label = "Yes",
                        Value = Boolean.TrueString,
                    },
                    new SlackDialogOption
                    {
                        Label = "No",
                        Value = Boolean.FalseString,
                    },
                }
            });

            await _slackClient.DialogOpen(new SlackApiDialogOpenRequest
            {
                TriggerId = payload.TriggerId,
                Dialog    = new SlackDialog
                {
                    CallbackId  = $"{Constants.CallbackIds.Edit}:{response.Guid}",
                    Title       = "Edit",
                    SubmitLabel = "Preview",
                    Elements    = elements,
                }
            });

            return(new SlackEmptyResponse());
        }