!7 sS chatBotID = #1026221; static long longPollMaxWait = 60*1000; // must match value in chatBotID static long clientLatency = 10*1000; // how long we allow a client to take for reconnecting srecord BotConversationID(S dbID, long convoID) {} concept Customer { S cookie; long lastPing; BotConversationID botConversationID; bool active() { ret elapsedMS_timestamp(lastPing) <= longPollMaxWait+clientLatency; } } concept Message { Customer customer; S text; bool unread; } concept IncomingMessage > Message {} concept OutgoingMessage > Message {} module MultiComm { start { dbIndexing(Customer, 'cookie); dm_vmBus_onMessage_q chatBot_userPolling(voidfunc(O mc, virtual Conversation conv) { Customer c = customerFromConv(mc, conv); if (c == null) ret; }); dm_vmBus_onMessage_q chatBot_messageAdded(voidfunc(O mc, virtual Conversation conv, virtual Msg msg) { Customer c = customerFromConv(mc, conv); if (c == null) ret; S text = getString text(msg); bool fromUser = getBool fromUser(msg); if (fromUser) cnew(IncomingMessage, customer := c, +text, unread := true); else cnew(OutgoingMessage, customer := c, +text); }); } visualize { /*showConceptsTable_postProcess.set(func(L l) -> L { filter(l, c -> c.active()) });*/ JTable tblCustomers = makeConceptsTable(Customer, /*defaultConceptRendererForTable(Customer)*/); ret jhsplit( jCenteredSection("Customers", tblCustomers), jCenteredSection("Messages", makeConceptsTable(Message))); } Customer customerFromConv(O mc, virtual Conversation conv) { S cookie = getString cookie(conv); if (empty(cookie)) null; Customer c = uniq(Customer, +cookie); cset(c, lastPing := now(), botConversationID := BotConversationID(programID(mc), getLong id(conv)); ret c; } }