Ejemplo n.º 1
0
        private static async Task <IActionResult> UpdatePlanMessage(IBinder binder, InteractiveMessagePayload payload, Plan plan, string ephemeralText)
        {
            if (payload.OriginalMessage != null)
            {
                // Message publique

                var message = new UpdateMessageRequest {
                    Text        = payload.OriginalMessage.Text,
                    Channel     = payload.Channel.Id,
                    Timestamp   = payload.MessageTimestamp,
                    Attachments = { await MessageHelpers.GetPlanAttachment(binder, plan) }
                };

                await SlackHelper.UpdateMessage(binder, payload.Team.Id, message);

                return(Utils.Ok());
            }
            else
            {
                // Message ephémère

                var message = new SlackMessage {
                    Text            = ephemeralText,
                    Attachments     = { await MessageHelpers.GetPlanAttachment(binder, plan) },
                    ReplaceOriginal = true
                };

                message.Attachments.Add(MessageHelpers.GetRemoveMessageAttachment());
                return(Utils.Ok(message));
            }
        }
Ejemplo n.º 2
0
        public static async Task <IActionResult> OnNext(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "slack/commands/next")] HttpRequest req,
            [Table("plans")] CloudTable plansTable,
            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 futurePlansQuery = new TableQuery <Plan>()
                                   .Where(
                TableQuery.CombineFilters(
                    TableQuery.GenerateFilterCondition("PartitionKey", "eq", partitionKey),
                    "and",
                    TableQuery.GenerateFilterConditionForDate("Date", "ge", DateTime.Now))
                );
            var futurePlans = await plansTable.ExecuteQueryAsync(futurePlansQuery);

            var attachmentTasks = futurePlans.OrderBy(x => x.Date).Select(x => MessageHelpers.GetPlanAttachment(binder, x));
            var message         = new SlackMessage {
                Text = futurePlans.Any()
                    ? "Voici les Lunch & Watch planifiés :"
                    : "Aucun Lunch & Watch n'est à l'horaire. Utilisez `/edu:plan` pour en planifier un!",
                Attachments = (await Task.WhenAll(attachmentTasks)).ToList()
            };

            message.Attachments.Add(MessageHelpers.GetRemoveMessageAttachment());

            return(Utils.Ok(message));
        }
Ejemplo n.º 3
0
        public static async Task PlanResponsibleFinalReminder(
            [TimerTrigger("0 55 11 * * *")] TimerInfo timer, // 11:55AM daily
            [Table("plans")] CloudTable plansTable,
            IBinder binder)
        {
            Utils.SetCulture();

            var plans = await GetTodayPlansWithoutResponsible(plansTable);

            foreach (var plan in plans)
            {
                await SlackHelper.PostMessage(binder, plan.Team, new PostMessageRequest {
                    Channel     = plan.Channel,
                    Text        = "<!channel> *Dernier rappel*: Le Lunch & Watch de ce midi a besoin d'un responsable! Si personne ne se manifeste, l'événement sera annulé.",
                    Attachments = { await MessageHelpers.GetPlanAttachment(binder, plan) }
                });
            }
        }
Ejemplo n.º 4
0
        public static async Task PlanResponsibleSecondReminder(
            [TimerTrigger("0 15 11 * * *")] TimerInfo timer, // 11:15AM daily
            [Table("plans")] CloudTable plansTable,
            IBinder binder)
        {
            Utils.SetCulture();

            var plans = await GetTodayPlansWithoutResponsible(plansTable);

            foreach (var plan in plans)
            {
                await SlackHelper.PostMessage(binder, plan.Team, new PostMessageRequest {
                    Channel     = plan.Channel,
                    Text        = "<!channel> Rappel: Le Lunch & Watch de ce midi a besoin d'un responsable!",
                    Attachments = { await MessageHelpers.GetPlanAttachment(binder, plan) }
                });
            }
        }
