Ejemplo n.º 1
0
        private Attachment MakeO365CardAttachmentAsync()
        {
            var card           = CardSampleHelper.CreateSampleO365ConnectorCard();
            var cardAttachment = new Attachment
            {
                Content     = card,
                ContentType = O365ConnectorCard.ContentType,
            };

            return(cardAttachment);
        }
Ejemplo n.º 2
0
        private AdaptiveCard MakeAdaptiveCard(string cardType)
        {
            var adaptiveCard = cardType switch
            {
                "botaction" => CardSampleHelper.CreateAdaptiveCardBotAction(),
                "taskmodule" => CardSampleHelper.CreateAdaptiveCardTaskModule(),
                "submitaction" => CardSampleHelper.CreateAdaptiveCardSubmit(),
                _ => throw new ArgumentException(nameof(cardType)),
            };

            return(adaptiveCard);
        }
Ejemplo n.º 3
0
        private async Task <DialogTurnResult> DisplayCardAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var card     = ((FoundChoice)stepContext.Result).Value.ToLowerInvariant();
            var cardType = ParseEnum <CardOptions>(card);

            if (ChannelSupportedCards.IsCardSupported(stepContext.Context.Activity.ChannelId, cardType))
            {
                switch (cardType)
                {
                case CardOptions.AdaptiveCardBotAction:
                    await stepContext.Context.SendActivityAsync(MessageFactory.Attachment(MakeAdaptiveCard("botaction").ToAttachment()), cancellationToken);

                    break;

                case CardOptions.AdaptiveCardTaskModule:
                    await stepContext.Context.SendActivityAsync(MessageFactory.Attachment(MakeAdaptiveCard("taskmodule").ToAttachment()), cancellationToken);

                    break;

                case CardOptions.AdaptiveCardSumbitAction:
                    await stepContext.Context.SendActivityAsync(MessageFactory.Attachment(MakeAdaptiveCard("submitaction").ToAttachment()), cancellationToken);

                    break;

                case CardOptions.Hero:
                    await stepContext.Context.SendActivityAsync(MessageFactory.Attachment(CardSampleHelper.CreateHeroCard().ToAttachment()), cancellationToken).ConfigureAwait(false);

                    break;

                case CardOptions.Thumbnail:
                    await stepContext.Context.SendActivityAsync(MessageFactory.Attachment(CardSampleHelper.CreateThumbnailCard().ToAttachment()), cancellationToken).ConfigureAwait(false);

                    break;

                case CardOptions.Receipt:
                    await stepContext.Context.SendActivityAsync(MessageFactory.Attachment(CardSampleHelper.CreateReceiptCard().ToAttachment()), cancellationToken).ConfigureAwait(false);

                    break;

                case CardOptions.Signin:
                    await stepContext.Context.SendActivityAsync(MessageFactory.Attachment(CardSampleHelper.CreateSigninCard().ToAttachment()), cancellationToken).ConfigureAwait(false);

                    break;

                case CardOptions.Carousel:
                    // NOTE: if cards are NOT the same height in a carousel, Teams will instead display as AttachmentLayoutTypes.List
                    await stepContext.Context.SendActivityAsync(
                        MessageFactory.Carousel(new[]
                    {
                        CardSampleHelper.CreateHeroCard().ToAttachment(),
                        CardSampleHelper.CreateHeroCard().ToAttachment(),
                        CardSampleHelper.CreateHeroCard().ToAttachment()
                    }),
                        cancellationToken).ConfigureAwait(false);

                    break;

                case CardOptions.List:
                    // NOTE: MessageFactory.Attachment with multiple attachments will default to AttachmentLayoutTypes.List
                    await stepContext.Context.SendActivityAsync(
                        MessageFactory.Attachment(new[]
                    {
                        CardSampleHelper.CreateHeroCard().ToAttachment(),
                        CardSampleHelper.CreateHeroCard().ToAttachment(),
                        CardSampleHelper.CreateHeroCard().ToAttachment()
                    }),
                        cancellationToken).ConfigureAwait(false);

                    break;

                case CardOptions.O365:

                    await stepContext.Context.SendActivityAsync(MessageFactory.Attachment(MakeO365CardAttachmentAsync()), cancellationToken).ConfigureAwait(false);

                    break;

                case CardOptions.TeamsFileConsent:
                    await stepContext.Context.SendActivityAsync(MessageFactory.Attachment(MakeTeamsFileConsentCard()), cancellationToken);

                    break;

                case CardOptions.Animation:
                    await stepContext.Context.SendActivityAsync(MessageFactory.Attachment(MakeAnimationCard().ToAttachment()), cancellationToken);

                    break;

                case CardOptions.Audio:
                    await stepContext.Context.SendActivityAsync(MessageFactory.Attachment(MakeAudioCard().ToAttachment()), cancellationToken);

                    break;

                case CardOptions.Video:
                    await stepContext.Context.SendActivityAsync(MessageFactory.Attachment(MakeVideoCard().ToAttachment()), cancellationToken);

                    break;

                case CardOptions.End:
                    return(new DialogTurnResult(DialogTurnStatus.Complete));
                }
            }
            else
            {
                await stepContext.Context.SendActivityAsync(MessageFactory.Text($"{cardType} cards are not supported in the {stepContext.Context.Activity.ChannelId} channel."), cancellationToken);
            }

            return(await stepContext.ReplaceDialogAsync(InitialDialogId, "What card would you want?", cancellationToken));
        }
