コード例 #1
0
        /// <summary>
        /// Prompts the user to login. This can be overridden inorder to allow custom prompt messages or cards per channel.
        /// </summary>
        /// <param name="context">Chat context</param>
        /// <param name="msg">Chat message</param>
        /// <param name="authenticationUrl">OAuth URL for authenticating user</param>
        /// <returns>Task from Posting or prompt to the context.</returns>
        protected virtual Task PromptToLogin(IDialogContext context, IMessageActivity msg, string authenticationUrl)
        {
            Attachment plAttachment = null;
            SigninCard plCard;

            if (msg.ChannelId == "msteams")
            {
                plCard = new SigninCard(this.prompt, GetCardActions(authenticationUrl, "openUrl"));
            }
            else
            {
                plCard = new SigninCard(this.prompt, GetCardActions(authenticationUrl, "signin"));
            }
            plAttachment = plCard.ToAttachment();

            IMessageActivity response = context.MakeMessage();

            response.Recipient = msg.From;
            response.Type      = "message";

            response.Attachments = new List <Attachment>();
            response.Attachments.Add(plAttachment);

            return(context.PostAsync(response));
        }
コード例 #2
0
        private static Attachment GetSigninCard()
        {
            SigninCard signinCard = new SigninCard
            {
                Text    = "BotFramework Sign-in Card",
                Buttons = new List <CardAction>
                {
                    new CardAction(ActionTypes.Signin, "Sign-in", value: "https://login.microsoftonline.com/"),
                    new CardAction
                    {
                        Value = "http://vk.com",
                        Title = "Open VK",
                        Type  = ActionTypes.OpenUrl
                    },
                    new CardAction
                    {
                        Value = AnimationCard,
                        Text  = AnimationCard,
                        Title = AnimationCard,
                        Type  = ActionTypes.ImBack
                    }
                }
            };

            return(signinCard.ToAttachment());
        }
コード例 #3
0
        private async Task <bool> PromptForLogin(IBotContext context)
        {
            if (context.Request.AsMessageActivity().Text == "signin")
            {
                //show card for the LogIn
                IMessageActivity activity = ((Activity)context.Request).CreateReply();
                var OAuthSignInUrl        = await AuthenticationHelper.GetAuthUrlAsync(context.ConversationReference);

                var card = new SigninCard(
                    text: "Sign in",
                    buttons: new CardAction[] {
                    new CardAction(
                        type: "signin",
                        title: "Sign In",
                        text: "Sign In",
                        value: $"{OAuthSignInUrl}"
                        )
                });

                activity.Attachments.Add(new Attachment(HeroCard.ContentType, content: card));

                context.Reply(activity);
                //if you want to send the link as a hyperlink --> context.Reply($"[Click Here to Sign In]({OAuthSignInUrl})");
                return(true);
            }
            else if (context.Request.AsMessageActivity().Text == "logout")
            {
                context.State.UserProperties.Remove("token");
                string signoutURl = "https://login.microsoftonline.com/common/oauth2/logout";
                context.Reply($"In order to finish the sign out, please click at this [link]({signoutURl}).");
                return(true);
            }
            return(false);
        }
コード例 #4
0
        /// <summary>
        /// Login the user.
        /// </summary>
        /// <param name="context"> The Dialog context.</param>
        /// <returns> A task that represents the login action.</returns>
        private async Task LogIn(IDialogContext context)
        {
            string token;

            if (!context.PrivateConversationData.TryGetValue(AuthTokenKey, out token))
            {
                context.PrivateConversationData.SetValue("persistedCookie", ResumptionCookie);

                // sending the sigin card with Facebook login url
                var reply      = context.MakeMessage();
                var fbLoginUrl = FacebookHelpers.GetFacebookLoginURL(ResumptionCookie, FacebookOauthCallback.ToString());
                reply.Text = "Please login in using this card";
                reply.Attachments.Add(SigninCard.Create("You need to authorize me",
                                                        "Login to Facebook!",
                                                        fbLoginUrl
                                                        ).ToAttachment());
                await context.PostAsync(reply);

                context.Wait(MessageReceivedAsync);
            }
            else
            {
                context.Done(token);
            }
        }
