コード例 #1
0
        private async Task ProcessMessages(TeamsBackfillCommand request, Credential credential, Chat chat, IChatMessagesCollectionPage messages)
        {
            foreach (var message in messages)
            {
                var images = new ImageProcessor().GetImages(message, Network.Teams);
                foreach (var image in images)
                {
                    try
                    {
                        if (_store.GetImage(request.SourceId, image.FromEntityId, image.Url) == null)
                        {
                            try
                            {
                                await _rest.DownloadImage(credential, request.SourceId, image.Id, image.Url, request.Token, GetImageDirectory(request.SourceId), _tokenUrls);
                            }
                            catch (Exception e)
                            {
                                _logger.LogError(e.Message);
                                var url = image.Url;
                                var hostedContentIds = Regex.Matches(url, @"hostedContents\/(.+)\/\$value").GetGroupMatches();
                                if (hostedContentIds.Length == 1)
                                {
                                    var hostedContent = hostedContentIds.First();
                                    var id            = ExtractUrlFromHostedContent(url, hostedContent);
                                    if (string.IsNullOrEmpty(id.Url))
                                    {
                                        _logger.LogWarning($"hostedContents had no url: {Base64Decode(hostedContent)}");
                                    }
                                    await _rest.DownloadImage(credential, request.SourceId, image.Id, id.Url, request.Token, GetImageDirectory(request.SourceId), _tokenUrls);
                                }
                                else
                                {
                                    _logger.LogError("Unable to find hostedContent");
                                    throw;
                                }
                            }
                            image.Created = message.CreatedDateTime.Value;
                            await _events.Add(credential, request.SourceId, image.FromEntityId, "ImageCreated", image.ToJson(), message.CreatedDateTime.Value.ToUnixTimeMilliseconds());

                            _store.Add(request.SourceId, image);
                            ReplaceMessageContent(message, image);
                        }
                        else
                        {
                            ReplaceMessageContent(message, image);
                        }
                    }
                    catch (Exception e)
                    {
                        _logger.LogError(e, "Could not download image");
                    }
                }
            }
            await _rest.SaveResponse(credential, request.SourceId, null, TeamsRequestTypes.ChatMessages, new TeamsMessageData { Id = chat.Id, Topic = chat.Topic }, messages.ToJson());
        }
コード例 #2
0
 public async Task SaveResponse(Credential creds, Guid sourceId, string url, string category, object queryString, string response)
 {
     await _events.Add(creds, sourceId, Guid.NewGuid().ToString(), "RestApiRequest", new RestApiRequest
     {
         Uri      = url,
         Category = category,
         Data     = queryString.ToJson(),
         Method   = "GET",
         Response = response,
     }.ToJson(), DateTimeOffset.UtcNow.ToUnixTimeMilliseconds());
 }
コード例 #3
0
        public async Task SaveResponses(Credential credential, Guid sourceId, object responses)
        {
            var jsonArray = JArray.FromObject(responses);

            foreach (dynamic item in jsonArray)
            {
                var payload = new JsonPayload {
                    Url = item.url, Json = item.json
                };
                _logger.LogInformation($"Saving {payload.Url}");
                var json = JsonConvert.SerializeObject(payload);
                await _events.Add(credential, sourceId, Guid.NewGuid().ToString(), "JsonPayload", json, DateTimeOffset.UtcNow.ToUnixTimeMilliseconds());
            }
        }