コード例 #1
0
 public void SaveMessage(IBotInputChat chat, IBotInputMessage message)
 {
     if (ById(message.Id) == null)
     {
         AddEntity(
             new BotMessage {
             Id         = message.Id,
             ChatId     = chat.Id,
             PlatformId = chat.PlatformId
         }
             );
     }
 }
コード例 #2
0
ファイル: Bot.cs プロジェクト: JohnSutray/BotCore
        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);
        }
コード例 #3
0
ファイル: Bot.cs プロジェクト: JohnSutray/BotCore
 private bool IsMessageActionMatch(MessageAction action, IBotChat chat, IBotInputMessage message) =>
 action.Metadata.MessagePattern.IsMatch(message.Content) &&
 action.Metadata.LatestQuery.IsMatch(chat.LastExecutedQuery);
コード例 #4
0
ファイル: Bot.cs プロジェクト: JohnSutray/BotCore
 private void HandleMessage(IBotInputMessage inputMessage, IBotInputChat inputChat)
 => TryToExecute(() => RootMessageHandler(inputMessage, inputChat));
コード例 #5
0
ファイル: Bot.cs プロジェクト: JohnSutray/BotCore
 private ServiceProvider BuildMessageControllerProvider(
     IBotInputMessage message, IBotInputChat inputChat
     ) => CollectBaseServiceCollection()
 .AddSingleton(message)
 .AddSingleton(inputChat)
 .BuildServiceProvider();
コード例 #6
0
ファイル: Bot.cs プロジェクト: JohnSutray/BotCore
 private void SaveMessage(
     IServiceProvider provider, IBotInputChat chat, IBotInputMessage message
     ) => provider.GetRequiredService <IBotMessageService>().SaveMessage(chat, message);
コード例 #7
0
ファイル: Bot.cs プロジェクト: JohnSutray/BotCore
 private MessageAction FindMessageAction(IBotChat chat, IBotInputMessage message) =>
 _messageActions.FirstOrDefault(action => IsMessageActionMatch(action, chat, message));
コード例 #8
0
 public string AcceptPhone(IBotInputMessage message) => $"order/phone/${message.Content}";
コード例 #9
0
 public string AcceptAddress(IBotInputMessage message) => $"order/address/{message.Content}";