How to create events for a visitor that is already an intercom user?

We use both web library and intercom-java sdk to send events as some events can be sent from client side, but some need to be sent from server side. Here is how we send server side events:

  • When the visitor triggers some action, say a failed login attempt, we grab visitorId from web library window.Intercom("getVisitorId") and send it to the server
  • On the server side, we first try to find the visitor Visitor.findByUserID(visitorId), if it returnsNotFoundException, then we try to find the lead Contact.findByUserID(visitorId), if it returns NotFoundException, then we try to find currently logged in user from server session(I know, old technology), if no logged in user found, we can’t create the event because we don’t know who the user is. If any of the steps above succeeds, we can create the event with the returned user’s userId

The flow above usually works, however it doesn’t work when the visitor has already logged in, and remains in the same intercom session while the server session is cleared out - say we restarted the server after the visitor logged in. In this case, the visitorId doesn’t represent any visitor/lead anymore, and the user is no longer logged in to be found in the server session. So we don’t know how to identify the user on the server side to send the event.

This is not a problem for client side events. So my question is, is there a way to workaround this on the intercom-java sdk side?