Ejemplo n.º 4
0
        private async Task <DialogTurnResult> DisplayCardAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            var card = ((FoundChoice)stepContext.Result).Value.ToLowerInvariant();

            switch (card)
            {
            case "botaction":
                await stepContext.Context.SendActivityAsync(MessageFactory.Attachment(MakeAdaptiveCard("botaction").ToAttachment()), cancellationToken);

                break;

            case "taskmodule":
                await stepContext.Context.SendActivityAsync(MessageFactory.Attachment(MakeAdaptiveCard("taskmodule").ToAttachment()), cancellationToken);

                break;

            case "submitaction":
                await stepContext.Context.SendActivityAsync(MessageFactory.Attachment(MakeAdaptiveCard("submitaction").ToAttachment()), cancellationToken);

                break;

            case "hero":
                await stepContext.Context.SendActivityAsync(MessageFactory.Attachment(CardSampleHelper.CreateHeroCard().ToAttachment()), cancellationToken).ConfigureAwait(false);

                break;

            case "thumbnail":
                await stepContext.Context.SendActivityAsync(MessageFactory.Attachment(CardSampleHelper.CreateThumbnailCard().ToAttachment()), cancellationToken).ConfigureAwait(false);

                break;

            case "receipt":
                await stepContext.Context.SendActivityAsync(MessageFactory.Attachment(CardSampleHelper.CreateReceiptCard().ToAttachment()), cancellationToken).ConfigureAwait(false);

                break;

            case "signin":
                await stepContext.Context.SendActivityAsync(MessageFactory.Attachment(CardSampleHelper.CreateSigninCard().ToAttachment()), cancellationToken).ConfigureAwait(false);

                break;

            case "carousel":
                // NOTE: if cards are NOT the same height in a carousel, Teams will instead display as AttachmentLayoutTypes.List
                await stepContext.Context.SendActivityAsync(
                    MessageFactory.Carousel(new[]
                {
                    CardSampleHelper.CreateHeroCard().ToAttachment(),
                    CardSampleHelper.CreateHeroCard().ToAttachment(),
                    CardSampleHelper.CreateHeroCard().ToAttachment()
                }),
                    cancellationToken).ConfigureAwait(false);

                break;

            case "list":
                // NOTE: MessageFactory.Attachment with multiple attachments will default to AttachmentLayoutTypes.List
                await stepContext.Context.SendActivityAsync(
                    MessageFactory.Attachment(new[]
                {
                    CardSampleHelper.CreateHeroCard().ToAttachment(),
                    CardSampleHelper.CreateHeroCard().ToAttachment(),
                    CardSampleHelper.CreateHeroCard().ToAttachment()
                }),
                    cancellationToken).ConfigureAwait(false);

                break;

            case "o365":

                await stepContext.Context.SendActivityAsync(MessageFactory.Attachment(MakeO365CardAttachmentAsync()), cancellationToken).ConfigureAwait(false);

                break;

            case "file":
                await stepContext.Context.SendActivityAsync(MessageFactory.Attachment(MakeFileCard()), cancellationToken);

                break;

            case "animation":
                await stepContext.Context.SendActivityAsync(MessageFactory.Attachment(MakeAnimationCard().ToAttachment()), cancellationToken);

                break;

            case "audio":
                await stepContext.Context.SendActivityAsync(MessageFactory.Attachment(MakeAudioCard().ToAttachment()), cancellationToken);

                break;

            case "video":
                await stepContext.Context.SendActivityAsync(MessageFactory.Attachment(MakeVideoCard().ToAttachment()), cancellationToken);

                break;

            case "uploadfile":
                await ShowUploadFile(stepContext, cancellationToken).ConfigureAwait(false);

                break;

            case "end":
                return(new DialogTurnResult(DialogTurnStatus.Complete));
            }

            return(await stepContext.ReplaceDialogAsync(InitialDialogId, "What card would you want?", cancellationToken));
        }