public static async Task PrepareVideoReminder( [TimerTrigger("0 30 11 * * *")] TimerInfo timer, //11:30 daily [Table("plans")] CloudTable plansTable, IBinder binder) { Utils.SetCulture(); var plans = await GetTodayPlansWithVideoAndResponsible(plansTable); foreach (var plan in plans) { var message = await MessageHelpers.GetPrepareVideoReminder(binder, plan); await SlackHelper.PostMessage(binder, plan.Team, message); } }
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()); }