// Gets recent mail the user has received within the last hour and displays up // to 5 of the emails in the bot. public static async Task ListRecentMailAsync(ITurnContext turnContext, TokenResponse tokenResponse) { if (turnContext == null) { throw new ArgumentNullException(nameof(turnContext)); } if (tokenResponse == null) { throw new ArgumentNullException(nameof(tokenResponse)); } var client = new SimpleGraphClient(tokenResponse.Token); var messages = await client.GetRecentMailAsync(); IMessageActivity reply = null; if (messages.Any()) { var count = messages.Length; if (count > 5) { count = 5; } reply = MessageFactory.Attachment(new List <Attachment>()); reply.AttachmentLayout = AttachmentLayoutTypes.Carousel; for (var i = 0; i < count; i++) { var mail = messages[i]; var card = new HeroCard( mail.Subject, $"{mail.From.EmailAddress.Name} <{mail.From.EmailAddress.Address}>", mail.BodyPreview, new List <CardImage>() { new CardImage( "https://botframeworksamples.blob.core.windows.net/samples/OutlookLogo.jpg", "Outlook Logo"), }); reply.Attachments.Add(card.ToAttachment()); } } else { reply = MessageFactory.Text("Unable to find any recent unread mail."); } await turnContext.SendActivityAsync(reply); }
// 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}."); }
// 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."); }