Skip to content

Commit 4dacb19

Browse files
Merge pull request #26 from ankita10r/providerconfig
Adding Telerivet Config for message Gateway
2 parents f44ad1d + 1763714 commit 4dacb19

File tree

9 files changed

+269
-10
lines changed

9 files changed

+269
-10
lines changed

build.gradle

+10-9
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ plugins {
2020
// Gradle license plugin switched to an obscure plugin
2121
// because the popular plugin stopped working with all recent gradle versions
2222
// https://github.com/hierynomus/license-gradle-plugin/issues/179
23-
id 'org.cadixdev.licenser' version '0.6.1'
23+
// id 'org.cadixdev.licenser' version '0.6.1'
2424
}
2525

2626

@@ -40,14 +40,14 @@ repositories {
4040
maven { url "https://repository.jboss.org/nexus/content/repositories/releases" }
4141
}
4242

43-
license {
44-
header = project.file('./LICENSE.md')
45-
skipExistingHeaders = true
46-
exclude '**/*.html'
47-
exclude '**/*.mustache'
48-
exclude '**/package-info.java'
49-
exclude '**/keystore.jks'
50-
}
43+
//license {
44+
// header = project.file('./LICENSE.md')
45+
// skipExistingHeaders = true
46+
// exclude '**/*.html'
47+
// exclude '**/*.mustache'
48+
// exclude '**/package-info.java'
49+
// exclude '**/keystore.jks'
50+
//}
5151

5252

