Hi,
I am trying to get events for the incoming calls to a genesys agent. I have subscribed to calls using the NotificationsHandler as mentioned below, but I don't get any events. Using the same way for sms/emails worked as desired.
Could you please guide me on what am i doing wrong or there is some different procedure to do the same.
Do I need to use webRTC sdk along with.
In the end, I would like to mention that the code works fine and I get events when I have logged into the Genesys Cloud UI portal. However, when logged out from UI it doesn't work even when I am logging in and setting agent to ON QUEUE from backend.
And our requirement is to accept and answer the incoming call to agent from backend only.
Can you help me find what's wrong/missing.
Here's the snippet of NotificationHandler and implemented Listener-
NotificationHandler
NotificationHandler notificationHandler = NotificationHandler.Builder.standard()
.withWebSocketListener(new MyWebSocketListener())
.withNotificationListeners(new ArrayList<NotificationListener<?>>() {
{
add(new RoutingListener(resp.getUserId()));
add(new CallEventListener(resp.getUserId(), apiClient));
}
}).withAutoConnect(false).build();
Listener
CallEventListener implements NotificationListener {
private String topic;
private String userId;
ApiClient apiClient;
@Override
public String getTopic() {
return topic;
}
@Override
public Class<Call> getEventBodyClass() {
return Call.class;
}
ArrayList<String> conversationIds = new ArrayList<String>();
@Override
public void onEvent(NotificationEvent<?> event) {
System.out.println("In call event listener...");
String eventBody = event.getEventBodyRaw();
String topicName = event.getTopicName();
String user_Id = topicName.substring(topicName.indexOf("users.") + 6,
topicName.indexOf(".conversations.calls"));
String conversationId = ((Call) event.getEventBody()).getId();
ConversationsApi conversationApi = new ConversationsApi(apiClient);
Conversation result = null;
try {
result = conversationApi.getConversation(conversationId);
List<Participant> participant = result.getParticipants();
String participantId = null;
System.out.println("trying to get participant id");
for (Participant pt : participant) {
if (pt.getPurpose().equals("agent") && pt.getUserId().equals(user_Id)
&& pt.getCalls().get(0).getState().toString().equals("alerting")) {
participantId = pt.getId();
String ptUserId = pt.getUserId();
System.out.println("particiapant id found-> " + participantId + " userId-->> " + ptUserId);
break;
}
}
if (participantId == null) {
System.out.println("participant id found null, not going to accept the conversation");
return;
}
System.out.println("now trying to accept the conversation with id-> " + conversationId
+ " and participant id-> " + participantId);
conversationApi.patchConversationParticipant(conversationId, participantId,
new MediaParticipantRequest().state(StateEnum.CONNECTED));
System.out.println("accepted successfully");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ApiException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public CallEventListener(String userId, ApiClient apiClient) {
topic = "v2.users." + userId + ".conversations.calls";
this.userId = userId;
this.apiClient = apiClient;
}
}
Warms Regards,
Archana