Ejemplo n.º 1
0
        public static async Task <IActionResult> OnPlan(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "slack/commands/plan")] HttpRequest req,
            [Table("proposals")] CloudTable proposalsTable,
            IBinder binder, ExecutionContext context)
        {
            Utils.SetCulture();

            var body = await SlackHelper.ReadSlackRequest(req, context);

            var parameters   = SlackHelper.ParseBody(body);
            var partitionKey = Utils.GetPartitionKey(parameters["team_id"], parameters["channel_id"]);

            var dialogRequest = new OpenDialogRequest {
                TriggerId = parameters["trigger_id"],
                Dialog    = await DialogHelpers.GetPlanDialog(binder, partitionKey, defaultDate : parameters["text"])
            };

            await SlackHelper.OpenDialog(binder, parameters["team_id"], dialogRequest);

            return(Utils.Ok());
        }
Ejemplo n.º 2
0
        public static async Task <IActionResult> DispatchAction(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "slack/action-endpoint")] HttpRequest req,
            IBinder binder, ExecutionContext context)
        {
            Utils.SetCulture();

            var body = await SlackHelper.ReadSlackRequest(req, context);

            var parameters = SlackHelper.ParseBody(body);
            var payload    = SlackHelper.DecodePayload(parameters["payload"]);

            if (payload is DialogSubmissionPayload dsp)
            {
                if (dsp.CallbackId == "propose")
                {
                    var result = ValidateProposal(dsp);
                    if (!result.Valid)
                    {
                        return(Utils.Ok(result));
                    }

                    await RecordProposal(binder, dsp);
                }
                else if (dsp.CallbackId == "plan")
                {
                    var result = await ValidatePlan(binder, dsp);

                    if (!result.Valid)
                    {
                        return(Utils.Ok(result));
                    }

                    await RecordPlan(binder, dsp);
                }
                else if (dsp.CallbackId == "vote")
                {
                    var result = ValidateVotes(dsp);
                    if (!result.Valid)
                    {
                        return(Utils.Ok(result));
                    }

                    await RecordVotes(binder, dsp);
                }
            }
            else if (payload is InteractiveMessagePayload imp)
            {
                switch (imp.CallbackId)
                {
                case "message_action" when imp.Actions.First().Name == "removeme":
                    return(Utils.Ok(new SlackMessage {
                        DeleteOriginal = true
                    }));

                case "plan_action":
                    return(await ProcessPlanAction(binder, imp));

                case "proposal_action":
                    return(await ProcessProposalAction(binder, imp));

                case "dialog_action":
                    return(await ProcessDialogAction(binder, imp));
                }
            }

            return(Utils.Ok());
        }