public void HandleUserMessage(ITelegramUserMessage message) { if (message.IsEmpty()) { return; } ISessionManager sessionManager = ModulesManager.GetModulesManager().GetSessionManager(); IChatSession chatSession = sessionManager.GetChatSession(message.ChatId); if (chatSession == null) { sessionManager.CreateChatSession(message.ChatId); chatSession = sessionManager.GetChatSession(message.ChatId); } sessionManager.UserSentMessage(message.ChatId, message.MessageId); if (string.Equals(message.Message, "/e") || string.Equals(message.Message, "/exit")) { sessionManager.KillChatSession(message.ChatId); } else { chatStateHandlerFactory.GetChatStateHandler(chatSession.State).HandleUserMessage(message, this); } }
public LoginMessageHandler( ITelegramBotClient telegramBotClient, IChatSession chatSession) { _telegramBotClient = telegramBotClient; _chatSession = chatSession; }
public void BotSentMessage(long chatId, int messageId) { if (IsChatSessionExist(chatId)) { IChatSession chatSession = currentChatSessions[chatId]; chatSession.BotSentMessage(messageId); } }
public RequestReplyMessageHandler( IUserChatHubSession userChatHubSession, IChatSession chatSession, ITelegramBotClient telegramBotClient) { _userChatHubSession = userChatHubSession; _chatSession = chatSession; _telegramBotClient = telegramBotClient; }
public override async Task SendMessageAsync(IChatSession sess, IOutgoingMessage msg) { if (!(sess is ChatSession)) { throw new Exception("Bad chat session type"); } var s = sess as ChatSession; switch (msg.Type) { case MsgOutType.Text: { var m = new TextMessage { Text = msg.Text, Receiver = s.InternalChatId }; await _cli.SendTextMessageAsync(m); break; } case MsgOutType.Keyboard: { var keyboardMsg = new KeyboardMessage { Text = msg.Text, Receiver = s.InternalChatId, Keyboard = GetViberKeyboard(msg.Keyboard.Buttons.ToArray()), MinApiVersion = 3 }; await _cli.SendKeyboardMessageAsync(keyboardMsg); break; } case MsgOutType.Photo: break; case MsgOutType.Wait: { var m = new TextMessage { Text = $"Нагадування встановлено", Receiver = s.InternalChatId }; await _cli.SendTextMessageAsync(m); break; } default: break; } }
protected override bool ParseIncomingMessage(String json, out IChatSession s, out IIncomingMessage m) { s = null; m = null; CallbackData data = JsonConvert.DeserializeObject <CallbackData>(json); switch (data.Event) { case EventType.Delivered: return(false); case EventType.Seen: return(false); case EventType.Failed: return(false); case EventType.Subscribed: { m = new IncomingMessage(); s = new ChatSession(data.User.Id); return(true); } case EventType.Unsubscribed: { s = new ChatSession(data.UserId); return(false); } case EventType.ConversationStarted: { return(false); } case EventType.Message: { m = new IncomingMessage(data); s = new ChatSession(data.Sender.Id); return(true); } case EventType.Webhook: { return(false); } case EventType.Action: return(false); default: return(false); } }
public ChatHubUserMessage( string text, DateTime sentAt, IChatHubHistory history, Func <IServiceProvider> serviceProviderFactory) : base(text, sentAt, history) { var provider = serviceProviderFactory(); _chatSession = provider.GetRequiredService <IChatSession>(); }
private void ClearSessions(object sender, ElapsedEventArgs e) { foreach (var s in currentChatSessions) { IChatSession chatSession = s.Value; if (chatSession.NeedKill()) { KillChatSession(chatSession.ChatId); } } }
public void GetChatSessionTest() { const int chatSessionId = 12; IChatSession chatSession1 = sessionManager.GetChatSession(chatSessionId); sessionManager.CreateChatSession(chatSessionId); IChatSession chatSession2 = sessionManager.GetChatSession(chatSessionId); Assert.AreEqual(chatSession1, null); Assert.AreNotEqual(chatSession2, null); }
public IEnumerable <IOutgoingMessage> ProcessIncomingMessage(IChatSession sess, IIncomingMessage msg) { var m = new IncomeMessage(sess.ChatId) { BotEngine = engine, BotKey = key, Message = msg }; bus.Send(m); yield break; }
public IChat StartChat(IBuddy buddy) { if (!IsLoggedIn) { throw new InvalidOperationException("Not logged in."); } IChatSession session = chatService.CreateSession(new SquiggleEndPoint(buddy.Id, ((Buddy)buddy).ChatEndPoint)); var chat = new Chat(session, CurrentUser, new[] { buddy }, id => buddies[id], history); return(chat); }
public ChatSession(IChatSession source) { var ba = source.ChatId.ToByteArray(); var i1 = BitConverter.ToInt64(ba, 0); var i2 = BitConverter.ToInt64(ba, 8); if (i1 != i2) { throw new Exception("Bad ChatId format"); } InternalChatId = i1; }
public void ChangeChatState(long chatId, ChatSessionState newState) { ISessionManager sessionManager = ModulesManager.GetSessionManager(); IChatSession chatSession = sessionManager.GetChatSession(chatId); if (chatSession != null) { chatSession.State = newState; chatStateHandlerFactory.GetChatStateHandler(chatSession.State).StartStateMessage(chatId); } }
public IChatSession CreateSession(ISquiggleEndPoint endPoint) { IChatSession result = chatSessions.Find(s => !s.IsGroupSession && s.RemoteUsers.Contains(endPoint)); if (result == null) { var session = CreateSession(Guid.NewGuid(), endPoint); session.Initialize(false); result = session; } return(result); }
protected override bool ParseIncomingMessage(String json, out IChatSession s, out IIncomingMessage m) { s = null; m = null; Update update = JsonConvert.DeserializeObject <Update>(json); switch (update.Type) { case UpdateType.Unknown: return(false); case UpdateType.Message: { m = new IncomingMessage(update.Message); s = new ChatSession(update.Message.Chat.Id); return(true); } case UpdateType.InlineQuery: return(false); case UpdateType.ChosenInlineResult: return(false); case UpdateType.CallbackQuery: { var message = update.CallbackQuery.Message; message.Text = update.CallbackQuery.Data; m = new IncomingMessage(message); s = new ChatSession(message.Chat.Id); return(true); } case UpdateType.EditedMessage: return(false); case UpdateType.ChannelPost: return(false); case UpdateType.EditedChannelPost: return(false); case UpdateType.ShippingQuery: return(false); case UpdateType.PreCheckoutQuery: return(false); default: return(false); } }
public LongPollingChat( IServiceScopeFactory serviceScopeFactory, ITelegramBotClient client, Func <UnitOfWork> uowFactory, IChatSession chatSession) { _serviceScopeFactory = serviceScopeFactory; _client = client; _uowFactory = uowFactory; _chatSession = chatSession; _client.OnUpdate += async(s, e) => await ClientOnOnUpdate(s, e); }
public AutoBotEngine(ILogger logger, IChatSession session) { this.Logger = logger; this.Session = session; this.Thread = new Thread(delegate() { while (this.IsRunning) { //TODO Add background task implementation here Thread.Sleep(1000); } Thread.CurrentThread.Abort(); } ); }
public ChatBuddies(IChatSession session, BuddyResolver buddyResolver, IEnumerable <IBuddy> buddies) { this.buddies = new Dictionary <string, IBuddy>(); this.buddyResolver = buddyResolver; this.session = session; foreach (Buddy buddy in buddies) { AddBuddy(buddy); } this.session.GroupChatStarted += session_GroupChatStarted; this.session.UserJoined += session_UserJoined; this.session.UserLeft += session_UserLeft; }
public Chat(IChatSession session, IBuddy self, IEnumerable <IBuddy> buddies, BuddyResolver buddyResolver, HistoryManager history) { this.self = self; this.buddies = new ChatBuddies(session, buddyResolver, buddies); this.buddies.BuddyJoined += buddies_BuddyJoined; this.buddies.BuddyLeft += buddies_BuddyLeft; this.buddies.GroupChatStarted += buddies_GroupChatStarted; this.session = session; session.MessageReceived += session_MessageReceived; session.MessageUpdated += session_MessageUpdated; session.UserTyping += session_UserTyping; session.BuzzReceived += session_BuzzReceived; session.ActivityInviteReceived += session_ActivityInviteReceived; this.history = history; }
public override async Task SendMessageAsync(IChatSession sess, IOutgoingMessage msg) { var ss = new ChatSession(sess); switch (msg.Type) { case MsgOutType.Text: { await _cli.SendTextMessageAsync(ss.GetChatId(), msg.Text); } break; case MsgOutType.Keyboard: { await _cli.SendTextMessageAsync ( ss.GetChatId(), msg.Text, ParseMode.Markdown, false, false, 0, GetTelegramKeyboard(msg.Keyboard) ); } break; case MsgOutType.Photo: break; case MsgOutType.Wait: { await _cli.SendTextMessageAsync(ss.GetChatId(), $"Нагадування встановлено"); break; } default: break; } }
public Task SendMessageAsync(IChatSession sess, IOutgoingMessage msg) { return(Task.CompletedTask); }
protected async Task ProcessIncomingMessageAsync(IMessageProcessor proc, IIncomingMessage msg, IChatSession sess) { var ms = proc.ProcessIncomingMessage(sess, msg); foreach (var m in ms) { await SendMessageAsync(sess, m); } }
protected abstract bool ParseIncomingMessage(String json, out IChatSession sess, out IIncomingMessage msg);
public ChatSession(IChatSession source) { var ba = source.ChatId.ToByteArray(); InternalChatId = Convert.ToBase64String(ba); }
public abstract Task SendMessageAsync(IChatSession sess, IOutgoingMessage msg);