Esempio n. 1
0
        private static async Task <IActionResult> ProcessDialogAction(IBinder binder, InteractiveMessagePayload payload)
        {
            var action = payload.Actions.First();

            if (action.Name == "plan")
            {
                var dialogRequest = new OpenDialogRequest {
                    TriggerId = payload.TriggerId,
                    Dialog    = await DialogHelpers.GetPlanDialog(binder, action.Value)
                };

                await SlackHelper.OpenDialog(binder, payload.Team.Id, dialogRequest);
            }

            // NOTE: Présentement toutes les dialog_actions suppriment le message original
            return(Utils.Ok(new SlackMessage {
                DeleteOriginal = true
            }));
        }
Esempio n. 2
0
        public static async Task <IActionResult> OnPropose(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "slack/commands/propose")] HttpRequest req,
            IBinder binder, ExecutionContext context)
        {
            Utils.SetCulture();

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

            var parameters = SlackHelper.ParseBody(body);

            var dialogRequest = new OpenDialogRequest {
                TriggerId = parameters["trigger_id"],
                Dialog    = DialogHelpers.GetProposeDialog(defaultName: parameters["text"])
            };

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

            return(Utils.Ok());
        }
Esempio n. 3
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());
        }
Esempio n. 4
0
        private static async Task <IActionResult> ProcessPlanAction(IBinder binder, InteractiveMessagePayload payload)
        {
            var plans = await binder.GetTable("plans");

            var action = payload.Actions.First();
            var plan   = await plans.Retrieve <Plan>(payload.PartitionKey, action.Value);

            if (plan == null)
            {
                return(Utils.Ok(new SlackMessage {
                    Text = "Oups! Ce Lunch & Watch ne semble plus exister.",
                    Attachments = { MessageHelpers.GetRemoveMessageAttachment() }
                }));
            }

            if (action.Name == "volunteer")
            {
                if (!string.IsNullOrWhiteSpace(plan.Owner))
                {
                    var message = new PostEphemeralRequest {
                        User        = payload.User.Id,
                        Channel     = payload.Channel.Id,
                        Text        = $"<@{plan.Owner}> est déjà responsable de ce Lunch & Watch.",
                        Attachments = new List <MessageAttachment> {
                            MessageHelpers.GetRemoveMessageAttachment()
                        }
                    };
                    await SlackHelper.PostEphemeral(binder, payload.Team.Id, message);

                    return(await UpdatePlanMessage(binder, payload, plan, ""));
                }

                plan.Owner = payload.User.Id;

                var result = await plans.ExecuteAsync(TableOperation.Replace(plan));

                if (result.IsError())
                {
                    await MessageHelpers.PostErrorMessage(binder, payload);

                    return(await UpdatePlanMessage(binder, payload, plan, ""));
                }

                if (plan.Date.Date == DateTime.Today && DateTime.Now.TimeOfDay >= TimeSpan.Parse("11:30"))
                {
                    var message = await MessageHelpers.GetPrepareVideoReminder(binder, plan);

                    await SlackHelper.PostMessage(binder, plan.Team, message);
                }

                return(await UpdatePlanMessage(binder, payload, plan, "Merci!"));
            }

            if (action.Name == "vote")
            {
                if (!string.IsNullOrWhiteSpace(plan.Video))
                {
                    return(Utils.Ok(new SlackMessage {
                        Text = "Le vidéo a déjà été sélectionné pour ce Lunch & Watch.",
                        Attachments = { MessageHelpers.GetRemoveMessageAttachment() }
                    }));
                }

                try
                {
                    var dialogRequest = new OpenDialogRequest {
                        TriggerId = payload.TriggerId,
                        Dialog    = await DialogHelpers.GetVoteDialog(binder, payload.PartitionKey, action.Value, payload.User.Id)
                    };

                    await SlackHelper.OpenDialog(binder, payload.Team.Id, dialogRequest);
                }
                catch (NoAvailableVideosException)
                {
                    return(Utils.Ok(new SlackMessage {
                        Text = "Oups! Aucun vidéo n'a été proposé. Proposez un vidéo avec /edu:propose.",
                        Attachments = { MessageHelpers.GetRemoveMessageAttachment() }
                    }));
                }
            }

            return(Utils.Ok());
        }