Ejemplo n.º 5
0
        private static async Task RecordPlan(IBinder binder, DialogSubmissionPayload planPayload)
        {
            var plans = await binder.GetTable("plans");

            var proposals = await binder.GetTable("proposals");

            var videoKey = planPayload.GetValue("video");

            if (!string.IsNullOrWhiteSpace(videoKey))
            {
                var proposal = await proposals.Retrieve <Proposal>(planPayload.State, videoKey);

                if (proposal == null)
                {
                    await MessageHelpers.PostErrorMessage(binder, planPayload, "Vidéo non trouvé");

                    return;
                }

                if (!string.IsNullOrWhiteSpace(proposal.PlannedIn))
                {
                    var otherPlan = await plans.Retrieve <Plan>(planPayload.State, proposal.PlannedIn);

                    if (otherPlan != null)
                    {
                        await MessageHelpers.PostErrorMessage(binder, planPayload, $"Ce vidéo est déjà planifié pour le {otherPlan.Date:dddd d MMMM}.");

                        return;
                    }
                }

                proposal.PlannedIn = planPayload.ActionTimestamp;

                var proposalResult = await proposals.ExecuteAsync(TableOperation.Replace(proposal));

                if (proposalResult.IsError())
                {
                    await MessageHelpers.PostErrorMessage(binder, planPayload);

                    return;
                }
            }

            var plan = new Plan {
                PartitionKey = planPayload.State,
                RowKey       = planPayload.ActionTimestamp,
                CreatedBy    = planPayload.User.Id,
                Team         = planPayload.Team.Id,
                Channel      = Utils.GetChannelFromPartitionKey(planPayload.State),
                Date         = Utils.ParseDate(planPayload.GetValue("date")).AddHours(12),
                Owner        = planPayload.GetValue("owner") ?? "",
                Video        = videoKey ?? ""
            };

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

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

                return;
            }

            var message = new PostMessageRequest {
                Text        = $"<@{planPayload.User.Id}> vient de planifier un Lunch & Watch :",
                Channel     = Utils.GetChannelFromPartitionKey(planPayload.State),
                Attachments = { await MessageHelpers.GetPlanAttachment(binder, plan) }
            };

            await SlackHelper.PostMessage(binder, planPayload.Team.Id, message);

            await binder.RecordChannelActivity(planPayload.Team.Id, planPayload.Channel.Id);
        }
Ejemplo n.º 6
0
        public static async Task PlanReminder(
            [TimerTrigger("0 0 9 * * *")] TimerInfo timer, // 9:00AM daily
            [Table("plans")] CloudTable plansTable,
            IBinder binder)
        {
            Utils.SetCulture();

            var today        = DateTime.Today;
            var withoutVideo = TableQuery.GenerateFilterCondition("Video", "eq", "");

            // Lundi: Initier le vote pour les vidéos de cette semaine (sauf si aujourd'hui)
            if (today.DayOfWeek == DayOfWeek.Monday)
            {
                var weeksPlans = await PlanHelpers.GetPlansBetween(plansTable, today.AddDays(1), today.AddDays(5), withoutVideo);

                foreach (var plan in weeksPlans)
                {
                    await SendMessage(plan);
                }
            }
            // Vendredi: Initier le vote pour les vidéos de lundi prochain
            if (today.DayOfWeek == DayOfWeek.Friday)
            {
                var mondaysPlans = await PlanHelpers.GetPlansForDate(plansTable, today.AddDays(3), withoutVideo);

                foreach (var plan in mondaysPlans)
                {
                    await SendMessage(plan);
                }
            }

            // Rappel du lunch & watch d'aujourd'hui
            var todaysPlans = await PlanHelpers.GetPlansForDate(plansTable, today);

            foreach (var plan in todaysPlans)
            {
                await SendMessage(plan);
            }

            async Task SendMessage(Plan plan)
            {
                var isToday = plan.Date.Date == today;

                string message = null;

                if (isToday)
                {
                    message = "Rappel: Il y a un Lunch & Watch ce midi!";
                    if (string.IsNullOrWhiteSpace(plan.Video))
                    {
                        message += " Votez pour le vidéo si ce n'est pas déjà fait! Vous avez jusqu'à 11h pour choisir.";
                    }
                    if (string.IsNullOrWhiteSpace(plan.Owner))
                    {
                        message += "\n\nIl n'y a pas encore de responsable pour préparer le vidéo. Cliquez sur _Je m'en occupe_ pour vous porter volontaire!";
                    }
                }
                else
                {
                    if (string.IsNullOrWhiteSpace(plan.Video))
                    {
                        message = "C'est le moment de voter pour le vidéo de ce Lunch & Watch :";
                    }
                }

                if (string.IsNullOrWhiteSpace(message))
                {
                    return;
                }

                await SlackHelper.PostMessage(binder, plan.Team, new PostMessageRequest {
                    Channel     = plan.Channel,
                    Text        = message,
                    Attachments = { await MessageHelpers.GetPlanAttachment(binder, plan) }
                });
            }
        }