Example #1
0
        private async Task <IEnumerable <IMessageDetails> > GetMessagesHistoryAsync(ITurnContext context, ReportParameters parameters, CancellationToken cancellationToken)
        {
            parameters.Till = DateTimeOffset.Now;

            List <IMessageDetails> details = new List <IMessageDetails>();

            switch (parameters.ReportPeriod)
            {
            case ReportPeriodType.LastDay:
            {
                parameters.Since = parameters.Till.AddDays(-1);
                break;
            }

            case ReportPeriodType.Last7Days:
            {
                parameters.Since = parameters.Till.AddDays(-7);
                break;
            }
            }

            // Get messages through Graph API using user token delegate
            var data = await graphClient.GetConversationHistoryAsync(() => context.GetUserTokenAsync(this.connectionName, cancellationToken), parameters.TeamId, parameters.ConversationId, parameters.ReplyToMessageId, parameters.Since);

            details.AddRange(data);

            return(details);
        }
Example #2
0
        private async Task <bool> IsAuthenticated(ITurnContext <IInvokeActivity> turnContext, CancellationToken cancellationToken)
        {
            // When the Bot Service Auth flow completes, the action.State will contain a magic code used for verification.
            var    magicCode = turnContext.GetAuthenticationStateCode();
            string authToken = await turnContext.GetUserTokenAsync(this.connectionName, magicCode, cancellationToken);

            var isAuthenticated = !string.IsNullOrEmpty(authToken);

            return(isAuthenticated);
        }
Example #3
0
        private async Task <IDriveItem> UploadFile(byte[] byteArray, IReportBodyDetails reportDetails, string fileName, ITurnContext context, CancellationToken cancellationToken)
        {
            using (var stream = new MemoryStream(byteArray))
            {
                stream.Position = 0;
                stream.Flush();
                IDriveItem file =
                    await graphClient.UploadFileInPersonalOneDrive(() => context.GetUserTokenAsync(this.connectionName, cancellationToken), stream, fileName);

                return(file);
            }
        }
Example #4
0
        private async Task <byte[]> GenerateReportByteArray(ITurnContext context, IReportBodyDetails reportBodyDetails, ReportFormatType format, CancellationToken cancellationToken)
        {
            switch (format)
            {
            case ReportFormatType.HTML:
            case ReportFormatType.PDF:
            {
                await graphClient.DownloadImages(() => context.GetUserTokenAsync(this.connectionName, cancellationToken), reportBodyDetails.Messages);

                break;
            }
            }

            return(reportGenerator.PrepareDocument(reportBodyDetails, format));
        }