コード例 #5
0
        /// <summary>
        /// Adds and converts a card to the attachments list.
        /// </summary>
        /// <param name="attachments">A list of attachments.</param>
        /// <param name="card">The card.</param>
        public static void Add(this IList <Attachment> attachments, SigninCard card)
        {
            attachments.ThrowIfNull(nameof(attachments));
            card.ThrowIfNull(nameof(card));

            attachments.Add(card.ToAttachment());
        }
コード例 #6
0
        public void MessageActivityWithSignInCard()
        {
            var skillRequest = SkillRequestHelper.CreateIntentRequest();
            var mapper       = new AlexaRequestMapper();

            var signinCard = new SigninCard
            {
                Text    = "sign in text",
                Buttons = new List <CardAction>()
                {
                    new CardAction
                    {
                        Title = "sign in",
                        Type  = ActionTypes.OpenUrl,
                        Image = "https://image",
                        Value = "https://value"
                    }
                }
            };

            var activity = Activity.CreateMessageActivity() as Activity;

            activity.Attachments.Add(new Attachment()
            {
                ContentType = SigninCard.ContentType, Content = signinCard
            });

            var skillResponse = ExecuteActivityToResponse(mapper, new MergedActivityResult {
                MergedActivity = activity
            }, skillRequest);

            Assert.NotNull(skillResponse.Response.Card);
            Assert.Equal(typeof(LinkAccountCard), skillResponse.Response.Card.GetType());
        }
コード例 #7
0
        public void SignInCardInitsWithNoArgs()
        {
            var signInCard = new SigninCard();

            Assert.NotNull(signInCard);
            Assert.IsType <SigninCard>(signInCard);
        }
コード例 #8
0
        public void SignInCardCreate()
        {
            var signInCard = SigninCard.Create("Please sign in", "Sign In", "http://example-signin.com");

            Assert.NotNull(signInCard);
            Assert.IsType <SigninCard>(signInCard);
        }
コード例 #9
0
        /// <summary>
        /// Prompt the user to authenticate using a sign in card.
        /// </summary>
        /// <param name="context">The context for the execution of a dialog's conversational process.</param>
        /// <returns>An instance of <see cref="Task"/> that represents the asynchronous operation.</returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="context"/> is null.
        /// </exception>
        private async Task AuthenticateAsync(IDialogContext context)
        {
            IMessageActivity message;
            Uri    redirectUri;
            string authUrl;
            string state;

            try
            {
                redirectUri = new Uri($"{HttpContext.Current.Request.Url.Scheme}://{HttpContext.Current.Request.Url.Host}:{HttpContext.Current.Request.Url.Port}/{BotConstants.CallbackPath}");

                state = $"&state={GenerateState(context)}";

                authUrl = await provider.AccessToken.GetAuthorizationRequestUrlAsync(
                    $"{provider.Configuration.ActiveDirectoryEndpoint}/{BotConstants.AuthorityEndpoint}",
                    provider.Configuration.GraphEndpoint,
                    provider.Configuration.ApplicationId,
                    redirectUri,
                    state).ConfigureAwait(false);

                message = context.MakeMessage();

                message.Attachments.Add(SigninCard.Create(
                                            Resources.SigninCardText, Resources.LoginCaptial, authUrl).ToAttachment());

                await context.PostAsync(message).ConfigureAwait(false);

                context.Wait(MessageReceivedAsync);
            }
            finally
            {
                message = null;
            }
        }
コード例 #10
0
        private async Task LogIn(IDialogContext context)
        {
            await context.PostAsync(context.CreateTypingActivity());

            var ticket = await SitecoreAuthenticationAPI.Instance().GetTicket(new ConversationReference(
                                                                                  user: new ChannelAccount(id: context.Activity.From.Id),
                                                                                  conversation: new ConversationAccount(id: context.Activity.Conversation.Id),
                                                                                  bot: new ChannelAccount(id: context.Activity.Recipient.Id),
                                                                                  channelId: context.Activity.ChannelId,
                                                                                  serviceUrl: context.Activity.ServiceUrl));

            var sitecoreLoginUrl = SitecoreAuthenticationAPI.Instance().GetSitecoreLoginURL(ticket);

            var reply = context.MakeMessage();

            reply.Attachments = new List <Attachment>();

            List <CardAction> cardButtons = new List <CardAction>();
            CardAction        loginButton = new CardAction()
            {
                Value = sitecoreLoginUrl,
                Type  = "openUrl",
                Title = "login"
            };

            cardButtons.Add(loginButton);

            SigninCard plCard = new SigninCard(text: "Trust me, I'm not standing here with Bobby Hack!!", buttons: cardButtons);

            reply.Attachments.Add(plCard.ToAttachment());

            await context.PostAsync(reply);
        }
