Skip to content

Instantly share code, notes, and snippets.

@steveperkins
Created September 7, 2016 02:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steveperkins/85dbcc909d462ca3dd18bd33e3d39de1 to your computer and use it in GitHub Desktop.
Save steveperkins/85dbcc909d462ca3dd18bd33e3d39de1 to your computer and use it in GitHub Desktop.
package org.lightside.notification;
import java.util.HashMap;
import java.util.Map;
import org.lightside.main.AwsClientFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.amazonaws.services.sns.model.MessageAttributeValue;
import com.amazonaws.services.sns.model.PublishRequest;
import com.amazonaws.services.sns.model.PublishResult;
public class SmsNotificationService {
private static final Logger LOG = LoggerFactory.getLogger(SmsNotificationService.class);
public PublishResult send(String phoneNumber, String message) {
Map<String, MessageAttributeValue> smsAttributes = new HashMap<String, MessageAttributeValue>();
smsAttributes.put("AWS.SNS.SMS.SenderID", new MessageAttributeValue()
.withStringValue("Lightside") //The sender ID shown on the device (except in US)
.withDataType("String"));
smsAttributes.put("AWS.SNS.SMS.MaxPrice", new MessageAttributeValue()
.withStringValue("0.01") //Sets the max price to 0.01 USD.
.withDataType("Number"));
smsAttributes.put("AWS.SNS.SMS.SMSType", new MessageAttributeValue()
.withStringValue("Promotional") //Sets the type to promotional.
.withDataType("String"));
PublishResult result = AwsClientFactory.getSnsClient().publish(new PublishRequest()
.withMessage(message)
.withPhoneNumber(phoneNumber)
.withMessageAttributes(smsAttributes));
LOG.info("Sent SMS message ID: " + result.getMessageId());
return result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment