use of org.motechproject.mots.dto.VotoResponseDto in project mots by motech-implementations.
the class IvrService method sendModuleAssignedMessage.
private void sendModuleAssignedMessage(String subscriberId) throws IvrException {
IvrConfig ivrConfig = ivrConfigService.getConfig();
String messageId = ivrConfig.getModuleAssignedMessageId();
String sendSmsIfVoiceFails = boolToIntAsString(ivrConfig.getSendSmsIfVoiceFails());
String detectVoiceMailAction = boolToIntAsString(ivrConfig.getDetectVoicemailAction());
String retryAttemptsShort = Integer.toString(ivrConfig.getRetryAttemptsShort());
String retryDelayShort = Integer.toString(ivrConfig.getRetryDelayShort());
String retryAttemptsLong = Integer.toString(ivrConfig.getRetryAttemptsLong());
String retryDelayLong = Integer.toString(ivrConfig.getRetryDelayLong());
MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
params.add(SEND_TO_SUBSCRIBERS, subscriberId);
params.add(MESSAGE_ID, messageId);
params.add(SEND_SMS_IF_VOICE_FAILS, sendSmsIfVoiceFails);
params.add(DETECT_VOICEMAIL_ACTION, detectVoiceMailAction);
params.add(RETRY_ATTEMPTS_SHORT, retryAttemptsShort);
params.add(RETRY_DELAY_SHORT, retryDelayShort);
params.add(RETRY_ATTEMPTS_LONG, retryAttemptsLong);
params.add(RETRY_DELAY_LONG, retryDelayLong);
sendVotoRequest(getAbsoluteUrl(SEND_MESSAGE_URL), params, new ParameterizedTypeReference<VotoResponseDto<String>>() {
}, HttpMethod.POST);
}
use of org.motechproject.mots.dto.VotoResponseDto in project mots by motech-implementations.
the class IvrService method sendVotoRequest.
private <T> T sendVotoRequest(String url, MultiValueMap<String, String> params, ParameterizedTypeReference<T> responseType, HttpMethod method) throws IvrException {
params.add(API_KEY, ivrApiKey);
HttpHeaders headers = new HttpHeaders();
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(url).queryParams(params);
HttpEntity<?> request = new HttpEntity<>(headers);
try {
ResponseEntity<T> responseEntity = restTemplate.exchange(builder.build().toString(), method, request, responseType);
return responseEntity.getBody();
} catch (RestClientResponseException ex) {
String responseBodyJson = ex.getResponseBodyAsString();
String responseMessage = responseBodyJson;
String clearVotoInfo = "";
try {
VotoResponseDto<String> votoResponse = mapper.readValue(responseBodyJson, new TypeReference<VotoResponseDto<String>>() {
});
if (votoResponse.getMessage() != null) {
responseMessage = votoResponse.getMessage();
clearVotoInfo = "Invalid IVR service response: " + responseMessage;
}
} catch (IOException e) {
responseMessage = responseBodyJson;
}
String message = "Invalid IVR service response: " + ex.getRawStatusCode() + " " + ex.getStatusText() + ", Response body: " + responseMessage;
throw new IvrException(message, ex, clearVotoInfo);
} catch (RestClientException ex) {
String message = "Error occurred when sending request to IVR service: " + ex.getMessage();
throw new IvrException(message, ex);
}
}
Aggregations