/// <summary>
        ///  Handle message extension submit action task received by the bot.
        /// </summary>
        /// <param name="turnContext">Context object containing information cached for a single turn of conversation with a user.</param>
        /// <param name="action">Messaging extension action value payload.</param>
        /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
        /// <returns>Response of messaging extension action.</returns>
        /// <remarks>
        /// Reference link: https://docs.microsoft.com/en-us/dotnet/api/microsoft.bot.builder.teams.teamsactivityhandler.onteamsmessagingextensionfetchtaskasync?view=botbuilder-dotnet-stable.
        /// </remarks>
        protected override async Task <MessagingExtensionActionResponse> OnTeamsMessagingExtensionSubmitActionAsync(
            ITurnContext <IInvokeActivity> turnContext,
            MessagingExtensionAction action,
            CancellationToken cancellationToken)
        {
            AddConversationReference(turnContext.Activity as Activity);
            var asJobject   = JObject.FromObject(action.Data);
            var title       = (string)asJobject.ToObject <TaskDetails <string> >()?.Title;
            var description = (string)asJobject.ToObject <TaskDetails <string> >()?.Description;
            var dateTime    = (DateTime)asJobject.ToObject <TaskDetails <DateTime> >()?.DateTime;

            var date = dateTime.ToLocalTime();

            var currentTaskList            = new List <SaveTaskDetail>();
            List <SaveTaskDetail> taskList = new List <SaveTaskDetail>();

            _taskDetails.TryGetValue("taskDetails", out currentTaskList);

            var taskDetails = new SaveTaskDetail()
            {
                Description = description,
                Title       = title,
                DateTime    = new DateTimeOffset(date.Year, date.Month, date.Day, date.Hour, date.Minute, 0, TimeSpan.Zero),
            };

            if (currentTaskList == null)
            {
                taskList.Add(taskDetails);
                _taskDetails.AddOrUpdate("taskDetails", taskList, (key, newValue) => taskList);
            }
            else
            {
                currentTaskList.Add(taskDetails);
                _taskDetails.AddOrUpdate("taskDetails", currentTaskList, (key, newValue) => currentTaskList);
            }

            TaskScheduler taskSchedule = new TaskScheduler();

            taskSchedule.Start(date.Year, date.Month, date.Day, date.Hour, date.Minute, _applicationBaseUrl);
            await turnContext.SendActivityAsync("Task submitted successfully. You will get reminder for the task at scheduled time");

            return(null);
        }
Esempio n. 2
0
        /// <summary>
        /// Handle task module is submit.
        /// </summary>
        /// <param name = "turnContext" > The turn context.</param>
        /// <param name = "taskModuleRequest" >The task module invoke request value payload.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>A Task Module Response for the request.</returns>
        protected override async Task <TaskModuleResponse> OnTeamsTaskModuleSubmitAsync(ITurnContext <IInvokeActivity> turnContext, TaskModuleRequest taskModuleRequest, CancellationToken cancellationToken)
        {
            var asJobject          = JObject.FromObject(taskModuleRequest.Data);
            var title              = (string)asJobject.ToObject <TaskDetails <string> >()?.Title;
            var description        = (string)asJobject.ToObject <TaskDetails <string> >()?.Description;
            var dateTime           = (DateTime)asJobject.ToObject <TaskDetails <DateTime> >()?.DateTime;
            var selectedDaysObject = (JArray)asJobject.ToObject <TaskDetails <JArray> >()?.SelectedDays;
            var selectedDays       = selectedDaysObject.ToObject <DayOfWeek[]>();
            var date = dateTime.ToLocalTime();

            var recurringDays              = string.Join(",", selectedDays);
            var currentTaskList            = new List <SaveTaskDetail>();
            List <SaveTaskDetail> taskList = new List <SaveTaskDetail>();

            _taskDetails.TryGetValue("taskDetails", out currentTaskList);

            var taskDetails = new SaveTaskDetail()
            {
                Description  = description,
                Title        = title,
                DateTime     = new DateTimeOffset(date.Year, date.Month, date.Day, date.Hour, date.Minute, 0, TimeSpan.Zero),
                SelectedDays = selectedDays
            };

            if (currentTaskList == null)
            {
                taskList.Add(taskDetails);
                _taskDetails.AddOrUpdate("taskDetails", taskList, (key, newValue) => taskList);
            }
            else
            {
                currentTaskList.Add(taskDetails);
                _taskDetails.AddOrUpdate("taskDetails", currentTaskList, (key, newValue) => currentTaskList);
            }

            TaskScheduler taskSchedule = new TaskScheduler();

            taskSchedule.Start(date.Hour, date.Minute, _applicationBaseUrl, selectedDays);
            await turnContext.SendActivityAsync("Task submitted successfully, you will get a recurring reminder for the task at a scheduled time");

            return(null);
        }