Intermittent UserPresence Websocket Events

Hello Pureclouders,

I'm having an issue where I sometimes to do not receive a websocket event when changing a user's status via Purecloud Java SDK. I've included the code where I call the UserPresence API, a request that had a corresponding websocket event and also a request that did not have a corresponding websocket event.

Steps to reproduce in my application:
1.) Place an outbound call
2.) Before outbound call is placed, I set the user's status to "Busy" in Purecloud. Observe websocket event.
3.) Hang up the outbound call.
4.) ACW starts and I get a status event from Purecloud.
5.) Place another outbound call right after hanging up.
6.) I do not see websocket event for setting the user's presence to "Busy" a second time.
7.) Hang up 2nd outbound call and observe ACW status event as expected.

Method where I call the presenceApi's patchUserIdPresenceSourceId(), however as you can see from the requests below, they are identical and I would expect both to have a corresponding websocket event. It's interesting, if I wait for a few seconds before placing another call, I seem to get the websocket event again.

   public void userPresence(String agentId, com.asurion.pss.pathfinder.telephony.dto.UserPresence userPresence) throws TelephonyException {
      String userId = getCurrentUserId();
      presenceApi.setApiClient(apiClientProvider.getApiClient());
      UserPresence body = purecloudApiFactory.buildUserPresence();
      OrganizationPresence updatepresence = null;
      OrganizationPresence primaryPresence = null;
      OrganizationPresence secondaryPresence = null;

      try {
         OrganizationPresenceEntityListing availableSystemPresences = getPresenceDefinitions();

         for (OrganizationPresence presence : availableSystemPresences.getEntities()) {

            if (!StringUtils.isEmpty(userPresence.getSecondaryPresence())) {
               if (userPresence.getSecondaryPresence().equals(presence.getLanguageLabels().get(TelephonyConstants.DEFAULT_LOCALE))) {
                  secondaryPresence = presence;
                  break;
               }

               if ((presence.getSystemPresence().equalsIgnoreCase(userPresence.getPrimaryPresence()))) {
                  primaryPresence = presence;
               }
            } else {
               if ((userPresence.getPrimaryPresence().equalsIgnoreCase(presence.getLanguageLabels().get(TelephonyConstants.DEFAULT_LOCALE)))) {
                  primaryPresence = presence;
                  break;
               }
            }
         }

         updatepresence = secondaryPresence != null ? secondaryPresence : primaryPresence;
         
         RoutingStatus routingStatus = null;
         if(TelephonyConstants.ON_QUEUE.equals(updatepresence.getLanguageLabels().get(TelephonyConstants.DEFAULT_LOCALE))) {
        	 routingStatus = getRoutingStatus(userId);
         }
         if (routingStatus != null && RoutingStatus.StatusEnum.NOT_RESPONDING.equals(routingStatus.getStatus())) {
        	 setIdleRoutingStatus(userId);
         } else {
        	 Call call = getAcwParticipant();

             body.setPresenceDefinition(updatepresence);
             log.debug("body >>>> " + body);
             UserPresence result = presenceApi.patchUserIdPresencesSourceId(userId, TelephonyConstants.PURECLOUD, body);

             log.debug("Result: " + result);

             if (call != null) {
            	 doWrapup(call.getId(), call.getParticipantId());
             } 
         }
         
      } catch (ApiException e) {
         throw new TelephonyException(TelephonyErrorConstants.USER_PRESENCE,
               "Exception when calling PresenceApi#patchUserIdPresencesSourceId agent: "+
               agentId, e);
      }
   }

Request where I see a corresponding websocket event subsequently:

:03-30-2017 18:23:01.941 [http-nio-12090-exec-10] DEBUG c.mypurecloud.sdk.SLF4JInterceptor SEAN.ROMOCKI sid:a0726722-ed42-4941-85e4-39588b51b0e2 tid:c81decfd-96de-407f-8b3b-27d685b32fe0 carrier:rakuten <<<< PATCH /api/v2/users/55c1a7ae-79d3-48cb-8004-16be6bcebe50/presences/PURECLOUD <<<<
 200 OK  (131 ms)