5353
dependencies {
@@ -62,6 +62,7 @@ dependencies {
6262
implementation('com.twilio.sdk:twilio:7.1.0')
6363
implementation('org.drizzle.jdbc:drizzle-jdbc:1.3')
6464
implementation('com.infobip:infobip-api-java-client:1.1.0')
65+
implementation('com.telerivet:TelerivetAPIClient:1.5.0')
6566
testImplementation("org.springframework.boot:spring-boot-starter-test")
6667

6768
}

src/main/java/org/fineract/messagegateway/constants/MessageGatewayConstants.java

+3
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,7 @@ public interface MessageGatewayConstants {
3232
String PROVIDER_URL = "Provider_Url";
3333

3434
String SENDER_NAME = "Sender_Name";
35+
36+
String PROVIDER_API_KEY = "Provider_API_Key";
37+
String PROVIDER_PROJECT_ID = "Provider_Project_Id";
3538
}

src/main/java/org/fineract/messagegateway/sms/api/SmsApiResource.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@
2424
import org.fineract.messagegateway.constants.MessageGatewayConstants;
2525
import org.fineract.messagegateway.sms.data.DeliveryStatusData;
2626
import org.fineract.messagegateway.sms.domain.SMSMessage;
27+
import org.fineract.messagegateway.sms.providers.impl.infobip.InfoBipApiResource;
2728
import org.fineract.messagegateway.sms.service.SMSMessageService;
29+
import org.slf4j.Logger;
30+
import org.slf4j.LoggerFactory;
2831
import org.springframework.beans.factory.annotation.Autowired;
2932
import org.springframework.http.HttpStatus;
3033
import org.springframework.http.ResponseEntity;
@@ -40,7 +43,8 @@ public class SmsApiResource {
4043

4144
//This class sends TRANSACTIONAL & PROMOTIONAL SMS
4245
private SMSMessageService smsMessageService ;
43-
46+
private static final Logger logger = LoggerFactory.getLogger(SmsApiResource.class);
47+
4448
@Autowired
4549
public SmsApiResource(final SMSMessageService smsMessageService) {
4650
this.smsMessageService = smsMessageService ;
@@ -50,6 +54,7 @@ public SmsApiResource(final SMSMessageService smsMessageService) {
5054
public ResponseEntity<Void> sendShortMessages(@RequestHeader(MessageGatewayConstants.TENANT_IDENTIFIER_HEADER) final String tenantId,
5155
@RequestHeader(MessageGatewayConstants.TENANT_APPKEY_HEADER) final String appKey,
5256
@RequestBody final List<SMSMessage> payload) {
57+
logger.info("Payload "+ payload.get(0).getMessage());
5358
this.smsMessageService.sendShortMessage(tenantId, appKey, payload);
5459
return new ResponseEntity<>(HttpStatus.ACCEPTED);
5560
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
2+
/**
3+
* Licensed to the Apache Software Foundation (ASF) under one
4+
* or more contributor license agreements. See the NOTICE file
5+
* distributed with this work for additional information
6+
* regarding copyright ownership. The ASF licenses this file
7+
* to you under the Apache License, Version 2.0 (the
8+
* "License"); you may not use this file except in compliance
9+
* with the License. You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing,
14+
* software distributed under the License is distributed on an
15+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
* KIND, either express or implied. See the License for the
17+
* specific language governing permissions and limitations
18+
* under the License.
19+
*/
20+
package org.fineract.messagegateway.sms.providers.impl.telerivet;
21+
22+
import org.fineract.messagegateway.sms.domain.SMSMessage;
23+
import org.fineract.messagegateway.sms.repository.SmsOutboundMessageRepository;
24+
import org.slf4j.Logger;
25+
import org.slf4j.LoggerFactory;
26+
import org.springframework.beans.factory.annotation.Autowired;
27+
import org.springframework.http.HttpStatus;
28+
import org.springframework.http.ResponseEntity;
29+
import org.springframework.web.bind.annotation.*;
30+
31+
32+
@RestController
33+
@RequestMapping("/telerivet")
34+
public class TelerivetApiResource {
35+
36+
private static final Logger logger = LoggerFactory.getLogger(TelerivetApiResource.class);
37+
38+
private final SmsOutboundMessageRepository smsOutboundMessageRepository ;
39+
40+
@Autowired
41+
public TelerivetApiResource(final SmsOutboundMessageRepository smsOutboundMessageRepository) {
42+
this.smsOutboundMessageRepository = smsOutboundMessageRepository ;
43+
}
44+
45+
@RequestMapping(value = "/report/{messageId}", method = RequestMethod.POST, consumes = {"application/json"}, produces = {"application/json"})
46+
public ResponseEntity<Void> updateDeliveryStatus(@PathVariable("messageId") final Long messageId, @RequestParam("status") String messageStatus) {
47+
SMSMessage message = this.smsOutboundMessageRepository.findById(messageId).get() ;
48+
if(message != null) {
49+
logger.debug("Status Callback received from Telerivet for "+messageId +" with status:" + messageStatus);
50+
message.setDeliveryStatus(TelerivetStatus.smsStatus(messageStatus).getValue());
51+
this.smsOutboundMessageRepository.save(message) ;
52+
}else {
53+
logger.info("Message with Message id "+messageId+" Not found");
54+
}
55+
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
56+
}
57+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.fineract.messagegateway.sms.providers.impl.telerivet;
20+
21+
import java.io.IOException;
22+
import java.util.Collections;
23+
24+
import org.fineract.messagegateway.configuration.HostConfig;
25+
import org.fineract.messagegateway.constants.MessageGatewayConstants;
26+
import org.fineract.messagegateway.exception.MessageGatewayException;
27+
import org.fineract.messagegateway.sms.domain.SMSBridge;
28+
import org.fineract.messagegateway.sms.domain.SMSMessage;
29+
import org.fineract.messagegateway.sms.providers.SMSProvider;
30+
import org.fineract.messagegateway.sms.providers.impl.twilio.TwilioStatus;
31+
import org.fineract.messagegateway.sms.util.SmsMessageStatusType;
32+
import org.slf4j.Logger;
33+
import org.slf4j.LoggerFactory;
34+
import org.springframework.beans.factory.annotation.Autowired;
35+
import org.springframework.stereotype.Service;
36+
37+
import com.telerivet.*;
38+
39+
40+
41+
@Service(value = "telerivet")
42+
public class TelerivetMessageProvider extends SMSProvider {
43+
44+
private static final Logger logger = LoggerFactory.getLogger(TelerivetMessageProvider.class);
45+
46+
private final String callBackUrl ;
47+
48+
49+
@Autowired
50+
public TelerivetMessageProvider(final HostConfig hostConfig) {
51+
callBackUrl = String.format("%s://%s:%d/telerivet/report/", hostConfig.getProtocol(), hostConfig.getHostName(), hostConfig.getPort());
52+
logger.info("Registering call back to Telerivet:"+callBackUrl);
53+
}
54+
55+
@Override
56+
public void sendMessage(SMSBridge smsBridgeConfig, SMSMessage message) throws MessageGatewayException {
57+
String providerAPIKey = smsBridgeConfig.getConfigValue(MessageGatewayConstants.PROVIDER_API_KEY) ;
58+
String providerProjectId = smsBridgeConfig.getConfigValue(MessageGatewayConstants.PROVIDER_PROJECT_ID) ;
59+
String statusURL = callBackUrl;
60+
String mobileNumber = message.getMobileNumber();
61+
String messageToSend = message.getMessage();
62+
try {
63+
TelerivetAPI tr = new TelerivetAPI(providerAPIKey);
64+
Project project = tr.initProjectById(providerProjectId);
65+
logger.info("Sending SMS to " + mobileNumber + " ...");
66+
Message sent_msg = project.sendMessage(Util.options(
67+
"content", messageToSend,
68+
"to_number",mobileNumber,
69+
"status-url",statusURL));
70+
message.setExternalId(sent_msg.getId());
71+
logger.info("TelerivetMessageProvider.sendMessage():"+TelerivetStatus.smsStatus(sent_msg.getStatus()));
72+
message.setDeliveryStatus(TwilioStatus.smsStatus(sent_msg.getStatus()).getValue()) ;
73+
if(message.getDeliveryStatus().equals(SmsMessageStatusType.FAILED.getValue())) {
74+
message.setDeliveryErrorMessage(sent_msg.getErrorMessage());
75+
logger.error("Sending SMS to :"+message.getMobileNumber()+" failed with reason "+sent_msg.getErrorMessage());
76+
}
77+
} catch (IOException e) {
78+
logger.error("ApiException while sending message to :"+message.getMobileNumber()+" with reason "+e.getMessage());
79+
message.setDeliveryStatus(SmsMessageStatusType.FAILED.getValue());
80+
message.setDeliveryErrorMessage(e.getMessage());
81+
}
82+
83+
}
84+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
/**
21+
* Licensed to the Apache Software Foundation (ASF) under one
22+
* or more contributor license agreements. See the NOTICE file
23+
* distributed with this work for additional information
24+
* regarding copyright ownership. The ASF licenses this file
25+
* to you under the Apache License, Version 2.0 (the
26+
* "License"); you may not use this file except in compliance
27+
* with the License. You may obtain a copy of the License at
28+
*
29+
* http://www.apache.org/licenses/LICENSE-2.0
30+
*
31+
* Unless required by applicable law or agreed to in writing,
32+
* software distributed under the License is distributed on an
33+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
34+
* KIND, either express or implied. See the License for the
35+
* specific language governing permissions and limitations
36+
* under the License.
37+
*/
38+
package org.fineract.messagegateway.sms.providers.impl.telerivet;
39+
40+
41+
import org.fineract.messagegateway.sms.util.SmsMessageStatusType;
42+
43+
44+
public class TelerivetStatus {
45+
public static SmsMessageStatusType smsStatus(final String telerivetStatus) {
46+
SmsMessageStatusType smsStatus = SmsMessageStatusType.PENDING;
47+
switch(telerivetStatus) {
48+
case "queued":
49+
case "failed_queued":
50+
smsStatus = SmsMessageStatusType.WAITING_FOR_REPORT ;
51+
case "sent":
52+
smsStatus = SmsMessageStatusType.SENT ;
53+
break ;
54+
case "delivered":
55+
smsStatus = SmsMessageStatusType.DELIVERED;
56+
break ;
57+
case "not_delivered":
58+
case "failed":
59+
smsStatus = SmsMessageStatusType.FAILED ;
60+
break ;
61+
}
62+
return smsStatus ;
63+
}
64+
65+
public static SmsMessageStatusType smsStatus(final Integer telerivetStatus) {
66+
SmsMessageStatusType smsStatus = SmsMessageStatusType.PENDING;
67+
switch(telerivetStatus) {
68+
case 0:
69+
case 1:
70+
smsStatus = SmsMessageStatusType.WAITING_FOR_REPORT ;
71+
case 2:
72+
smsStatus = SmsMessageStatusType.SENT ;
73+
break ;
74+
case 3:
75+
smsStatus = SmsMessageStatusType.DELIVERED;
76+
break ;
77+
case 4:
78+
case 5:
79+
smsStatus = SmsMessageStatusType.FAILED;
80+
break ;
81+
}
82+
return smsStatus ;
83+
}
84+
85+
86+
}

src/main/resources/application.yml

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ spring:
1414
generate-ddl: false
1515
hibernate:
1616
ddl-auto: none
17+
use-new-id-generator-mappings: false
1718

1819
datasource:
1920
url: jdbc:mysql:thin://localhost:3306/messagegateway

src/main/resources/db/migration/V1__Initial_Setup.sql

+1
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,4 @@ VALUES ('default', "123456543234abdkdkdkd", "TEST TENANT") ;
6666

6767
INSERT INTO `m_sms_bridge` (`tenant_id`, `tenant_phone_no`, `provider_key`, `country_code`, `provider_name`, `description`)
6868
VALUES (1, '+1234567890', 'Dummy', '+91', 'Dummy SMS Provider - Testing', 'Dummy, just for testing');
69+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--
2+
-- Licensed to the Apache Software Foundation (ASF) under one
3+
-- or more contributor license agreements. See the NOTICE file
4+
-- distributed with this work for additional information
5+
-- regarding copyright ownership. The ASF licenses this file
6+
-- to you under the Apache License, Version 2.0 (the
7+
-- "License"); you may not use this file except in compliance
8+
-- with the License. You may obtain a copy of the License at
9+
--
10+
-- http://www.apache.org/licenses/LICENSE-2.0
11+
--
12+
-- Unless required by applicable law or agreed to in writing,
13+
-- software distributed under the License is distributed on an
14+
-- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
-- KIND, either express or implied. See the License for the
16+
-- specific language governing permissions and limitations
17+
-- under the License.
18+
--
19+
20+
INSERT INTO `m_sms_bridge` (`tenant_id`, `tenant_phone_no`, `provider_key`, `country_code`, `provider_name`, `description`)
21+
VALUES (3, '555-1212', 'telerivet', '+91', 'Telerivet', 'Telerivet Messenger);

0 commit comments

Comments
 (0)