private void OnClientMessage(object sender, MessageEventArgs e) { try { string username = $"{e.Message.Chat.FirstName} {e.Message.Chat.LastName}".Trim(); if (e.Message.Type != Telegram.Bot.Types.Enums.MessageType.Text) { _loggingService.Info($"Unknown image type from {username} : {e.Message.Type}"); return; } var chatMessage = ChatMessage.Create( e.Message.MessageId, e.Message.From.Id, Chat.Create(e.Message.Chat.Id, UserInfo.Create(e.Message.From.Id, username)), e.Message.Date, ChatMessageType.Incoming, e.Message.Text); _loggingService.Info($"New message from '{chatMessage.Chat.Id} ({username})': {chatMessage.Message}"); var messageEventArgs = NewMessageEventArgs.Create(chatMessage); NewMessage.Raise(this, messageEventArgs); } catch (Exception ex) { _loggingService.Error(ex); } }
private void GenerateMessages() { while (_isRunning) { Thread.Sleep(2000); int chatId = _randy.Next(3, 15); string username = $"Chat №{chatId}"; var chatMessage = ChatMessage.Create( _randy.Next(1, 30), chatId, Chat.Create(chatId, UserInfo.Create(chatId, username)), DateTime.UtcNow, ChatMessageType.Incoming, Guid.NewGuid().ToString("N")); _loggingService.Info($"New message from '{chatMessage.Chat.Id} ({username})': {chatMessage.Message}"); var messageEventArgs = NewMessageEventArgs.Create(chatMessage); NewMessage.Raise(this, messageEventArgs); } }