0

I am using AWS SDK to send the sms to the mobile number for sending OTP through the SMS.

The Issue here I am facing is the SMS are only being sent during the day time according to Indian Standard Time (9 am to 9pm). If I try to send SMS request to the AWS SNS endpoint after 9 pm, then it will send the message after 9 am the next day.

The code is as below.

String ACCESS_KEY = env.getProperty("aws.access.key");
String SECRET_KEY = env.getProperty("aws.secret.access.key");

// Above we get the access and secret access key as credentials for the user.

String otp = getRandomNumberString();  // generates an OTP number of 4 digit

AmazonSNSClient snsClient = new AmazonSNSClient(new BasicAWSCredentials(ACCESS_KEY, 
         SECRET_KEY));

String message = "Your Connect OTP for Login/Signup is: " + otp
    + ".\nNote: Please DO NOT SHARE THIS OTP with anyone.\nThanks";
String phoneNumber = "+91" + String.valueOf(mobile); // Ex: +91XXX4374XX
String messageID = sendSMSMessage(snsClient, message, phoneNumber);

// The definition of method named "sendSMSMessage" as above is written below in next code block
//definition of method named "sendSMSMessage"

public static String sendSMSMessage(AmazonSNSClient snsClient, String message, String phoneNumber) {
    PublishResult result = snsClient
        .publish(new PublishRequest().withMessage(message).withPhoneNumber(phoneNumber));
    return result.getMessageId();
}
vahdet
  • 6,357
  • 9
  • 51
  • 106
  • 2
    It looks like nothing with the code, but the list item #3 in this answer: https://stackoverflow.com/a/42561149/4636715 – vahdet Dec 24 '19 at 10:36

1 Answers1

0

There are two types of SMS that you can send.

-Promotional Messages
-Transaction Messages

Promotional messages are like Advertisment. These Messges will not be delivered to DND numbers and also these messages can only be delivered between 9Am to 9PM as per NCPR guidelines.

Transaction Messages are sent for Transaction purpose like sending OTP and sending Payment confirmation. These messages can be delivered to any number 24/7.

So the problem is you need to change your SMS type to Transaction SMS

Mohan Murugesan
  • 246
  • 3
  • 8