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);
        }
Пример #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);
            }
        }
Пример #4
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);
                }
            }
        }