コード例 #1
0
        private BasicCard CreateGoogleCardFromHeroCard(HeroCard heroCard)
        {
            var imageUrl = heroCard.Images?.FirstOrDefault()?.Url;
            var buttons  = new List <Button>();

            var heroCardButtons = heroCard.Buttons
                                  .Where(b => b.Type == ActionTypes.OpenUrl && b.Value is string buttonValue && buttonValue.StartsWith("http", StringComparison.InvariantCultureIgnoreCase))
                                  .ToList();

            if (heroCardButtons?.FirstOrDefault() is CardAction button)
            {
                if (heroCardButtons.Count() > 1)
                {
                    Logger.LogWarning("Only one 'button' is supported on Google basic card, using first button");
                }

                buttons.Add(new Button()
                {
                    Title         = button.Title,
                    OpenUrlAction = new OpenUrlAction()
                    {
                        Url = button.Value as string
                    }
                });
            }

            return(GoogleCardFactory.CreateBasicCard(heroCard.Title, heroCard.Subtitle, heroCard.Text, buttons, imageUrl != null ? new Image {
                Url = imageUrl
            } : null));
        }
コード例 #2
0
        protected override async Task OnMessageActivityAsync(ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken)
        {
            switch (turnContext.Activity.Text.ToLower())
            {
            default:
                await turnContext.SendActivityAsync(MessageFactory.Text($"Echo: {turnContext.Activity.Text}. What's next?", inputHint: InputHints.ExpectingInput), cancellationToken);

                break;

            case "finish":
                await turnContext.SendActivityAsync(MessageFactory.Text($"Ok, I won't ask anymore.", inputHint: InputHints.IgnoringInput), cancellationToken);

                break;

            case "card":
                var activityWithCard = MessageFactory.Text($"Ok, I included a simple card.");
                var basicCard        = GoogleCardFactory.CreateBasicCard("card title", "card subtitle", "some text for the content");
                activityWithCard.Attachments.Add(basicCard.ToAttachment());
                await turnContext.SendActivityAsync(activityWithCard, cancellationToken);

                break;

            case "signin":
                var activityWithSigninCard = MessageFactory.Text($"Ok, I included a simple card.");
                var signinCard             = new SigninCard();
                activityWithSigninCard.Attachments.Add(signinCard.ToAttachment());
                await turnContext.SendActivityAsync(activityWithSigninCard, cancellationToken);

                break;

            case "list":
                var activityWithListAttachment = MessageFactory.Text($"Ok, I included a list.");
                var listIntent = GoogleHelperIntentFactory.CreateListIntent(
                    "List title",
                    new List <OptionItem>()
                {
                    new OptionItem(
                        "List item 1",
                        "This is the List Item 1 description",
                        new OptionItemInfo()
                    {
                        Key = "Item1", Synonyms = new List <string>()
                        {
                            "first"
                        }
                    },
                        new OptionItemImage()
                    {
                        AccessibilityText = "Item 1 image",
                        Url = "https://storage.googleapis.com/actionsresources/logo_assistant_2x_64dp.png"
                    }),
                    new OptionItem(
                        "List item 2",
                        "This is the List Item 2 description",
                        new OptionItemInfo()
                    {
                        Key = "Item2", Synonyms = new List <string>()
                        {
                            "second"
                        }
                    },
                        new OptionItemImage()
                    {
                        AccessibilityText = "Item 2 image",
                        Url = "https://storage.googleapis.com/actionsresources/logo_assistant_2x_64dp.png"
                    })
                });
                activityWithListAttachment.Attachments.Add(listIntent.ToAttachment());
                await turnContext.SendActivityAsync(activityWithListAttachment, cancellationToken);

                break;

            case "carousel":
                var activityWithCarouselAttachment = MessageFactory.Text($"Ok, I included a carousel.");
                var carouselIntent = GoogleHelperIntentFactory.CreateCarouselIntent(
                    "List title",
                    new List <OptionItem>()
                {
                    new OptionItem(
                        "List item 1",
                        "This is the List Item 1 description",
                        new OptionItemInfo()
                    {
                        Key = "Item1", Synonyms = new List <string>()
                        {
                            "first"
                        }
                    },
                        new OptionItemImage()
                    {
                        AccessibilityText = "Item 1 image",
                        Url = "https://storage.googleapis.com/actionsresources/logo_assistant_2x_64dp.png"
                    }),
                    new OptionItem(
                        "List item 2",
                        "This is the List Item 2 description",
                        new OptionItemInfo()
                    {
                        Key = "Item2", Synonyms = new List <string>()
                        {
                            "second"
                        }
                    },
                        new OptionItemImage()
                    {
                        AccessibilityText = "Item 2 image",
                        Url = "https://storage.googleapis.com/actionsresources/logo_assistant_2x_64dp.png"
                    })
                });
                activityWithCarouselAttachment.Attachments.Add(carouselIntent.ToAttachment());
                await turnContext.SendActivityAsync(activityWithCarouselAttachment, cancellationToken);

                break;

            case "table":
                var activityWithTableCardAttachment = MessageFactory.Text($"Ok, I included a table card.");
                var tableCard = GoogleCardFactory.CreateTableCard(
                    new List <ColumnProperties>()
                {
                    new ColumnProperties()
                    {
                        Header = "Column 1"
                    },
                    new ColumnProperties()
                    {
                        Header = "Column 2"
                    }
                },
                    new List <Row>()
                {
                    new Row()
                    {
                        Cells = new List <Cell>
                        {
                            new Cell {
                                Text = "Row 1, Item 1"
                            },
                            new Cell {
                                Text = "Row 1, Item 2"
                            }
                        }
                    },
                    new Row()
                    {
                        Cells = new List <Cell>
                        {
                            new Cell {
                                Text = "Row 2, Item 1"
                            },
                            new Cell {
                                Text = "Row 2, Item 2"
                            }
                        }
                    }
                },
                    "Table Card Title",
                    "Table card subtitle",
                    new List <Button>()
                {
                    new Button()
                    {
                        Title = "Click here", OpenUrlAction = new OpenUrlAction()
                        {
                            Url = "https://www.microsoft.com"
                        }
                    }
                });
                activityWithTableCardAttachment.Attachments.Add(tableCard.ToAttachment());
                await turnContext.SendActivityAsync(activityWithTableCardAttachment, cancellationToken);

                break;
            }
        }