コード例 #1
0
        public HttpResponseMessage HandleFetchTaskAction(HttpRequestMessage request, string commandId)
        {
            if (string.Equals(commandId, MessagingExtensionCommands.OpenNewPosition, StringComparison.OrdinalIgnoreCase))
            {
                var card = _templateService.GetAdaptiveCardForNewJobPosting();

                var response = new TaskModuleResponseEnvelope
                {
                    Task = new TaskModuleContinueResponse
                    {
                        Type  = "continue",
                        Value = new TaskModuleTaskInfo
                        {
                            Card   = card.ToAttachment(),
                            Title  = "Create new job posting",
                            Width  = "large",
                            Height = "large"
                        }
                    }
                };

                return(request.CreateResponse(HttpStatusCode.OK, response));
            }

            return(request.CreateResponse(HttpStatusCode.NotFound));
        }
コード例 #2
0
        public void TaskModuleTests_CustomForm()
        {
            TaskModuleResponseEnvelope currentTaskModuleEnvelope = new TaskModuleResponseEnvelope
            {
                Task = new TaskModuleContinueResponse
                {
                    Type  = "continue",
                    Value = new TaskModuleTaskInfo()
                    {
                        Title       = "Custom Form",
                        Height      = 510,
                        Width       = 430,
                        Url         = "https://contoso.com/teamsapp/customform",
                        FallbackUrl = "https://contoso.com/teamsapp/customform"
                    }
                }
            };

            var expectedTaskModuleEnvelope = JObject.Parse(File.ReadAllText(@"Jsons\SampleTaskModuleCustomFormPayload.json"));

            Assert.IsTrue(expectedTaskModuleEnvelope != null);
            var currentTaskJObject = JObject.FromObject(currentTaskModuleEnvelope, new JsonSerializer()
            {
                NullValueHandling = NullValueHandling.Ignore
            });

            Assert.IsTrue(JObject.DeepEquals(currentTaskJObject, expectedTaskModuleEnvelope));
        }
コード例 #3
0
        public void TaskModuleTests_Message()
        {
            TaskModuleResponseEnvelope currentTaskModuleEnvelope = new TaskModuleResponseEnvelope
            {
                Task = new TaskModuleMessageResponse
                {
                    Type  = "message",
                    Value = "This is a test message"
                }
            };

            var expectedTaskModuleEnvelope = JObject.Parse(File.ReadAllText(@"Jsons\SampleTaskModuleMessagePayload.json"));

            Assert.IsTrue(expectedTaskModuleEnvelope != null);
            Assert.IsTrue(JObject.DeepEquals(JObject.FromObject(currentTaskModuleEnvelope), expectedTaskModuleEnvelope));
        }
コード例 #4
0
        public void TaskModuleTests_AdaptiveCard()
        {
            AdaptiveCards.AdaptiveCard currentAdaptiveCard = new AdaptiveCards.AdaptiveCard();
            currentAdaptiveCard.Body.Add(new AdaptiveCards.AdaptiveTextBlock("some text on card"));

            var action = new AdaptiveCards.AdaptiveOpenUrlAction();

            action.Url = new Uri("https://microsoft.com");
            currentAdaptiveCard.Actions.Add(action);

            TaskModuleResponseEnvelope currentTaskModuleEnvelope = new TaskModuleResponseEnvelope
            {
                Task = new TaskModuleContinueResponse
                {
                    Value = new TaskModuleTaskInfo()
                    {
                        Title  = "Adaptive Card: Inputs",
                        Card   = currentAdaptiveCard.ToAttachment(),
                        Height = "small",
                        Width  = "small",
                    },
                    Type = "continue",
                }
            };

            var inputJson = File.ReadAllText(@"Jsons\SampleTaskModuleAdaptiveCardPayload.json");
            var expectedTaskModuleEnvelope = JObject.Parse(inputJson);

            Assert.IsTrue(expectedTaskModuleEnvelope != null);
            Assert.IsTrue(expectedTaskModuleEnvelope["task"] != null);
            Assert.IsTrue(expectedTaskModuleEnvelope["task"]["type"].ToString() == currentTaskModuleEnvelope.Task.Type);

            var expected = JsonConvert.DeserializeObject <TaskModuleTaskInfo>(expectedTaskModuleEnvelope["task"]["value"].ToString());
            var current  = (currentTaskModuleEnvelope.Task as TaskModuleContinueResponse).Value as TaskModuleTaskInfo;

            Assert.AreEqual(expected.Width, current.Width);
            Assert.AreEqual(expected.Title, current.Title);
            Assert.AreEqual(expected.Card.ContentType, current.Card.ContentType);
        }
        /// <summary>
        /// Handle request to fetch task module content.
        /// </summary>
        private async Task <HttpResponseMessage> HandleTaskModuleFetchRequest(Activity activity, string activityValue)
        {
            var action = JsonConvert.DeserializeObject <TaskModule.TaskModuleActionData <ActionDetails> >(activityValue);

            var channelData = activity.GetChannelData <TeamsChannelData>();
            var tenantId    = channelData.Tenant.Id;

            // Default to common parameters for task module
            var taskInfo = new TaskModuleTaskInfo()
            {
                Title  = ApplicationSettings.AppName,
                Height = 900,
                Width  = 600,
            };

            // Populate the task module content, based on the kind of dialog requested
            Attachment card = null;

            switch (action.Data.Data.ActionType)
            {
            case Constants.CreateOrEditAnnouncement:
                taskInfo.Title = "Create New";
                card           = await CardHelper.GetCreateNewAnnouncementCard(tenantId);

                break;

            case Constants.ShowMoreDetails:
                taskInfo.Title = "Details";
                var showDetails = JsonConvert.DeserializeObject <TaskModule.TaskModuleActionData <AnnouncementActionDetails> >(activityValue);
                card = await CardHelper.GetPreviewAnnouncementCard(showDetails.Data.Data.Id);

                taskInfo.Height = 900;
                taskInfo.Width  = 600;

                break;

            case Constants.ShowEditAnnouncementTaskModule:
                taskInfo.Title = "Edit a message";
                var editAnnouncement = JsonConvert.DeserializeObject <TaskModule.TaskModuleActionData <AnnouncementActionDetails> >(activityValue);

                var campaign = await Cache.Announcements.GetItemAsync(editAnnouncement.Data.Data.Id);

                if (campaign == null || campaign.Status == Status.Sent)
                {
                    card            = CardHelper.GetUpdateMessageCard($"This {Helper.ApplicationSettings.AppFeature} is already sent and not allowed to edit.");
                    taskInfo.Height = 100;
                    taskInfo.Width  = 500;
                }
                else
                {
                    card = await CardHelper.GetEditAnnouncementCard(editAnnouncement.Data.Data.Id, tenantId);
                }
                break;

            default:
                break;
            }

            taskInfo.Card = card;
            TaskModuleResponseEnvelope taskModuleEnvelope = new TaskModuleResponseEnvelope
            {
                Task = new TaskModuleContinueResponse
                {
                    Type  = "continue",
                    Value = taskInfo
                }
            };

            return(Request.CreateResponse(HttpStatusCode.OK, taskModuleEnvelope));
        }