public async Task <MessagingExtensionActionResponse> Handle(Activity activity)
        {
            var editForm = GetEditForm(activity);

            var localPlannedDrawTime = _dateTimeService.UtcNow.AddHours(2).ToOffset(activity.GetOffset());

            if (!string.IsNullOrEmpty(editForm.PlannedDrawTimeLocalDate) && !string.IsNullOrEmpty(editForm.PlannedDrawTimeLocalTime))
            {
                var dateTime = DateTime.Parse(editForm.PlannedDrawTimeLocalDate + "T" + editForm.PlannedDrawTimeLocalTime, CultureInfo.InvariantCulture);
                localPlannedDrawTime = new DateTimeOffset(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, dateTime.Minute, 0, activity.GetOffset());
            }

            var card     = _activityBuilder.CreateComposeEditForm(editForm.Gift, int.Parse(editForm.WinnerCount), editForm.GiftImageUrl, localPlannedDrawTime, string.Empty, activity.Locale);
            var taskInfo = new TaskModuleContinueResponse
            {
                Type  = "continue",
                Value = new TaskModuleTaskInfo
                {
                    Title = string.Empty,
                    Card  = card
                }
            };

            var response = new MessagingExtensionActionResponse {
                Task = taskInfo
            };

            return(await Task.FromResult(response));
        }
Beispiel #2
0
        public async Task <object> Handle(Activity activity)
        {
            var data                 = ((JObject)activity.Value).GetValue("data");
            var editForm             = JsonSerializer.Deserialize <CompetitionEditForm>(Newtonsoft.Json.JsonConvert.SerializeObject(data));
            var plannedDrawTime      = editForm.GetPlannedDrawTime(activity.GetOffset(), _dateTimeService.UtcNow.AddHours(2));
            var localPlannedDrawTime = plannedDrawTime.ToOffset(activity.GetOffset());

            var errorMessage = CanPreviewCompetition(editForm.Gift, int.Parse(editForm.WinnerCount), plannedDrawTime, editForm.GiftImageUrl, activity.Locale);

            if (string.IsNullOrEmpty(errorMessage))
            {
                var card    = _activityBuilder.CreatePreviewCard(editForm, localPlannedDrawTime, activity.Locale);
                var preview = MessageFactory.Attachment(card) as Activity;
                preview.Value = editForm;
                var response = new MessagingExtensionActionResponse
                {
                    ComposeExtension = new MessagingExtensionResult
                    {
                        Type            = "botMessagePreview",
                        ActivityPreview = preview
                    }
                };
                return(await Task.FromResult(response));
            }
            else
            {
                var card     = _activityBuilder.CreateComposeEditForm(editForm.Gift, int.Parse(editForm.WinnerCount), editForm.GiftImageUrl, localPlannedDrawTime, errorMessage, activity.Locale);
                var taskInfo = new TaskModuleContinueResponse
                {
                    Type  = "continue",
                    Value = new TaskModuleTaskInfo
                    {
                        Title = string.Empty,
                        Width = "medium",
                        Card  = card
                    }
                };
                var response = new MessagingExtensionActionResponse {
                    Task = taskInfo
                };
                return(await Task.FromResult(response));
            }
        }
Beispiel #3
0
        public async Task <MessagingExtensionActionResponse> Handle(Activity activity)
        {
            var localPlannedDrawTime = _dateTimeService.UtcNow.AddHours(2).ToOffset(TimeSpan.FromHours(activity.GetOffset().TotalHours));
            var card     = _activityBuilder.CreateComposeEditForm(string.Empty, 1, string.Empty, localPlannedDrawTime, string.Empty, activity.Locale);
            var taskInfo = new TaskModuleContinueResponse
            {
                Type  = "continue",
                Value = new TaskModuleTaskInfo
                {
                    Title = string.Empty,
                    Width = "medium",
                    Card  = card
                }
            };

            var response = new MessagingExtensionActionResponse {
                Task = taskInfo
            };

            return(await Task.FromResult(response));
        }