コード例 #11
0
        private Attachment GetSigninCard()
        {
            var signinCard = new SigninCard()
            {
                Text    = "請選擇操作: ",
                Buttons = new List <CardAction>()
                {
                    new CardAction()
                    {
                        Type  = ActionTypes.ImBack,
                        Title = "新增",
                        Value = "Add"
                    },
                    new CardAction()
                    {
                        Type  = ActionTypes.ImBack,
                        Title = "修改",
                        Value = "Edit"
                    },
                    new CardAction()
                    {
                        Type  = ActionTypes.ImBack,
                        Title = "刪除",
                        Value = "Delete"
                    }
                }
            };

            return(signinCard.ToAttachment());
        }
コード例 #12
0
        private async Task LogIn(IDialogContext context, IMessageActivity msg, string[] scopes)
        {
            try
            {
                string token = await context.GetAccessToken(scopes);

                if (string.IsNullOrEmpty(token))
                {
                    if (msg.Text != null &&
                        CancellationWords.GetCancellationWords().Contains(msg.Text.ToUpper()))
                    {
                        context.Done(string.Empty);
                    }
                    else
                    {
                        var resumptionCookie = new ResumptionCookie(msg);

                        var authenticationUrl = await AzureActiveDirectoryHelper.GetAuthUrlAsync(resumptionCookie, scopes);

                        if (msg.ChannelId == "skype")
                        {
                            IMessageActivity response = context.MakeMessage();
                            response.Recipient = msg.From;
                            response.Type      = "message";

                            response.Attachments = new List <Attachment>();
                            List <CardAction> cardButtons = new List <CardAction>();
                            CardAction        plButton    = new CardAction()
                            {
                                Value = authenticationUrl,
                                Type  = "signin",
                                Title = "Authentication Required"
                            };

                            cardButtons.Add(plButton);
                            SigninCard plCard = new SigninCard(this.prompt, new List <CardAction>()
                            {
                                plButton
                            });
                            Attachment plAttachment = plCard.ToAttachment();
                            response.Attachments.Add(plAttachment);
                            await context.PostAsync(response);
                        }
                        else
                        {
                            await context.PostAsync(this.prompt + "[Click here](" + authenticationUrl + ")");
                        }
                        context.Wait(this.MessageReceivedAsync);
                    }
                }
                else
                {
                    context.Done(string.Empty);
                }
            }catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #13
0
ファイル: SigninCardTestData.cs プロジェクト: jcme/BotSpec
        internal static IEnumerable <SigninCard> CreateSigninCardSetWithOneCardThatHasSetProperties(string text = default(string), IList <CardAction> buttons = default(IList <CardAction>))
        {
            var matchingCard = new SigninCard(text, buttons);
            var cards        = CreateRandomSigninCards();

            cards.Add(matchingCard);
            return(cards);
        }
コード例 #14
0
        public void WithButtons_should_return_CardActionSetAssertions()
        {
            var buttons    = CardActionTestData.CreateRandomCardActions();
            var signinCard = new SigninCard(buttons: buttons);

            var sut = new SigninCardAssertions(signinCard);

            sut.WithButtons().Should().BeAssignableTo <CardActionSetAssertions>().And.NotBeNull();
        }
コード例 #15
0
        private async Task <HttpResponseMessage> HandleO365ConnectorCardActionQuery(Activity activity)
        {
            var connectorClient = new ConnectorClient(new Uri(activity.ServiceUrl));

            var userInfo = UserInfoRepository.GetUserInfo(activity.From.Id);

            // Validate for Sing In
            if (userInfo == null || userInfo.ExpiryTime < DateTime.Now)
            {
                var        reply  = activity.CreateReply();
                SigninCard plCard = RootDialog.GetSignInCard();
                reply.Attachments.Add(plCard.ToAttachment());
                await connectorClient.Conversations.ReplyToActivityWithRetriesAsync(reply);

                return(new HttpResponseMessage(System.Net.HttpStatusCode.OK));
            }

            var email  = string.Empty;
            var member = connectorClient.Conversations.GetConversationMembersAsync(activity.Conversation.Id).Result.AsTeamsChannelAccounts().FirstOrDefault();

            if (member != null)
            {
                email = member.Email;
            }


            // Get O365 connector card query data.
            Task <Task> task = new Task <Task>(async() =>
            {
                O365ConnectorCardActionQuery o365CardQuery = activity.GetO365ConnectorCardActionQueryData();
                Activity replyActivity = activity.CreateReply();
                switch (o365CardQuery.ActionId)
                {
                case "Custom":
                    // Get Passenger List & Name
                    var teamDetails = Newtonsoft.Json.JsonConvert.DeserializeObject <CustomTeamData>(o365CardQuery.Body);
                    await CreateTeam(connectorClient, activity, userInfo, teamDetails.TeamName, teamDetails.Members.Split(';').ToList());
                    break;

                case "Flight":
                    var flightDetails = Newtonsoft.Json.JsonConvert.DeserializeObject <O365BodyValue>(o365CardQuery.Body);


                    await CreateTeam(connectorClient, activity, userInfo, "Flight-" + flightDetails.Value, GetMemberList(email));
                    // await AttachClassWisePassengerList(classInfo.Value, replyActivity, $"Passengers with {classInfo.Value} tickets");
                    break;

                default:
                    break;
                }
            });

            task.Start();

            return(new HttpResponseMessage(System.Net.HttpStatusCode.OK));
        }
コード例 #16
0
ファイル: For_text_matching.cs プロジェクト: jcme/BotSpec
        public void TextMatching_should_throw_SigninCardAssertionFailedException_when_text_is_null()
        {
            var card = new SigninCard();

            var sut = new SigninCardAssertions(card);

            Action act = () => sut.TextMatching("anything");

            act.ShouldThrow <SigninCardAssertionFailedException>();
        }
コード例 #17
0
ファイル: For_text_matching.cs プロジェクト: jcme/BotSpec
        public void TextMatching_should_pass_when_using_standard_regex_features(string cardText, string regex)
        {
            var signinCard = new SigninCard(text: cardText);

            var sut = new SigninCardAssertions(signinCard);

            Action act = () => sut.TextMatching(regex);

            act.ShouldNotThrow <Exception>();
        }
コード例 #18
0
ファイル: For_text_matching.cs プロジェクト: jcme/BotSpec
        public void TextMatching_should_throw_SigninCardAssertionFailedException_for_non_matching_regexes(string cardText, string regex)
        {
            var signinCard = new SigninCard(text: cardText);

            var sut = new SigninCardAssertions(signinCard);

            Action act = () => sut.TextMatching(regex);

            act.ShouldThrow <SigninCardAssertionFailedException>();
        }
コード例 #19
0
ファイル: For_text_matching.cs プロジェクト: jcme/BotSpec
        public void TextMatching_should_pass_regardless_of_case(string cardText, string regex)
        {
            var signinCard = new SigninCard(text: cardText);

            var sut = new SigninCardAssertions(signinCard);

            Action act = () => sut.TextMatching(regex);

            act.ShouldNotThrow <Exception>();
        }
コード例 #20
0
ファイル: For_text_matching.cs プロジェクト: jcme/BotSpec
        public void TextMatching_should_pass_if_regex_exactly_matches_message_Text(string cardTextAndRegex)
        {
            var signinCard = new SigninCard(text: cardTextAndRegex);

            var sut = new SigninCardAssertions(signinCard);

            Action act = () => sut.TextMatching(cardTextAndRegex);

            act.ShouldNotThrow <Exception>();
        }
コード例 #21
0
ファイル: For_text_matching.cs プロジェクト: jcme/BotSpec
        public void TextMatching_should_throw_ArgumentNullException_if_regex_is_null()
        {
            var card = new SigninCard();

            var sut = new SigninCardAssertions(card);

            Action act = () => sut.TextMatching(null);

            act.ShouldThrow <ArgumentNullException>();
        }
コード例 #22
0
ファイル: SigninCardTestData.cs プロジェクト: jcme/BotSpec
        internal static IEnumerable <SigninCard> CreateSigninCardSetWithAllCardsWithSetProperties(string text = default(string), IList <CardAction> buttons = default(IList <CardAction>))
        {
            var cards = new List <SigninCard>();

            for (var i = 0; i < 5; i++)
            {
                var matchingCard = new SigninCard(text, buttons);
                cards.Add(matchingCard);
            }
            return(cards);
        }
コード例 #23
0
ファイル: For_text_matching.cs プロジェクト: jcme/BotSpec
        public void TextMatching_should_throw_SigninCardAssertionFailedException_when_trying_to_capture_groups_but_text_is_null()
        {
            IList <string> matches;
            var            card = new SigninCard();

            var sut = new SigninCardAssertions(card);

            Action act = () => sut.TextMatching("anything", "(.*)", out matches);

            act.ShouldThrow <SigninCardAssertionFailedException>();
        }
コード例 #24
0
        public static SigninCard GetSigninCard()
        {
            var signinCard = new SigninCard
            {
                Text    = "BotFramework Sign-in Card",
                Buttons = new List <CardAction> {
                    new CardAction(ActionTypes.Signin, "Sign-in", value: "https://login.microsoftonline.com/")
                },
            };

            return(signinCard);
        }
コード例 #25
0
        public static SigninCard GetSignInCard()
        {
            string            configUrl     = ConfigurationManager.AppSettings["BaseUri"].ToString() + "/composeExtensionSettings.html";
            CardAction        configExp     = new CardAction(ActionTypes.Signin, "Sign In", null, configUrl);
            List <CardAction> lstCardAction = new List <CardAction>();

            lstCardAction.Add(configExp);

            SigninCard plCard = new SigninCard(text: "Please sign in to AAD acount. This app needs admin consent.", buttons: lstCardAction);

            return(plCard);
        }
コード例 #26
0
        private static Attachment GetSigninCard()
        {
            var signinCard = new SigninCard
            {
                Text    = "Заголовок Sign-in Card",
                Buttons = new List <CardAction> {
                    new CardAction(ActionTypes.Signin, "Войти", value: "https://login.microsoftonline.com/")
                }
            };

            return(signinCard.ToAttachment());
        }
コード例 #27
0
        public static SigninCard GetSigninCard(string[] QnA_Response)
        {
            var signinCard = new SigninCard
            {
                Text    = QnA_Response[0],
                Buttons = new List <CardAction> {
                    new CardAction(ActionTypes.Signin, "Sign-in", value: QnA_Response[1])
                },
            };

            return(signinCard);
        }
コード例 #28
0
        private static Attachment GetSigninCard()
        {
            var signinCard = new SigninCard
            {
                Text    = StringResources.Sign_In_Card_Title,
                Buttons = new List <CardAction> {
                    new CardAction(ActionTypes.Signin, StringResources.Log_In, value: "https://login.microsoftonline.com/")
                }
            };

            return(signinCard.ToAttachment());
        }
コード例 #29
0
ファイル: For_text_matching.cs プロジェクト: jcme/BotSpec
        public void TextMatching_should_not_output_matches_when_groupMatchingRegex_does_not_match_text()
        {
            IList <string> matches;

            var signinCard = new SigninCard(text: "some text");

            var sut = new SigninCardAssertions(signinCard);

            sut.TextMatching("some text", "(non matching)", out matches);

            matches.Should().BeNull();
        }
コード例 #30
0
ファイル: For_text_matching.cs プロジェクト: jcme/BotSpec
        public void TextMatching_should_throw_ArgumentNullException_if_groupMatchRegex_is_null()
        {
            IList <string> matches;

            var card = new SigninCard();

            var sut = new SigninCardAssertions(card);

            Action act = () => sut.TextMatching("(.*)", null, out matches);

            act.ShouldThrow <ArgumentNullException>();
        }