public static Attachment GenerateInstallCard(ITurnContext turnContext)
        {
            AdaptiveCard adaptiveCard = new AdaptiveCard(new AdaptiveSchemaVersion(1, 0));

            adaptiveCard.Body.Add(new AdaptiveTextBlock(Resources.Strings.InstallBotMessageText)
            {
                Size   = AdaptiveTextSize.Medium,
                Weight = AdaptiveTextWeight.Default,
                Wrap   = true,
            });
            adaptiveCard.Actions.Add(new AdaptiveSubmitAction()
            {
                Title = Resources.Strings.InstallBotButtonText,
                Data  = new Dictionary <string, object>
                {
                    // The magic happens here. This tells Teams to add this bot to the current conversation
                    // https://docs.microsoft.com/en-us/microsoftteams/platform/resources/messaging-extension-v3/create-extensions?tabs=typescript#request-to-install-your-conversational-bot
                    // https://stackoverflow.com/questions/58866100/operation-returned-an-invalid-status-code-forbidden-when-calling-getconversati
                    ["msteams"] = new Dictionary <string, bool>
                    {
                        ["justInTimeInstall"] = true,
                    },
                },
            });

            return(adaptiveCard.ToAttachment());
        }
Exemplo n.º 2
0
        // Step 5: End the dialog
        private async Task <DialogTurnResult> FinalStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            if ((bool)stepContext.Result)
            {
                var requestDetails = stepContext.Options is ConsultingRequestDetails
                        ? stepContext.Options as ConsultingRequestDetails
                        : new ConsultingRequestDetails();

                var timeProperty     = new TimexProperty(requestDetails.workDate);
                var deliveryDateText = timeProperty.ToNaturalLanguage(DateTime.Now);

                // TODO: Update billing system here and report any errors to user
                // Here is the success message
                var confirmationMessage = $"OK, I've charged {requestDetails.project.Name} for {requestDetails.workHours} hours worked {deliveryDateText}. Thank you for using ConsultingBot.";

                await stepContext.Context.SendActivityAsync(MessageFactory.Text(confirmationMessage), cancellationToken);

                AdaptiveCard card  = BillingConfirmationCard.GetCard(requestDetails);
                var          reply = stepContext.Context.Activity.CreateReply();
                reply.Attachments.Add(card.ToAttachment());
                await stepContext.Context.SendActivityAsync(reply).ConfigureAwait(false);

                return(await stepContext.EndDialogAsync(requestDetails, cancellationToken));
            }
            else
            {
                return(await stepContext.EndDialogAsync(null, cancellationToken));
            }
        }
        protected override async Task <TaskModuleResponse> OnTeamsTaskModuleFetchAsync(ITurnContext <IInvokeActivity> turnContext, TaskModuleRequest taskModuleRequest, CancellationToken cancellationToken)
        {
            var reply = MessageFactory.Text("handleTeamsTaskModuleFetchAsync TaskModuleRequest: " + JsonConvert.SerializeObject(taskModuleRequest));
            await turnContext.SendActivityAsync(reply, cancellationToken);

            var adaptiveCard = new AdaptiveCard();

            adaptiveCard.Body.Add(new AdaptiveTextBlock("This is an Adaptive Card within a Task Module"));
            adaptiveCard.Actions.Add(new AdaptiveSubmitAction {
                Type = "Action.Submit", Title = "Action.Submit", Data = new JObject {
                    { "submitLocation", "taskModule" }
                }
            });

            return(new TaskModuleResponse
            {
                Task = new TaskModuleContinueResponse
                {
                    Value = new TaskModuleTaskInfo()
                    {
                        Card = adaptiveCard.ToAttachment(),
                        Height = 200,
                        Width = 400,
                        Title = "Task Module Example",
                    },
                },
            });
        }
        public static Attachment GetAnnouncementBasicDetails(Campaign campaign)
        {
            var basicDetailsCard = new AdaptiveCard(new AdaptiveSchemaVersion("1.0"))
            {
                Body = new List <AdaptiveElement>()
                {
                    new AdaptiveColumnSet()
                    {
                        Columns = new List <AdaptiveColumn>()
                        {
                            new AdaptiveColumn()
                            {
                                Width = AdaptiveColumnWidth.Auto,
                                Items = new List <AdaptiveElement>()
                                {
                                    // Need to fetch this from Graph API.
                                    new AdaptiveImage()
                                    {
                                        Id  = "profileImage",
                                        Url = Uri.IsWellFormedUriString(campaign.Author?.ProfilePhoto, UriKind.Absolute)?
                                              new Uri(campaign.Author?.ProfilePhoto) : null,
                                        Size = AdaptiveImageSize.Medium, Style = AdaptiveImageStyle.Person
                                    }
                                }
                            },
                            new AdaptiveColumn()
                            {
                                Width = AdaptiveColumnWidth.Auto,
                                Items = new List <AdaptiveElement>()
                                {
                                    new AdaptiveTextBlock()
                                    {
                                        Text   = campaign.Title,
                                        Weight = AdaptiveTextWeight.Bolder, Wrap = true
                                    },
                                    new AdaptiveTextBlock()
                                    {
                                        Text = "Author: " + campaign.Author?.Name,
                                        Size = AdaptiveTextSize.Default, Spacing = AdaptiveSpacing.None, IsSubtle = true, Wrap = true
                                    },
                                    new AdaptiveTextBlock()
                                    {
                                        Text   = $"Created Date: {campaign.CreatedTime.ToShortDateString()}",
                                        Weight = AdaptiveTextWeight.Lighter,
                                        Size   = AdaptiveTextSize.Default, Wrap = true
                                    }
                                }
                            }
                        }
                    }
                },
            };

            return(basicDetailsCard.ToAttachment());
        }
