예제 #1
0
        // 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);
        }