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} ({me.UserPrincipalName}); you job title is: {title}; your photo is: "); var photo = await client.GetPhotoAsync(); var cardImage = new CardImage(photo); var card = new ThumbnailCard(images: new List <CardImage>() { cardImage }); var reply = MessageFactory.Attachment(card.ToAttachment()); await stepContext.Context.SendActivityAsync(reply, cancellationToken); 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) { // 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.GetMyProfile(); var imagelink = await client.GetPhotoAsync(); var heroCard = new ThumbnailCard { Title = "Thumbnail Card", Text = $"Hello, {me.DisplayName}", Images = new List <CardImage> { new CardImage(imagelink) }, }; var attachments = new Attachment(HeroCard.ContentType, null, heroCard); await stepContext.Context.SendActivityAsync(MessageFactory.Attachment(attachments), cancellationToken); 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)); }
protected async override Task <MessagingExtensionResponse> OnTeamsAppBasedLinkQueryAsync(ITurnContext <IInvokeActivity> turnContext, AppBasedLinkQuery query, CancellationToken cancellationToken) { var tokenResponse = await GetTokenResponse(turnContext, query.State, cancellationToken); if (tokenResponse == null || string.IsNullOrEmpty(tokenResponse.Token)) { // There is no token, so the user has not signed in yet. // Retrieve the OAuth Sign in Link to use in the MessagingExtensionResult Suggested Actions var signInLink = await(turnContext.Adapter as IUserTokenProvider).GetOauthSignInLinkAsync(turnContext, _connectionName, cancellationToken); return(new MessagingExtensionResponse { ComposeExtension = new MessagingExtensionResult { Type = "auth", SuggestedActions = new MessagingExtensionSuggestedAction { Actions = new List <CardAction> { new CardAction { Type = ActionTypes.OpenUrl, Value = signInLink, Title = "Bot Service OAuth", }, }, }, }, }); } var client = new SimpleGraphClient(tokenResponse.Token); var profile = await client.GetMyProfile(); var imagelink = await client.GetPhotoAsync(); var heroCard = new ThumbnailCard { Title = "Thumbnail Card", Text = $"Hello {profile.DisplayName}", Images = new List <CardImage> { new CardImage(imagelink) } }; var attachments = new MessagingExtensionAttachment(HeroCard.ContentType, null, heroCard); var result = new MessagingExtensionResult("list", "result", new[] { attachments }); return(new MessagingExtensionResponse(result)); }
// 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); }
protected override async Task <MessagingExtensionResponse> OnTeamsMessagingExtensionQueryAsync(ITurnContext <IInvokeActivity> turnContext, MessagingExtensionQuery action, CancellationToken cancellationToken) { var tokenResponse = await GetTokenResponse(turnContext, action.State, cancellationToken); if (tokenResponse == null || string.IsNullOrEmpty(tokenResponse.Token)) { // There is no token, so the user has not signed in yet. // Retrieve the OAuth Sign in Link to use in the MessagingExtensionResult Suggested Actions var signInLink = await(turnContext.Adapter as IUserTokenProvider).GetOauthSignInLinkAsync(turnContext, _connectionName, cancellationToken); return(new MessagingExtensionResponse { ComposeExtension = new MessagingExtensionResult { Type = "auth", SuggestedActions = new MessagingExtensionSuggestedAction { Actions = new List <CardAction> { new CardAction { Type = ActionTypes.OpenUrl, Value = signInLink, Title = "Bot Service OAuth", }, }, }, }, }); } var client = new SimpleGraphClient(tokenResponse.Token); var me = await client.GetMyProfile(); var imagelink = await client.GetPhotoAsync(); var previewcard = new ThumbnailCard { Title = me.DisplayName, Images = new List <CardImage> { new CardImage { Url = imagelink } } }; var attachment = new MessagingExtensionAttachment { ContentType = ThumbnailCard.ContentType, Content = previewcard, Preview = previewcard.ToAttachment() }; return(new MessagingExtensionResponse { ComposeExtension = new MessagingExtensionResult { Type = "result", AttachmentLayout = "list", Attachments = new List <MessagingExtensionAttachment> { attachment } } }); }