Exemplo n.º 5
0
        private Attachment GetAdaptiveCardWithInvokeAction()
        {
            var adaptiveCard = new AdaptiveCard();

            adaptiveCard.Body.Add(new AdaptiveTextBlock("Bot Builder Invoke Action"));
            var action4 = new CardAction("invoke", "invoke", null, null, null, JObject.Parse(@"{ ""key"" : ""value"" }"));

            adaptiveCard.Actions.Add(action4.ToAdaptiveCardAction());

            return(adaptiveCard.ToAttachment());
        }
        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.º 7
0
        private Attachment AdaptiveTextCard(string text)
        {
            AdaptiveCard adaptiveCard = new AdaptiveCard(new AdaptiveSchemaVersion(1, 0));

            adaptiveCard.Body.Add(new AdaptiveTextBlock(text)
            {
                Size   = AdaptiveTextSize.Medium,
                Weight = AdaptiveTextWeight.Bolder,
                Wrap   = true,
            });

            return(adaptiveCard.ToAttachment());
        }
        private Attachment GetAdaptiveCardWithInvokeAction(Activity activity)
        {
            var skillId = ((JObject)activity.Value).Value <string>("skillid");
            var skill   = _skillsConfig.Skills[skillId];

            var adaptiveCard = new AdaptiveCard();

            adaptiveCard.Body.Add(new AdaptiveTextBlock("Bot Builder Invoke Action"));
            var action4 = new CardAction("invoke", "custom health check invoke", null, null, null, GetCardActionValue("Adaptive Card invoke", skill.Id));

            adaptiveCard.Actions.Add(action4.ToAdaptiveCardAction());

            return(adaptiveCard.ToAttachment());
        }
        private async Task SendAdaptiveCard3Async(ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken)
        {
            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);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Turns the card into an <see cref="Attachment"/>.
        /// </summary>
        /// <returns>An <see cref="Attachment"/>.</returns>
        public Attachment ToAttachment()
        {
            var card = new AdaptiveCard {
                Speak = this.sticker.Name,
                Body  = new List <AdaptiveElement>()
                {
                    new AdaptiveImage
                    {
                        HorizontalAlignment = AdaptiveHorizontalAlignment.Center,
                        Url     = this.sticker.ImageUri,
                        AltText = this.sticker.Name
                    }
                }
            };

            return(card.ToAttachment());
        }
