Add chat username to TextMatchMatched
This commit is contained in:
parent
8560bbbf31
commit
90eeb7f851
@ -9,7 +9,7 @@
|
||||
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.5.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Label="Serilog">
|
||||
<PackageVersion Include="Nocr.TelegramListener.Async.Api.Contracts" Version="0.3.0" />
|
||||
<PackageVersion Include="Nocr.TelegramListener.Async.Api.Contracts" Version="0.4.4" />
|
||||
<PackageVersion Include="RestEase" Version="1.6.4" />
|
||||
<PackageVersion Include="Serilog" Version="3.1.1" />
|
||||
<PackageVersion Include="Serilog.AspNetCore" Version="8.0.1" />
|
||||
|
||||
@ -34,19 +34,21 @@ public sealed class MessageReceivedHandler : IHandleMessages<MessageReceived>
|
||||
|
||||
foreach (var match in matches)
|
||||
{
|
||||
if (match.IsMatches(message.ChatId, message.ChatUserName, message.Text))
|
||||
if (match.IsMatches(message.ChatId, message.ChatUsername, message.Text))
|
||||
{
|
||||
_logger.LogInformation("Message {@Message} matched {@Match}", message, match);
|
||||
var @event = new TextMatchMatched
|
||||
{
|
||||
ChatId = message.ChatId,
|
||||
ChatUsername = message.ChatUsername,
|
||||
Text = message.Text,
|
||||
UserId = message.From,
|
||||
OccuredDateTime = message.OccuredDateTime,
|
||||
PublishedDateTime = _dateProvider.UtcNow
|
||||
};
|
||||
|
||||
await _bus.Advanced.Topics.Publish("nocr.text.matcher", @event);
|
||||
// TODO:
|
||||
await _bus.Advanced.Topics.Publish("nocr.text.matcher.matched", @event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
using Nocr.TextMatcher.AppServices.Contracts.TextMatches;
|
||||
|
||||
namespace Nocr.TextMatcher.AppServices.TextMatches.Repositories;
|
||||
|
||||
public sealed class InMemoryTextMatchRepository : ITextMatchRepository
|
||||
@ -6,12 +8,26 @@ public sealed class InMemoryTextMatchRepository : ITextMatchRepository
|
||||
|
||||
private List<TextMatch> _textMatches = new List<TextMatch>();
|
||||
|
||||
public InMemoryTextMatchRepository()
|
||||
{
|
||||
var seed = new[]
|
||||
{
|
||||
TextMatch.Initialize(1, "baraholka_tbi", "телевизор", TextMatchRule.Full, DateTimeOffset.UtcNow),
|
||||
TextMatch.Initialize(1, "baraholka_tbi", "macbook mac", TextMatchRule.AnyWord, DateTimeOffset.UtcNow),
|
||||
TextMatch.Initialize(1, "baraholka_tbi", "гитар", TextMatchRule.Full, DateTimeOffset.UtcNow),
|
||||
TextMatch.Initialize(1, "baraholka_tbi", "обувь ботинки туфли", TextMatchRule.AnyWord, DateTimeOffset.UtcNow),
|
||||
TextMatch.Initialize(1, "baraholka_tbi", "одежда платья брюки рубашка рубашки", TextMatchRule.AnyWord, DateTimeOffset.UtcNow),
|
||||
};
|
||||
|
||||
_textMatches.AddRange(seed);
|
||||
}
|
||||
|
||||
public Task<long> Create(TextMatch textMatch, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var id = Interlocked.Increment(ref _id);
|
||||
textMatch.Id = id;
|
||||
_textMatches.Add(textMatch);
|
||||
|
||||
|
||||
return Task.FromResult(id);
|
||||
}
|
||||
|
||||
@ -19,7 +35,7 @@ public sealed class InMemoryTextMatchRepository : ITextMatchRepository
|
||||
{
|
||||
var index = _textMatches.FindIndex(x => x.Id == id);
|
||||
_textMatches.RemoveAt(index);
|
||||
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
|
||||
@ -31,7 +31,8 @@ public sealed class TextMatchService : ITextMatchService
|
||||
ChatUsername = textMatch.ChatUsername
|
||||
};
|
||||
|
||||
await _bus.Advanced.Topics.Publish("nocr.text.matcher", @event);
|
||||
// TODO:
|
||||
await _bus.Advanced.Topics.Publish("nocr.text.matcher.matches", @event);
|
||||
|
||||
return textMatch.Id;
|
||||
}
|
||||
|
||||
@ -6,7 +6,9 @@ public class TextMatchMatched : IEvent
|
||||
|
||||
public long UserId { get; set; }
|
||||
|
||||
public long ChatId { get; set; }
|
||||
public long? ChatId { get; set; }
|
||||
|
||||
public string ChatUsername { get; set; } = null!;
|
||||
|
||||
public string Text { get; set; }
|
||||
|
||||
|
||||
@ -12,7 +12,6 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Label="Rebus">
|
||||
<PackageReference Include="Rebus.ServiceProvider" />
|
||||
<PackageReference Include="Rebus.RabbitMq" />
|
||||
<PackageReference Include="Rebus.Serilog" />
|
||||
</ItemGroup>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user