Hello everyone,
I have maked this code in APEX on visual Studio, to send a WhatsApp message using this API: https://api.mypurecloud.de/api/v2/conversations/messages/agentless.
I create the Template On the WhatsApp integration with Meta.
I got the Id that i used to configure a Template In Genesys.
Using All that Informations i was able to create a code:
String client_id = 'XXXXXXXXXX';
String client_secret ='XXXXXXXXX';
String smsBody = thisAutoSms;
String accessToken = WSE012_SendWhatsAppMessageGenesys.getAccessToken(client_id, client_secret);
Http http = new Http();
HttpRequest request = new HttpRequest();
HttpResponse response = new HttpResponse();
request.setEndpoint('https://api.mypurecloud.de/api/v2/conversations/messages/agentless');
request.setMethod('POST');
request.setHeader('Content-Type', 'application/json');
request.setHeader('Authorization', 'Bearer ' +accessToken);
System.debug('jsonRep:' +accessToken);
String jsonReq = '';
String memberPhone = SendindPhoneNumber;
Map<String, Object> parameters = new Map<String, Object> {
'id' => '762c3e5d-a672-429c-ac3b-5e9d371cad3e',
'value' => ''
};
Map<String, Object> messagingTemplate = new Map<String, Object> {
'responseId' => '762c3e5d-a672-429c-ac3b-5e9d371cad3e',
'parameters' => new List<Map<String, Object>>{ parameters }
};
Map<String, Object> mapData = new Map<String, Object> {
'fromAddress' => '714175940796044', // (string required) The messaging address of the sender of the message. For an SMS messenger type, this must be a currently provisioned SMS phone number. For a WhatsApp messenger type use the provisioned WhatsApp integration’s ID.
'toAddress' => '33XXXXXXXX', // E.g. +13175555555 or +34234234234
'toAddressMessengerType' => 'whatsapp', // sms, whatsapp, open
// SMS - 765 characters, other channels - 2000 characters
'messagingTemplate ' => messagingTemplate, // (MessagingTemplateRequest) The messaging template to use in the case of WhatsApp messenger type
'useExistingActiveConversation' => TechUseExisting // A rajouter dans les champs d'un objet pour la surveillance du statut nouvelle conversation ou pas !
};
System.debug('mapData:' +mapData);
String mapString = (String) JSON.serialize(mapData);
jsonReq = mapString;
System.debug('jsonRep:' +jsonReq);
request.setBody(jsonReq);
if (Test.isRunningTest() && (mock!=null)) {
response = mock.respond(request);
} else {
response = http.send(request);
}
if (response.getStatusCode() == 202) {
String responseMessage = response.getBody();
System.debug('SMS sent successfully: ' + responseMessage);
} else {
String errorMessage = 'SMS sending failed with status code: ' + response.getStatusCode();
if (response.getBody() != null) {
errorMessage += ', Error Message: ' + response.getBody();
}
System.debug(errorMessage);
}
I'm receiving this error when trying to send a message using my Developper Console:
SMS sending failed with status code: 500, Error Message: {"message":"Internal server error. Type: java.lang.NullPointerException, Message: Cannot invoke "com.inin.contracts.ratatoskr.SendMessagingTemplate.getResponseId()" because the return value of "com.inin.contracts.ratatoskr.SendAgentlessOutboundMessage.getMessagingTemplate()" is null","code":"internal.server.error","status":500,"messageWithParams":"Internal server error. Type: {type}, Message: {message}","messageParams":{"type":"java.lang.NullPointerException","message":"Cannot invoke "com.inin.contracts.ratatoskr.SendMessagingTemplate.getResponseId()" because the return value of "com.inin.contracts.ratatoskr.SendAgentlessOutboundMessage.getMessagingTemplate()" is null"},"contextId":"6055b7d3-70dd-4b55-be48-9ba04905e59d","details":[],"errors":[]}
I have being doing many researchs and not founding nothing that can Help me.
Can you please take a look on this ?
Thank !