Exemplo n.º 11
0
        private async Task SendAdaptiveCard1Async(ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken)
        {
            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);
        }
        public async Task <bool> HandleAdaptiveCardAction(Activity activity, CancellationToken cancellationToken)
        {
            var command = JsonConvert.DeserializeObject <ActionCommandBase>(activity.Value?.ToString());

            if (string.IsNullOrEmpty(command?.CommandId))
            {
                return(false);
            }

            AdaptiveCard result = null;

            switch (command.CommandId)
            {
            case AppCommands.OpenNewPosition:
                result = await OpenNewPosition(activity, cancellationToken);

                break;

            case AppCommands.LeaveInternalComment:
                result = await LeaveInternalComment(activity, cancellationToken);

                break;

            case AppCommands.ScheduleInterview:
                result = await ScheduleInterview(activity, cancellationToken);

                break;
            }

            if (result is null)
            {
                return(false);
            }

            // update activity
            var message = Activity.CreateMessageActivity();
            var client  = new ConnectorClient(new Uri(activity.ServiceUrl));

            message.Attachments.Add(result.ToAttachment());
            await client.Conversations.UpdateActivityAsync(activity.Conversation.Id, activity.ReplyToId, (Activity)message, cancellationToken);

            return(true);
        }
Exemplo n.º 13
0
        protected override async Task OnMessageActivityAsync(ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken)
        {
            AdaptiveCard card = new AdaptiveCard("1.0");

            card.Body.Add(new AdaptiveTextBlock()
            {
                Text = "Hello, click on Show Task Module.",
                Size = AdaptiveTextSize.Large
            });

            card.Actions.Add(new TaskModuleAction("Show Task Module 1", new ActionDetails()
            {
                ActionType = "action 1"
            }).ToAdaptiveCardAction());
            card.Actions.Add(new TaskModuleAction("Show Task Module 2", new ActionDetails()
            {
                ActionType = "action 2"
            }).ToAdaptiveCardAction());
            var message = MessageFactory.Attachment(card.ToAttachment());
            await turnContext.SendActivityAsync(message, cancellationToken);
        }
Exemplo n.º 14
0
        protected override async Task <TaskModuleResponse> OnTeamsTaskModuleFetchAsync(ITurnContext <IInvokeActivity> turnContext, CancellationToken cancellationToken)
        {
            var reply = MessageFactory.Text("OnTeamsTaskModuleFetchAsync Value: " + turnContext.Activity.Value.ToString());
            await turnContext.SendActivityAsync(reply, cancellationToken);

            var adaptiveCard = new AdaptiveCard();

            adaptiveCard.Body.Add(new AdaptiveTextBlock("This is an Adaptive Card within a Task Module"));

            return(new TaskModuleResponse
            {
                Task = new TaskModuleContinueResponse()
                {
                    Value = new TaskModuleTaskInfo()
                    {
                        Card = adaptiveCard.ToAttachment(),
                        Height = 200,
                        Width = 400,
                        Title = "Task Module Example",
                    },
                },
            });
        }
Exemplo n.º 15
0
 /// <summary>
 /// Converts an adaptive card to an activity.
 /// </summary>
 /// <param name="card">The adaptive card.</param>
 /// <param name="context">The context of the bot.</param>
 /// <returns>The activity.</returns>
 public static Activity ToActivity(this AdaptiveCard card, ITurnContext context) => card.ToAttachment().ToActivity(context);
