private async Task <DialogTurnResult> LoginStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) { // Get the token from the previous step. Note that we could also have gotten the // token directly from the prompt itself. There is an example of this in the next method. var tokenResponse = (TokenResponse)stepContext.Result; if (tokenResponse?.Token != null) { // Pull in the data from the Microsoft Graph. var client = new SimpleGraphClient(tokenResponse.Token); var me = await client.GetMeAsync(); var title = !string.IsNullOrEmpty(me.JobTitle) ? me.JobTitle : "Unknown"; await stepContext.Context.SendActivityAsync($"You're logged in as {me.DisplayName} your token {tokenResponse.Token} ({me.UserPrincipalName}); you job title is: {title}"); return(await stepContext.PromptAsync(nameof(ConfirmPrompt), new PromptOptions { Prompt = MessageFactory.Text("Would you like to register your app?") }, cancellationToken)); } await stepContext.Context.SendActivityAsync(MessageFactory.Text("Login was not successful please try again."), cancellationToken); return(await stepContext.EndDialogAsync(cancellationToken : cancellationToken)); }
private static async Task <User> GetUserAsync(ITurnContext turnContext, TokenResponse tokenResponse) { if (turnContext == null) { throw new ArgumentNullException(nameof(turnContext)); } if (tokenResponse == null) { throw new ArgumentNullException(nameof(tokenResponse)); } // Pull in the data from the Microsoft Graph. var client = new SimpleGraphClient(tokenResponse.Token); return(await client.GetMeAsync()); }
// Displays information about the user in the bot. public static async Task ListMeAsync(ITurnContext turnContext, TokenResponse tokenResponse) { if (turnContext == null) { throw new ArgumentNullException(nameof(turnContext)); } if (tokenResponse == null) { throw new ArgumentNullException(nameof(tokenResponse)); } // Pull in the data from the Microsoft Graph. var client = new SimpleGraphClient(tokenResponse.Token); var me = await client.GetMeAsync(); await turnContext.SendActivityAsync($"You are {me.DisplayName}."); }
private async Task <DialogTurnResult> LoginStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) { var tokenResponse = (TokenResponse)stepContext.Result; if (tokenResponse?.Token != null) { var client = new SimpleGraphClient(tokenResponse.Token); var me = await client.GetMeAsync(); var title = !string.IsNullOrEmpty(me.JobTitle) ? me.JobTitle : "Unknown"; await stepContext.Context.SendActivityAsync($"You're logged in as {me.DisplayName} ({me.UserPrincipalName}); you job title is: {title}"); return(await stepContext.PromptAsync(nameof(ConfirmPrompt), new PromptOptions { Prompt = MessageFactory.Text("Would you like to view your token?") }, cancellationToken)); } await stepContext.Context.SendActivityAsync(MessageFactory.Text("Login was not successful please try again."), cancellationToken); return(await stepContext.EndDialogAsync(cancellationToken : cancellationToken)); }
private async Task <DialogTurnResult> LoginStepAsync(WaterfallStepContext stepContext, CancellationToken cancellationToken) { var authenticatedUserIsAuthenticated = await _AuthenticatedUserAccessor.GetAsync(stepContext.Context, () => new AuthenticatedUser()); if (authenticatedUserIsAuthenticated.IsAuthenticated) { return(await stepContext.ContinueDialogAsync()); } // Get the token from the previous step. Note that we could also have gotten the // token directly from the prompt itself. There is an example of this in the next method. var tokenResponse = (TokenResponse)stepContext.Result; if (tokenResponse?.Token != null) { AuthenticatedUser AuthenticatedUser = new AuthenticatedUser(); AuthenticatedUser.IsAuthenticated = true; AuthenticatedUser.JwtSecurityToken = tokenResponse.Token; await _AuthenticatedUserAccessor.SetAsync(stepContext.Context, AuthenticatedUser); // Pull in the data from the Microsoft Graph. var client = new SimpleGraphClient(tokenResponse.Token); var me = await client.GetMeAsync(); var title = !string.IsNullOrEmpty(me.JobTitle) ? me.JobTitle : "Unknown"; await stepContext.Context.SendActivityAsync($"You're logged in as {me.DisplayName} ({me.UserPrincipalName}); you job title is: {title}"); await stepContext.Context.SendActivityAsync("Your intent please:"); //return await stepContext.PromptAsync(nameof(ConfirmPrompt), new PromptOptions { Prompt = MessageFactory.Text("Your intent please:") }, cancellationToken); } //await stepContext.Context.SendActivityAsync(MessageFactory.Text("Login was not successful please try again."), cancellationToken); return(await stepContext.EndDialogAsync(cancellationToken : cancellationToken)); }
private async Task <DialogTurnResult> AskForAttendees(WaterfallStepContext stepContext, CancellationToken cancellationToken) { var tokenResponse = (TokenResponse)stepContext.Result; // Get the token from the previous step. if (tokenResponse?.Token != null) { // Pull in the data from the Microsoft Graph. var client = new SimpleGraphClient(tokenResponse.Token); var me = await client.GetMeAsync(); userEmail = me.UserPrincipalName; table = CreateTableAsync("botdata"); //creates table if does not exist already MeetingDetail meetingDetail = new MeetingDetail(stepContext.Context.Activity.Conversation.Id, userEmail); await InsertOrMergeEntityAsync(table, meetingDetail); //inserts user's email in table return(await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = MessageFactory.Text("With whom would you like to set up a meeting?") }, cancellationToken)); } await stepContext.Context.SendActivityAsync("Something went wrong. Please type anything to get started again."); return(await stepContext.EndDialogAsync(cancellationToken : cancellationToken)); }
// Enable the user to send an email via the bot. public static async Task SendMailAsync(ITurnContext turnContext, TokenResponse tokenResponse, string recipient) { if (turnContext == null) { throw new ArgumentNullException(nameof(turnContext)); } if (tokenResponse == null) { throw new ArgumentNullException(nameof(tokenResponse)); } var client = new SimpleGraphClient(tokenResponse.Token); var me = await client.GetMeAsync(); await client.SendMailAsync( recipient, "Message from a bot!", $"Hi there! I had this message sent from a bot. - Your friend, {me.DisplayName}"); await turnContext.SendActivityAsync( $"I sent a message to '{recipient}' from your account."); }
// Displays information about the user in the bot. public static async Task ListMeAsync(ITurnContext turnContext, TokenResponse tokenResponse) { if (turnContext == null) { throw new ArgumentNullException(nameof(turnContext)); } if (tokenResponse == null) { throw new ArgumentNullException(nameof(tokenResponse)); } // Pull in the data from the Microsoft Graph. var client = new SimpleGraphClient(tokenResponse.Token); var me = await client.GetMeAsync(); var manager = await client.GetManagerAsync(); var photoResponse = await client.GetPhotoAsync(); // Generate the reply activity. var reply = turnContext.Activity.CreateReply(); var photoText = string.Empty; if (photoResponse != null) { var replyAttachment = new Attachment(photoResponse.ContentType, photoResponse.Base64String); reply.Attachments.Add(replyAttachment); } else { photoText = "Consider adding an image to your Outlook profile."; } reply.Text = $"You are {me.DisplayName} and you report to {manager.DisplayName}. {photoText}"; await turnContext.SendActivityAsync(reply); }