---- HEADERS ----
Cache-Control: no-cache, no-store, must-revalidate
Connection: keep-alive
Content-Length: 328
Content-Type: application/json
Date: Thu, 30 Mar 2017 23:23:01 GMT
Expires: 0
ININ-Correlation-Id: b5c07233-17f9-41c6-8bde-3f55b2f0a64c
Pragma: no-cache
inin-ratelimit-allowed: 180
inin-ratelimit-count: 4
inin-ratelimit-reset: 47
---- BODY (328 bytes) ----
{"source":"PURECLOUD","presenceDefinition":{"id":"31fe3bac-dea6-44b7-bed7-47f91660a1a0","systemPresence":"Busy","selfUri":"/api/v2/presencedefinitions/31fe3bac-dea6-44b7-bed7-47f91660a1a0"},"message":"","modifiedDate":"2017-03-30T23:23:01.882Z","selfUri":"/api/v2/users/55c1a7ae-79d3-48cb-8004-16be6bcebe50/presences/PURECLOUD"}
<<<< END <<<<

Websocket User Presence Event received:

{
localTime: 2017 - 03 - 30 T18: 23: 02.024,
utcDateTime: 2017 - 03 - 30 T23: 23: 02.024 Z,
carrier: rakuten,
severity: INFO,
userId: SEAN.ROMOCKI,
sessionId: 1 df110e8-6d2e-4f62-a912-032df875b3b2,
supportSessionId: a0726722-ed42-4941-85e4-39588b51b0e2,
message: {
	topicName: v2.users.55c1a7ae-79d3-48cb-8004-16be6bcebe50.presence,
	version: 2,
	eventBody: {
		source: PURECLOUD,
		presenceDefinition: {
			id: 31fe3bac-dea6-44b7-bed7-47f91660a1a0,
			systemPresence: BUSY
		},
		primary: true,
		message:
	},
	metadata: {
		CorrelationId: b5c07233-17f9-41c6-8bde-3f55b2f0a64c
	}
  }
}

Request where I do not see a corresponding websocket event:

:03-30-2017 18:23:16.162 [http-nio-12090-exec-2] DEBUG c.mypurecloud.sdk.SLF4JInterceptor SEAN.ROMOCKI sid:a0726722-ed42-4941-85e4-39588b51b0e2 tid:8368f4c2-f889-4706-98de-a50fc7a38323 carrier:rakuten <<<< PATCH /api/v2/users/55c1a7ae-79d3-48cb-8004-16be6bcebe50/presences/PURECLOUD <<<<
     200 OK  (81 ms)
---- HEADERS ----
Cache-Control: no-cache, no-store, must-revalidate
Connection: keep-alive
Content-Length: 328
Content-Type: application/json
Date: Thu, 30 Mar 2017 23:23:16 GMT
Expires: 0
ININ-Correlation-Id: 3bd7618c-024e-4dbd-a56c-4ecd80b40241
Pragma: no-cache
inin-ratelimit-allowed: 180
inin-ratelimit-count: 6
inin-ratelimit-reset: 33
---- BODY (328 bytes) ----
{"source":"PURECLOUD","presenceDefinition":{"id":"31fe3bac-dea6-44b7-bed7-47f91660a1a0","systemPresence":"Busy","selfUri":"/api/v2/presencedefinitions/31fe3bac-dea6-44b7-bed7-47f91660a1a0"},"message":"","modifiedDate":"2017-03-30T23:23:01.882Z","selfUri":"/api/v2/users/55c1a7ae-79d3-48cb-8004-16be6bcebe50/presences/PURECLOUD"}
<<<< END <<<<

Any insights are appreciated!

Thanks,
Sean

Can you open a ticket for this with PureCloud Support? Troubleshooting missing notifications isn't something that can be done through the forum.

Hey Tim,

Funny you should say that. I already did previously open a ticket to the support forum #00048034 and they told me to write a post to the forums. Looks like there is some confusion around whose court it should be in.

Thanks,
Sean

Thanks for the ticket number. I'll check with the engineer.