Exemplo n.º 16
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);
                }
            }
        }
        public static Attachment Generate(ITurnContext turnContext, List <ReportFormatType> reportFormats)
        {
            AdaptiveCard adaptiveCard = new AdaptiveCard(new AdaptiveSchemaVersion(1, 0));

            // Scope choice set for channel/ message for group chat
            var scopeContainer = new AdaptiveContainer()
            {
                Items = new List <AdaptiveElement>()
            };
            var conversationType = turnContext.Activity.Conversation.ConversationType;

            if (conversationType == Constants.ChannelConversationType)
            {
                scopeContainer.Items.Add(new AdaptiveTextBlock(Resources.Strings.MessageExtChannelScopeMessage)
                {
                    Size   = AdaptiveTextSize.Medium,
                    Weight = AdaptiveTextWeight.Default,
                    Wrap   = true,
                });

                var choiceSet = new AdaptiveChoiceSetInput()
                {
                    Id      = ChannelScopeInputId,
                    Style   = AdaptiveChoiceInputStyle.Expanded,
                    Choices = new List <AdaptiveChoice>()
                    {
                        new AdaptiveChoice()
                        {
                            Value = Resources.Strings.ChannelHistoryOptionAll,
                            Title = Resources.Strings.ChannelHistoryOptionAll,
                        },
                        new AdaptiveChoice()
                        {
                            Value = Resources.Strings.ChannelHistoryOptionConversation,
                            Title = Resources.Strings.ChannelHistoryOptionConversation,
                        },
                    },
                    Value = Resources.Strings.ChannelHistoryOptionAll,
                };
                scopeContainer.Items.Add(choiceSet);
            }

            adaptiveCard.Body.Add(scopeContainer);

            // Timer range choice set
            var timeRangeContainer = new AdaptiveContainer()
            {
                Items = new List <AdaptiveElement>()
            };

            timeRangeContainer.Items.Add(new AdaptiveTextBlock(Resources.Strings.MessageExtTimeRangeReportMessage)
            {
                Size   = AdaptiveTextSize.Medium,
                Weight = AdaptiveTextWeight.Default,
                Wrap   = true,
            });
            var timeSet = new AdaptiveChoiceSetInput()
            {
                Id      = TimeRangeInputId,
                Style   = AdaptiveChoiceInputStyle.Expanded,
                Choices = new List <AdaptiveChoice>()
                {
                    new AdaptiveChoice()
                    {
                        Value = Resources.Strings.TimePeriodOptionAllTime,
                        Title = Resources.Strings.TimePeriodOptionAllTime,
                    },
                    new AdaptiveChoice()
                    {
                        Value = Resources.Strings.TimePeriodOptionLast7Days,
                        Title = Resources.Strings.TimePeriodOptionLast7Days,
                    },
                    new AdaptiveChoice()
                    {
                        Value = Resources.Strings.TimePeriodOptionLastDay,
                        Title = Resources.Strings.TimePeriodOptionLastDay,
                    },
                },
                Value = Resources.Strings.TimePeriodOptionAllTime,
            };

            timeRangeContainer.Items.Add(timeSet);
            adaptiveCard.Body.Add(timeRangeContainer);

            // File format choice set
            var fileFormatContainer = new AdaptiveContainer()
            {
                Items = new List <AdaptiveElement>()
            };

            fileFormatContainer.Items.Add(new AdaptiveTextBlock(Resources.Strings.MessageExtFileTypeReportMessage)
            {
                Size   = AdaptiveTextSize.Medium,
                Weight = AdaptiveTextWeight.Default,
                Wrap   = true,
            });
            var reportFormatChoices = reportFormats.Select(x => new AdaptiveChoice()
            {
                Value = ReportFileFormatConverter.GetReportFormat(x),
                Title = ReportFileFormatConverter.GetReportFormat(x),
            }).ToList();
            var formatSet = new AdaptiveChoiceSetInput()
            {
                Id      = ReportTypeInputId,
                Style   = AdaptiveChoiceInputStyle.Expanded,
                Choices = reportFormatChoices,
                Value   = reportFormatChoices.First().Value,
            };

            fileFormatContainer.Items.Add(formatSet);
            adaptiveCard.Body.Add(fileFormatContainer);

            adaptiveCard.Actions.Add(new AdaptiveSubmitAction()
            {
                Title = Resources.Strings.SignOutButtonText,
                Data  = new Dictionary <string, string> {
                    ["action"] = SignOutAction
                },
            });
            adaptiveCard.Actions.Add(new AdaptiveSubmitAction()
            {
                Title = Resources.Strings.MessageExtExtractButton,
                Id    = GenerateBtnId,
                Data  = new Dictionary <string, string> {
                    ["action"] = GenerateReportAction
                },
            });


            return(adaptiveCard.ToAttachment());
        }