public static AdaptiveCard CreateAdaptiveCardTaskModule()
        {
            var taskModuleAction = new TaskModuleAction("Launch Task Module", @"{ ""hiddenKey"": ""hidden value from task module launcher"" }");

            var adaptiveCard = new AdaptiveCard(new AdaptiveSchemaVersion(1, 2));

            adaptiveCard.Body.Add(new AdaptiveTextBlock("Task Module Adaptive Card"));
            adaptiveCard.Actions.Add(taskModuleAction.ToAdaptiveCardAction());

            return(adaptiveCard);
        }
        private async Task SendAdaptiveCard2Async(ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken)
        {
            var taskModuleAction = new TaskModuleAction("Launch Task Module", @"{ ""hiddenKey"": ""hidden value from task module launcher"" }");

            var adaptiveCard = new AdaptiveCard();

            adaptiveCard.Body.Add(new AdaptiveTextBlock("Task Module Adaptive Card"));
            adaptiveCard.Actions.Add(taskModuleAction.ToAdaptiveCardAction());

            var replyActivity = MessageFactory.Attachment(adaptiveCard.ToAttachment());
            await turnContext.SendActivityAsync(replyActivity, cancellationToken);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Handles the message activity asynchronously.
        /// </summary>
        /// <param name="turnContext">The turn context.</param>
        /// <returns>Task tracking operation.</returns>
        public async Task HandleMessageAsync(ITurnContext turnContext)
        {
            ITeamsContext teamsContext = turnContext.TurnState.Get <ITeamsContext>();

            string actualText = teamsContext.GetActivityTextWithoutMentions();

            if (actualText.Equals("Cards", StringComparison.OrdinalIgnoreCase))
            {
                // Demo card 1 - adaptive card with bot bulder actions
                AdaptiveCards.AdaptiveCard adaptiveCard = new AdaptiveCards.AdaptiveCard();
                adaptiveCard.Body.Add(new AdaptiveCards.AdaptiveTextBlock("Bot Builder actions"));

                var action1 = new CardAction("imback", "imBack", null, null, null, "text");
                var action2 = new CardAction("messageBack", "message back", null, "text received by bots", "text display to users", JObject.Parse(@"{ ""key"" : ""value"" }"));
                var action3 = new CardAction("invoke", "invoke", null, null, null, JObject.Parse(@"{ ""key"" : ""value"" }"));
                adaptiveCard.Actions.Add(action1.ToAdaptiveCardAction());
                adaptiveCard.Actions.Add(action2.ToAdaptiveCardAction());
                adaptiveCard.Actions.Add(action3.ToAdaptiveCardAction());

                // Task module action
                var taskModuleAction = new TaskModuleAction("Launch Task Module", @"{ ""hiddenKey"": ""hidden value from task module launcher"" }");

                // Demo card 2 - launch task module from adaptive card
                AdaptiveCards.AdaptiveCard taskModuleCard1 = new AdaptiveCards.AdaptiveCard();
                taskModuleCard1.Body.Add(new AdaptiveCards.AdaptiveTextBlock("Task Module Adaptive Card"));
                taskModuleCard1.Actions.Add(taskModuleAction.ToAdaptiveCardAction());

                // Demo card 3 - launch task module from hero card (or any bot-builder framework card)
                HeroCard taskModuleCard2 = new HeroCard("Launch Task Module", null, null, null, new List <CardAction> {
                    taskModuleAction
                });

                Activity replyActivity = turnContext.Activity.CreateReply();
                replyActivity.Attachments = new List <Attachment>()
                {
                    adaptiveCard.ToAttachment(),
                        taskModuleCard1.ToAttachment(),
                        taskModuleCard2.ToAttachment(),
                };
                await turnContext.SendActivityAsync(replyActivity).ConfigureAwait(false);
            }
            else
            {
                Activity replyActivity = turnContext.Activity.CreateReply();
                replyActivity.TextFormat = "xml";
                replyActivity.Text       = $"You said: {turnContext.Activity.Text}";
                await turnContext.SendActivityAsync(replyActivity).ConfigureAwait(false);
            }
        }
        public void TaskModuleActionInits(string title, object value)
        {
            if ((string)value == "makeJObject")
            {
                value = new JObject();
            }

            var action      = new TaskModuleAction(title, value);
            var expectedKey = "type";
            var expectedVal = "task/fetch";

            Assert.NotNull(action);
            Assert.IsType <TaskModuleAction>(action);
            Assert.Equal(title, action.Title);
            var valAsObj = JObject.Parse(action.Value as string);

            Assert.True(valAsObj.ContainsKey(expectedKey));
            Assert.Equal(expectedVal, valAsObj[expectedKey]);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Get list card attachment having list of favorite rooms along with buttons to manage favorites, book meeting for other rooms and refresh list.
        /// </summary>
        /// <param name="rooms">Rooms schedule response object.</param>
        /// <param name="startUTCDateTime">Start date time of meeting.</param>
        /// <param name="endUTCDateTime">End date time of meeting.</param>
        /// <param name="timeZone">User time zone.</param>
        /// <param name="activityReferenceId">Unique GUID related to activity Id from ActivityEntities table.</param>
        /// <returns>List card attachment having favorite rooms of user.</returns>
        public static Attachment GetFavoriteRoomsListAttachment(RoomScheduleResponse rooms, DateTime startUTCDateTime, DateTime endUTCDateTime, string timeZone, string activityReferenceId = null)
        {
            ListCard card = new ListCard
            {
                Title   = Strings.RoomAvailability,
                Items   = new List <ListItem>(),
                Buttons = new List <CardAction>(),
            };

            // For first run, user configuration will be null.
            if (timeZone != null)
            {
                var startTime = TimeZoneInfo.ConvertTimeFromUtc(startUTCDateTime, TimeZoneInfo.FindSystemTimeZoneById(timeZone));
                var endTime   = TimeZoneInfo.ConvertTimeFromUtc(endUTCDateTime, TimeZoneInfo.FindSystemTimeZoneById(timeZone));
                card.Title = string.Format(CultureInfo.CurrentCulture, "{0} | {1} - {2}", Strings.RoomAvailability, startTime.ToString("t", CultureInfo.CurrentCulture), endTime.ToString("t", CultureInfo.CurrentCulture));
            }

            ListItem room = new ListItem();
            Meeting  meeting;

            if (rooms.Schedules.Count > 0)
            {
                foreach (var item in rooms.Schedules)
                {
                    var availability      = item.ScheduleItems.Count > 0 ? Strings.Unavailable : Strings.Available;
                    var availabilityColor = item.ScheduleItems.Count > 0 ? RedColorCode : GreenColorCode;
                    var subtitle          = string.Format(CultureInfo.CurrentCulture, "{0}&nbsp;|&nbsp;<b><font color='{1}'>{2}</font></b>", item.BuildingName, availabilityColor, availability);

                    meeting = new Meeting
                    {
                        EndDateTime   = DateTime.SpecifyKind(endUTCDateTime, DateTimeKind.Utc).ToString("o"),
                        RoomEmail     = item.ScheduleId,
                        RoomName      = item.RoomName,
                        StartDateTime = DateTime.SpecifyKind(startUTCDateTime, DateTimeKind.Utc).ToString("o"),
                        BuildingName  = item.BuildingName,
                        Status        = availability,
                        Text          = BotCommands.CreateMeeting,
                    };

                    card.Items.Add(new ListItem
                    {
                        Id       = item.ScheduleId,
                        Title    = item.RoomName,
                        Subtitle = subtitle,
                        Type     = "person",
                        Tap      = new CardAction {
                            Type = ActionTypes.MessageBack, DisplayText = string.Empty, Title = BotCommands.CreateMeeting, Value = JsonConvert.SerializeObject(meeting)
                        },
                    });
                }
            }
            else
            {
                room = new ListItem
                {
                    Title = Strings.NoFavoriteRooms,
                    Type  = "section",
                };
            }

            card.Items.Add(room);
            CardAction addFavoriteButton = new TaskModuleAction(Strings.ManageFavorites, new { data = JsonConvert.SerializeObject(new AdaptiveTaskModuleCardAction {
                    Text = BotCommands.ShowFavoriteTaskModule, ActivityReferenceId = activityReferenceId
                }) });

            card.Buttons.Add(addFavoriteButton);

            CardAction otherRoomButton = new TaskModuleAction(Strings.OtherRooms, new { data = JsonConvert.SerializeObject(new AdaptiveTaskModuleCardAction {
                    Text = BotCommands.ShowOtherRoomsTaskModule, ActivityReferenceId = activityReferenceId
                }) });

            card.Buttons.Add(otherRoomButton);

            if (rooms?.Schedules.Count > 0)
            {
                CardAction refreshListButton = new CardAction
                {
                    Title       = Strings.Refresh,
                    Type        = ActionTypes.MessageBack,
                    Text        = BotCommands.RefreshList,
                    DisplayText = string.Empty,
                    Value       = JsonConvert.SerializeObject(new AdaptiveTaskModuleCardAction {
                        Text = BotCommands.RefreshList, ActivityReferenceId = activityReferenceId
                    }),
                };

                card.Buttons.Add(refreshListButton);
            }

            var attachment = new Attachment()
            {
                ContentType = "application/vnd.microsoft.teams.card.list",
                Content     = card,
            };

            return(attachment);
        }
Exemplo n.º 6
0
        /*
         * You can @mention the bot the text "1", "2", or "3". "1" will send back adaptive cards. "2" will send back a
         * task module that contains an adpative card. "3" will return an adpative card that contains BF card actions.
         *
         */
        protected override async Task OnMessageActivityAsync(ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken)
        {
            if (turnContext.Activity.Text != null)
            {
                turnContext.Activity.RemoveRecipientMention();
                string actualText = turnContext.Activity.Text;

                if (actualText.Equals("1"))
                {
                    var adaptiveCard = new AdaptiveCard();
                    adaptiveCard.Body.Add(new AdaptiveTextBlock("Bot Builder actions"));

                    var action1 = new CardAction(ActionTypes.ImBack, "imBack", null, null, null, "text");
                    var action2 = new CardAction(ActionTypes.MessageBack, "message back", null, null, null, JObject.Parse(@"{ ""key"" : ""value"" }"));
                    var action3 = new CardAction(ActionTypes.MessageBack, "message back local echo", null, "text received by bots", "display text message back", JObject.Parse(@"{ ""key"" : ""value"" }"));
                    var action4 = new CardAction("invoke", "invoke", null, null, null, JObject.Parse(@"{ ""key"" : ""value"" }"));

                    adaptiveCard.Actions.Add(action1.ToAdaptiveCardAction());
                    adaptiveCard.Actions.Add(action2.ToAdaptiveCardAction());
                    adaptiveCard.Actions.Add(action3.ToAdaptiveCardAction());
                    adaptiveCard.Actions.Add(action4.ToAdaptiveCardAction());

                    var replyActivity = MessageFactory.Attachment(adaptiveCard.ToAttachment());
                    await turnContext.SendActivityAsync(replyActivity, cancellationToken);
                }
                else if (actualText.Equals("2"))
                {
                    var taskModuleAction = new TaskModuleAction("Launch Task Module", @"{ ""hiddenKey"": ""hidden value from task module launcher"" }");

                    var adaptiveCard = new AdaptiveCard();
                    adaptiveCard.Body.Add(new AdaptiveTextBlock("Task Module Adaptive Card"));
                    adaptiveCard.Actions.Add(taskModuleAction.ToAdaptiveCardAction());

                    var replyActivity = MessageFactory.Attachment(adaptiveCard.ToAttachment());
                    await turnContext.SendActivityAsync(replyActivity, cancellationToken);
                }
                else if (actualText.Equals("3"))
                {
                    var adaptiveCard = new AdaptiveCard();
                    adaptiveCard.Body.Add(new AdaptiveTextBlock("Bot Builder actions"));
                    adaptiveCard.Body.Add(new AdaptiveTextInput {
                        Id = "x"
                    });
                    adaptiveCard.Actions.Add(new AdaptiveSubmitAction {
                        Type = "Action.Submit", Title = "Action.Submit", Data = new JObject {
                            { "key", "value" }
                        }
                    });

                    var replyActivity = MessageFactory.Attachment(adaptiveCard.ToAttachment());
                    await turnContext.SendActivityAsync(replyActivity, cancellationToken);
                }
                else
                {
                    await turnContext.SendActivityAsync(MessageFactory.Text($"You said: {turnContext.Activity.Text}"), cancellationToken);
                }
            }
            else
            {
                await turnContext.SendActivityAsync(MessageFactory.Text($"App sent a message with null text"), cancellationToken);

                // TODO: process the response from the card

                if (turnContext.Activity.Value != null)
                {
                    await turnContext.SendActivityAsync(MessageFactory.Text($"but with value {turnContext.Activity.Value}"), cancellationToken);
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Method to show personal goals details card in personal scope.
        /// </summary>
        /// <param name="applicationBasePath">Application base URL of the application.</param>
        /// <param name="personalGoalDetails">Personal goal values entered by user.</param>
        /// <param name="localizer">The current cultures' string localizer.</param>
        /// <param name="goalCycleId">Goal cycle id to identify that goal cycle is ended or not.</param>
        /// <returns>Returns an attachment of personal goal details card in personal scope.</returns>
        public static Attachment GetPersonalGoalDetailsListCard(string applicationBasePath, IEnumerable <PersonalGoalDetail> personalGoalDetails, IStringLocalizer <Strings> localizer, string goalCycleId)
        {
            personalGoalDetails = personalGoalDetails ?? throw new ArgumentNullException(nameof(personalGoalDetails));
            var goalCycleStartDate = personalGoalDetails.Select(goal => goal.StartDate).First();
            var goalCycleEndDate   = personalGoalDetails.Select(goal => goal.EndDate).First();

            // Start date and end date are stored in storage with user specific time zones.
            goalCycleStartDate = DateTime.Parse(goalCycleStartDate, CultureInfo.CurrentCulture)
                                 .ToString(Constants.ListCardDateTimeFormat, CultureInfo.CurrentCulture);
            goalCycleEndDate = DateTime.Parse(goalCycleEndDate, CultureInfo.CurrentCulture)
                               .ToString(Constants.ListCardDateTimeFormat, CultureInfo.CurrentCulture);

            var      reminder                    = personalGoalDetails.Select(goal => goal.ReminderFrequency).First();
            var      reminderFrequency           = (ReminderFrequency)reminder;
            ListCard personalGoalDetailsListCard = new ListCard
            {
                Title = localizer.GetString("PersonalGoalListCardTitle"),
            };

            personalGoalDetailsListCard.Items.Add(new ListItem
            {
                Title = localizer.GetString("PersonalGoalCardCycleText", goalCycleStartDate, goalCycleEndDate),
                Type  = "section",
            });

            foreach (var personalGoalDetailEntity in personalGoalDetails)
            {
                personalGoalDetailsListCard.Items.Add(new ListItem
                {
                    Id       = personalGoalDetailEntity.PersonalGoalId,
                    Title    = personalGoalDetailEntity.GoalName,
                    Subtitle = reminderFrequency.ToString(),
                    Type     = "resultItem",
                    Tap      = new TaskModuleAction(localizer.GetString("PersonalGoalEditButtonText"), new AdaptiveSubmitAction
                    {
                        Title = localizer.GetString("PersonalGoalEditButtonText"),
                        Data  = new AdaptiveSubmitActionData
                        {
                            AdaptiveActionType = Constants.EditPersonalGoalsCommand,
                            GoalCycleId        = goalCycleId,
                        },
                    }),
                    Icon = $"{applicationBasePath}/Artifacts/listIcon.png",
                });
            }

            CardAction editButton = new TaskModuleAction(localizer.GetString("PersonalGoalEditButtonText"), new AdaptiveSubmitAction
            {
                Data = new AdaptiveSubmitActionData
                {
                    AdaptiveActionType = Constants.EditPersonalGoalsCommand,
                    GoalCycleId        = goalCycleId,
                },
            });

            personalGoalDetailsListCard.Buttons.Add(editButton);

            CardAction addNoteButton = new TaskModuleAction(localizer.GetString("PersonalGoalAddNoteButtonText"), new AdaptiveSubmitAction
            {
                Data = new AdaptiveSubmitActionData
                {
                    AdaptiveActionType = Constants.AddNoteCommand,
                    GoalCycleId        = goalCycleId,
                },
            });

            personalGoalDetailsListCard.Buttons.Add(addNoteButton);

            var personalGoalsListCard = new Attachment()
            {
                ContentType = "application/vnd.microsoft.teams.card.list",
                Content     = personalGoalDetailsListCard,
            };

            return(personalGoalsListCard);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Method to show teams goals details card in team.
        /// </summary>
        /// <param name="applicationBasePath">Application base URL of the application.</param>
        /// <param name="teamGoalDetails">Team goal values entered by user.</param>
        /// <param name="localizer">The current cultures' string localizer.</param>
        /// <param name="teamGoalsCreator">Name of the user who created/edited team goals.</param>
        /// <param name="goalCycleId">Goal cycle id to identify that goal cycle is ended or not.</param>
        /// <param name="isCardForTeamMembers">Determines whether card is sent in personal or team scope.</param>
        /// <returns>Returns an attachment of teams goals details card in team.</returns>
        public static Attachment GetTeamGoalDetailsListCard(string applicationBasePath, IEnumerable <TeamGoalDetail> teamGoalDetails, IStringLocalizer <Strings> localizer, string teamGoalsCreator, string goalCycleId, bool isCardForTeamMembers = false)
        {
            teamGoalDetails = teamGoalDetails ?? throw new ArgumentNullException(nameof(teamGoalDetails));

            var teamId = teamGoalDetails.Select(goal => goal.TeamId).First();
            var teamGoalCycleStartDate = teamGoalDetails.Select(goal => goal.TeamGoalStartDate).First();

            teamGoalCycleStartDate = DateTime.Parse(teamGoalCycleStartDate, CultureInfo.InvariantCulture).ToUniversalTime()
                                     .ToString(Constants.ListCardDateTimeFormat, CultureInfo.InvariantCulture);

            var teamGoalCycleEndDate = teamGoalDetails.Select(goal => goal.TeamGoalEndDate).First();

            teamGoalCycleEndDate = DateTime.Parse(teamGoalCycleEndDate, CultureInfo.InvariantCulture).ToUniversalTime()
                                   .ToString(Constants.ListCardDateTimeFormat, CultureInfo.InvariantCulture);

            var      reminder                = teamGoalDetails.Select(goal => goal.ReminderFrequency).First();
            var      reminderFrequency       = (ReminderFrequency)reminder;
            ListCard teamGoalDetailsListCard = new ListCard
            {
                Title = isCardForTeamMembers
                        ? localizer.GetString("TeamGoalListCardTitleForTeamMembers")
                        : localizer.GetString("TeamGoalListCardTitleForTeam"),
            };

            teamGoalDetailsListCard.Items.Add(new ListItem
            {
                Title = isCardForTeamMembers
                        ? localizer.GetString("TeamGoalCardCycleTextForTeamMembers", teamGoalsCreator, teamGoalCycleStartDate, teamGoalCycleEndDate)
                        : localizer.GetString("TeamGoalCardCycleTextForTeam", teamGoalCycleStartDate, teamGoalCycleEndDate),
                Type = "section",
            });

            if (isCardForTeamMembers)
            {
                foreach (var teamGoalDetailEntity in teamGoalDetails)
                {
                    teamGoalDetailsListCard.Items.Add(new ListItem
                    {
                        Id       = teamGoalDetailEntity.TeamGoalId,
                        Title    = teamGoalDetailEntity.TeamGoalName,
                        Subtitle = reminderFrequency.ToString(),
                        Type     = "resultItem",
                        Icon     = $"{applicationBasePath}/Artifacts/listIcon.png",
                    });
                }
            }
            else
            {
                foreach (var teamGoalDetailEntity in teamGoalDetails)
                {
                    teamGoalDetailsListCard.Items.Add(new ListItem
                    {
                        Id       = teamGoalDetailEntity.TeamGoalId,
                        Title    = teamGoalDetailEntity.TeamGoalName,
                        Subtitle = reminderFrequency.ToString(),
                        Type     = "resultItem",
                        Tap      = new TaskModuleAction(localizer.GetString("EditButtonText"), new AdaptiveSubmitAction
                        {
                            Title = localizer.GetString("EditButtonText"),
                            Data  = new AdaptiveSubmitActionData
                            {
                                AdaptiveActionType = Constants.EditTeamGoalsCommand,
                                TeamId             = teamGoalDetailEntity.TeamId,
                                GoalCycleId        = goalCycleId,
                            },
                        }),
                        Icon = $"{applicationBasePath}/Artifacts/listIcon.png",
                    });
                }
            }

            if (!isCardForTeamMembers)
            {
                CardAction editTeamGoals = new TaskModuleAction(localizer.GetString("EditButtonText"), new AdaptiveSubmitAction
                {
                    Data = new AdaptiveSubmitActionData
                    {
                        AdaptiveActionType = Constants.EditTeamGoalsCommand,
                        TeamId             = teamId,
                        GoalCycleId        = goalCycleId,
                    },
                });
                teamGoalDetailsListCard.Buttons.Add(editTeamGoals);
            }

            CardAction alignGoals = new TaskModuleAction(localizer.GetString("AlignGoalsButtonText"), new AdaptiveSubmitAction
            {
                Data = new AdaptiveSubmitActionData
                {
                    AdaptiveActionType = Constants.AlignGoalCommand,
                    TeamId             = teamId,
                    GoalCycleId        = goalCycleId,
                },
            });

            teamGoalDetailsListCard.Buttons.Add(alignGoals);

            var teamGoalsListCard = new Attachment()
            {
                ContentType = "application/vnd.microsoft.teams.card.list",
                Content     = teamGoalDetailsListCard,
            };

            return(teamGoalsListCard);
        }