/// <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()); }
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()); }
private static async Task DisplayPersonalisationMenu(IDialogContext context) { IMessageActivity replyToConversation = context.MakeMessage(); replyToConversation.Type = "message"; replyToConversation.Attachments = new List <Attachment>(); List <CardAction> cardButtons = new List <CardAction> { new CardAction() { Type = "imBack", Title = "Change name", Value = "changepreferredname" }, new CardAction() { Type = "imBack", Title = "Change home city", Value = "changehomecity" }, new CardAction() { Type = "imBack", Title = "Back to main menu", Value = "exit" } }; SigninCard plCard = new SigninCard("Available options", cardButtons); Attachment plAttachment = plCard.ToAttachment(); replyToConversation.Attachments.Add(plAttachment); await context.PostAsync(replyToConversation); }
public Attachment GetSelectedCard(object selectedCard) { var signinCard = new SigninCard() { Text = "Authorization Needed", Buttons = new List <CardAction> { new CardAction() { Value = "https://login.microsoftonline.com/", Type = "signin", Title = "Microsoft OAuth", Image = "file:///C:/Users/Vrushali/Downloads/if_72-windows8_104431.svg" }, new CardAction() { Value = "https://accounts.google.com/signin", Type = "signin", Title = "Google", Image = "http://images.dailytech.com/nimage/G_is_For_Google_New_Logo_Thumb.png" } } }; return(signinCard.ToAttachment()); }
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); }
public static async Task LogIn(IDialogContext context) { GitHubClient client = new GitHubClient(new ProductHeaderValue(Constants.ProductHeader)); ConversationReference cr = context.Activity.ToConversationReference(); IMessageActivity reply = context.MakeMessage(); string csrf = Membership.GeneratePassword(24, 1); context.UserData.SetValue(Constants.StateKey, csrf); OauthLoginRequest request = new OauthLoginRequest(ConfigurationManager.AppSettings[Constants.GitHubClientIdKey]) { Scopes = { "repo" }, State = csrf, RedirectUri = GetRedirectUri(cr) }; Uri loginUrl = client.Oauth.GetGitHubLoginUrl(request); reply.Text = "Please login to GitHub using the button below."; SigninCard card = SigninCard.Create("Authorize me to access your GitHub account.", "Login to GitHub", loginUrl.ToString()); reply.Attachments.Add(card.ToAttachment()); await context.PostAsync(reply); }
/// <summary> /// This function is written for showing the initial login dialog after adding the bot /// </summary> /// <param name="activity">Activity associated with a bot</param> /// <returns>Response of the recent activity</returns> public async Task ShowLoginDialog(Activity activity) { ConnectorClient loginConnector = new ConnectorClient(new Uri(activity.ServiceUrl)); Activity replyToConversation = activity.CreateReply(); replyToConversation.Recipient = activity.From; replyToConversation.Type = "message"; replyToConversation.Attachments = new List <Attachment>(); List <CardAction> cardButtons = new List <CardAction>(); CardAction plButton = new CardAction() { Value = $"{ConfigurationManager.AppSettings["AppWebSite"]}?userId={HttpUtility.UrlEncode(activity.From.Id)}&serviceUrl={HttpUtility.UrlEncode(activity.ServiceUrl)}&conversationId={activity.Conversation.Id}&channelId={HttpUtility.UrlEncode(activity.ChannelId)}", Type = "signin", Title = "Authentication Required" }; cardButtons.Add(plButton); SigninCard plCard = new SigninCard("Please login to AEX", new List <CardAction>() { plButton }); Attachment plAttachment = plCard.ToAttachment(); replyToConversation.Attachments.Add(plAttachment); await loginConnector.Conversations.SendToConversationAsync(replyToConversation); }
/// <summary> /// This function is written for showing the initial login dialog after adding the bot /// </summary> /// <param name="activity">Activity associated with a bot</param> /// <returns>Response of the recent activity</returns> public async Task ShowSupportEnginner(Activity activity) { ConnectorClient loginConnector = new ConnectorClient(new Uri(activity.ServiceUrl)); Activity replyToConversation = activity.CreateReply(); replyToConversation.Recipient = activity.From; replyToConversation.Type = "message"; replyToConversation.Attachments = new List <Attachment>(); List <CardAction> cardButtons = new List <CardAction>(); CardAction plButton = new CardAction() { Value = $"skype:subhajit.insync?chat", Type = "openUrl", Title = "Subhajit Goswami" }; cardButtons.Add(plButton); SigninCard plCard = new SigninCard("Please chat with our support", new List <CardAction>() { plButton }); Attachment plAttachment = plCard.ToAttachment(); replyToConversation.Attachments.Add(plAttachment); await loginConnector.Conversations.SendToConversationAsync(replyToConversation); }
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()); }
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; } }
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)); }
private static Microsoft.Bot.Connector.Attachment GetSkypeSigninCard(ConversationReference conversationReference) { var signinCard = new SigninCard { Text = "Please login to microsoft account", Buttons = new List <CardAction> { new CardAction(ActionTypes.Signin, "Authentication Required", value: SharepointHelpers.GetSharepointLoginURL(conversationReference, Constants.SharepointOauthCallback.ToString())) } }; return(signinCard.ToAttachment()); }
private static Attachment GetSigninCard() { var signinCard = new SigninCard { Text = "Mio宇达電通官方网站", Buttons = new List <CardAction> { new CardAction(ActionTypes.Signin, "Sign-in", value: "https://advantage.mio.com/MioAdvantage/login/LoginAction!toLogin.action?com=zh_cn") } }; return(signinCard.ToAttachment()); }
/// <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; switch (msg.ChannelId) { case "emulator": { SigninCard plCard = new SigninCard(this.prompt, GetCardActions(authenticationUrl, "signin")); plAttachment = plCard.ToAttachment(); break; } case "skype": { SigninCard plCard = new SigninCard(this.prompt, GetCardActions(authenticationUrl, "signin")); plAttachment = plCard.ToAttachment(); break; } // Teams does not yet support signin cards case "msteams": { ThumbnailCard plCard = new ThumbnailCard() { Title = this.prompt, Subtitle = "", Images = new List <CardImage>(), Buttons = GetCardActions(authenticationUrl, "openUrl") }; plAttachment = plCard.ToAttachment(); break; } default: { SigninCard plCard = new SigninCard(this.prompt, GetCardActions(authenticationUrl, "signin")); plAttachment = plCard.ToAttachment(); break; } // return context.PostAsync(this.prompt + "[Click here](" + authenticationUrl + ")"); } IMessageActivity response = context.MakeMessage(); response.Recipient = msg.From; response.Type = "message"; response.Attachments = new List <Attachment>(); response.Attachments.Add(plAttachment); return(context.PostAsync(response)); }
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()); }
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()); }
static Attachment 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.ToAttachment()); }
/// <summary> /// Issue a new Signin card. /// </summary> /// <param name="activity">Incoming request from Bot Framework.</param> /// <param name="connectorClient">Connector client instance for posting to Bot Framework.</param> /// <returns>The returned ResourceResponse</returns> private static async Task<ResourceResponse> SendSigninCard(Activity activity, ConnectorClient connectorClient) { var userId = activity.From.Id; var authUrl = ConfigurationManager.AppSettings["SigninBaseUrl"] + "/auth/start/" + userId; SigninCard card = new SigninCard(); card.Text = "Sign in Facebook app"; card.Buttons = new List<CardAction>() { new CardAction("signin", "Login", null, authUrl) }; Activity replyActivity = activity.CreateReply(); replyActivity.Attachments = new List<Attachment>(); Attachment plAttachment = card.ToAttachment(); replyActivity.Attachments.Add(plAttachment); return await connectorClient.Conversations.ReplyToActivityWithRetriesAsync(replyActivity); }
//4 private static Attachment GetSigninCard() { var heroCard = new SigninCard() { Text = "Signin Card", Buttons = new List <CardAction> { new CardAction(ActionTypes.OpenUrl, "Log in", value: "https://uk-ua.facebook.com/login/") } }; return(heroCard.ToAttachment()); }
private static Attachment GetStudentSigninCard() { var signinCard = new SigninCard { Text = "Login to University system", Buttons = new List <CardAction> { new CardAction(ActionTypes.Signin, "Sign-in", value: "http://student.vinhuni.edu.vn/CMCSoft.IU.Web.Info/Login.aspx?url=http://student.vinhuni.edu.vn/cmcsoft.iu.web.info/home.aspx"), } }; return(signinCard.ToAttachment()); }
private Attachment GetSigninCard() { var signin = new SigninCard { Text = "Login", Buttons = new List <CardAction> { new CardAction(ActionTypes.Signin, "Sign-in", value: "https://login.microsoftonline.com/") } }; return(signin.ToAttachment()); }
private static Attachment GetStudentSigninCard() { var signinCard = new SigninCard { Text = "BotFramework Sign-in Card", Buttons = new List <CardAction> { new CardAction(ActionTypes.Signin, "Sign-in", value: "https://student.vinhuni.edu.vn/") } }; return(signinCard.ToAttachment()); }
private static async Task DisplayMainMenu(IDialogContext context) { string displayedUserName; if (!context.UserData.TryGetValue("PreferredName", out displayedUserName)) { displayedUserName = "******"; } var mainMenuMessage = context.MakeMessage(); mainMenuMessage.Recipient = mainMenuMessage.From; mainMenuMessage.Type = "message"; mainMenuMessage.Attachments = new List <Attachment>(); List <CardAction> cardButtons = new List <CardAction> { new CardAction() { Type = "imBack", Title = "Get latest news", Value = "news" }, new CardAction() { Type = "imBack", Title = "Find offices nearby", Value = "office" }, new CardAction() { Type = "imBack", Title = "Foreign exchange rates", Value = "rates" }, new CardAction() { Type = "imBack", Title = "Personalisation", Value = "personalisation" } }; SigninCard plCard = new SigninCard("Available options", cardButtons); Attachment plAttachment = plCard.ToAttachment(); mainMenuMessage.Attachments.Add(plAttachment); await context.PostAsync(mainMenuMessage); }
private async Task SignInAsync(IDialogContext context, IAwaitable <object> result) { var activity = await result as Activity; var teamAccount = await context.GetTeamsAccountAsync(); userObjectId = teamAccount.ObjectId; var graphServiceClient = await AuthenticationHelper.GetGraphServiceClientSafeAsync(userObjectId, Permissions.Delegated); if (graphServiceClient != null) { context.Done(graphServiceClient); return; } var signCard = new SigninCard { Text = "Authentication Required", Buttons = new List <CardAction>() { new CardAction( ActionTypes.OpenUrl, "Sign into Office 365", value: signInUrl) } }; var message = context.MakeMessage(); message.Attachments.Add(signCard.ToAttachment()); await context.PostAsync(message); await context.SayAsync("Hi There! Nice to meet you. Please click the Sign into Office 365 button above."); var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromMinutes(SignInMinutes)); try { graphServiceClient = await GetGraphServiceClientAsync(activity, cancellationTokenSource.Token); } catch (TaskCanceledException ex) { var exception = new SignTimeoutException("Sign in timeout", ex); context.Fail(exception); // throw exception return; } context.Done(graphServiceClient); }
private static void ShowSignInCard(IMessageActivity replyMessage) { List <CardAction> cardButtons = new List <CardAction>(); CardAction plButton = new CardAction() { Value = "https://<OAuthSignInURL>", Type = "signin", Title = "Connect" }; cardButtons.Add(plButton); SigninCard plCard = new SigninCard(text: "You need to authorize me", buttons: cardButtons); Attachment plAttachment = plCard.ToAttachment(); replyMessage.Attachments.Add(plAttachment); }
public void SigninCardToAttachmentTest() { var attachments = new List <Attachment>(); var signinCard = new SigninCard { Text = "Testing Text.", Buttons = new List <CardAction> { new CardAction(ActionTypes.Signin, "Sign-in", value: "https://login.microsoftonline.com/") }, }; attachments.Add(signinCard.ToAttachment()); Assert.NotEmpty(attachments); Assert.Equal("application/vnd.microsoft.card.signin", attachments[0].ContentType); }
private async Task signInAsync(IDialogContext context, IAwaitable <string> arguement) { // based on the selection, users need to input their NRIC to validate themselves // if user choose web sign-in, then they simply sign-in // note that no OAuth is coded, this is just for illustration purpose string userResponse = await arguement; switch (userResponse) { case "Web Sign-in": var reply = context.MakeMessage(); reply.Type = "message"; reply.Attachments = new List <Attachment>(); List <CardAction> cardButtons = new List <CardAction>(); CardAction plButton = new CardAction() { Value = "https://www.singpass.gov.sg/spauth/login/loginpage?URL=/&TAM_OP=login", Type = "signin", Title = "Connect to Sing Pass" }; cardButtons.Add(plButton); SigninCard plCard = new SigninCard() { Text = "Login to Sing Pass", Buttons = cardButtons }; Attachment plAttachment = plCard.ToAttachment(); reply.Attachments.Add(plAttachment); await context.PostAsync(reply); break; // apart from web, users need to provide their NRIC case "Face": loginOption = "Face"; await askNRICAsync(context); break; case "Voice": loginOption = "Voice"; await askNRICAsync(context); break; } }
/// <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 = 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)); }
public void AttachSignInCard(Activity replyToConversation) { replyToConversation.Attachments = new List <Attachment>(); List <CardAction> cards = new List <CardAction>(); CardAction signIn = new CardAction() { Value = "https://sms.mysabre.com", Type = "signin", Title = "Connect" }; cards.Add(signIn); SigninCard signInCard = new SigninCard(text: "Authorization required", buttons: cards); Attachment signInAttachment = signInCard.ToAttachment(); replyToConversation.Attachments.Add(signInAttachment); }
private static Microsoft.Bot.Connector.Attachment GetSigninCard(ConversationReference conversationReference) { List <CardAction> cardButtons = new List <CardAction>(); CardAction plButton = new CardAction() { Value = SharepointHelpers.GetSharepointLoginURL(conversationReference, Constants.SharepointOauthCallback.ToString()), Type = "openUrl", Title = "Authentication Required" }; cardButtons.Add(plButton); SigninCard plCard = new SigninCard("Please login to microsoft account", new List <CardAction>() { plButton }); return(plCard.ToAttachment()); }