Unable to recieve events for incoming voice calls for the agents

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

Hi Archana,

To determine that there are no issues with your code I would recommend using the notification tester and subscribe to the topic from there.
If you get notifications using the tester and no notifications using your code then there is an issue with the code.

Do I need to use webRTC sdk along with.

No, the standard platform SDK will work just fine with notifications.

Hey Ronan,

Thanks, this could be a great help. I will try it out.

I tried testing using notification tester, it turned out to be quite helpful and I was able to receive notifications for the call.
However, I am unable to answer the incoming call. I used this api to answer the call -

PATCH https://api.euw2.pure.cloud/api/v2/conversations/calls/{conversationId}/participants/{participantId}

i.e - https://api.euw2.pure.cloud/api/v2/conversations/calls/46b6745b-a423-4ef7-a64a-bff8031fd7c7/participants/08b67ced-48c7-429f-81ea-75f74e6e59dc

Request body-
{"state":"connected"}

I get the following error -

{
    "message": "Failed to update properties on conversation participant.",
    "code": "conversation.participant.update.invalid",
    "status": 400,
    "contextId": "cdb265cc-ab61-4b2c-99a2-8641aabc5891",
    "details": [],
    "errors": [

        {
            "message": "The participant has no active conversation.",
            "code": "conversation.error.participant.no.active.conversations",
            "status": 400,
            "details": [
                {
                    "fieldName": "state"
                }
            ]
        }
    ]
}

I picked the conversation id from the event fired during and incoming call and the participant is of the agent (having the correct user id)

Clearly, according to it there is no active conversation. However, I don't understand, why.
I have an incoming call and I am using the right api too to accept call.

Can you give hint on this?

Seems like the reason is that the participant id keeps on changing for each call alerting notification.
Call alerting timeout is 7 seconds.

Even when alerting timeout is 60 seconds, I am unable to answer a call. Hitting the patch api returns empty response. But call does not gets answered.

To accept an incoming call you must be authenticated using implicit grant or code authorization because only a "user" can accept a call.

Also, since you mentioned WebRTC I'll assume you're using a WebRTC station. There's a few more steps involved in answering calls using the API when using a WebRTC station. The following forum post outlines the necessary steps:

I am not using webRTC.
However, after increasing the alerting timeout and using the correct participant id (having state as alerting),I am able to answer the call.

Thanks for your time, Ronan.

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.