public void SaveMessage(IBotInputChat chat, IBotInputMessage message) { if (ById(message.Id) == null) { AddEntity( new BotMessage { Id = message.Id, ChatId = chat.Id, PlatformId = chat.PlatformId } ); } }
private void RootMessageHandler(IBotInputMessage inputMessage, IBotInputChat inputChat) { using var provider = BuildMessageControllerProvider(inputMessage, inputChat); EnsureChatSaved(provider, inputChat); var chat = FindChat(provider, inputChat); var messageAction = FindMessageAction(chat, inputMessage); var query = ConvertMessageToQuery(provider, messageAction, inputChat); Log(inputChat); Log(chat); Log(inputMessage); SaveMessage(provider, inputChat, inputMessage); if (messageAction == null) { throw new ArgumentOutOfRangeException("No message handler for this message"); } RootQueryHandler(query, inputChat); }
private bool IsMessageActionMatch(MessageAction action, IBotChat chat, IBotInputMessage message) => action.Metadata.MessagePattern.IsMatch(message.Content) && action.Metadata.LatestQuery.IsMatch(chat.LastExecutedQuery);
private void HandleMessage(IBotInputMessage inputMessage, IBotInputChat inputChat) => TryToExecute(() => RootMessageHandler(inputMessage, inputChat));
private ServiceProvider BuildMessageControllerProvider( IBotInputMessage message, IBotInputChat inputChat ) => CollectBaseServiceCollection() .AddSingleton(message) .AddSingleton(inputChat) .BuildServiceProvider();
private void SaveMessage( IServiceProvider provider, IBotInputChat chat, IBotInputMessage message ) => provider.GetRequiredService <IBotMessageService>().SaveMessage(chat, message);
private MessageAction FindMessageAction(IBotChat chat, IBotInputMessage message) => _messageActions.FirstOrDefault(action => IsMessageActionMatch(action, chat, message));
public string AcceptPhone(IBotInputMessage message) => $"order/phone/${message.Content}";
public string AcceptAddress(IBotInputMessage message) => $"order/address/{message.Content}";