I apologize for the confusion earlier. Here is a revised description of the testing method and the problem I am requesting help with.
I received an ACCESS_CODE through a code verification process.
ACCESS_CODE = '1EIUwKtS4CoJkEWSybeEyu1ZbyVzhRmItDg3P6akYinU5SsSgR2p8qVuhZpZ_zEDIgzZkJF1l9RN1zHVcexY8A';
used the purecloud library and created an object, and then received notifications via WebSocket.
I used the following code:
const platformClient = require('platformClient');
platformClient.ApiClient.instance.setAccessToken(ACCESS_CODE);
const client = platformClient.ApiClient.instance;
client.setEnvironment(platformClient.PureCloudRegionHosts.ap_northeast_2);
const conversationsApi = new platformClient.ConversationsApi();
const notificationsApi = new platformClient.NotificationsApi();
client.loginImplicitGrant(CLIENT_ID, REDIRECT_URI).then(() => {
return usersApi.getUsersMe();
})
.then((userMe) => {
me = userMe.body;
return notificationsApi.postNotificationsChannels();
})
.then((channel) => {
notificationChannel = channel.body;
webSocket = new WebSocket(notificationChannel.connectUri);
webSocket.onmessage = handleNotification;
conversationsTopic = 'v2.users.' + me.id + '.conversations';
const body = [ { id: conversationsTopic } ];
return notificationsApi.putNotificationsChannelSubscriptions(notificationChannel.id, body);
}).catch((err) => console.error(err));
function handleNotification(message) {
const notification = JSON.parse(message.data);
if (notification.topicName.toLowerCase() === 'channel.metadata') {
return;
} else if (notification.topicName.toLowerCase() !== conversationsTopic.toLowerCase()) {
return;
}
var conversation = notification.eventBody;
conversation.participants.forEach((participant) => {
if (!participant.calls || participant.calls.length === 0) return;
if(participant.calls[0].state === 'alerting'){
$("#noti_id").val(conversation.id);
$("#participant_id").val(participant.id);
}
});
}
I received a call and obtained a conversation ID: c86dfb59-2ce6-4882-babb-30e114239873 and a participant ID: 722c2d3f-89de-45ca-8fb5-0668e2776736. Then, I clicked the receive button:
$('button#btn_accept').click(() => {
var c_id = $("#noti_id").val();
var p_id = $("#participant_id").val();
call_accept(c_id, p_id);
});
function call_accept(conversationId, participantId) {
let body = {
'state': 'Connected'
};
conversationsApi.patchConversationsCallParticipant(conversationId, participantId, body)
.then((response) => {
console.log('response', response);
console.log('headers', response.headers);
}).catch((err) => console.error(err, err.body.message));
}
However, after clicking the receive button, the response showed up as follows, and the call continued to ring without being answered:
{
"status": 202,
"statusText": "",
"headers": {
"cache-control": "no-cache, no-store, must-revalidate",
"content-type": "application/json"
},
"body": {},
"error": null
}