Created
September 7, 2016 02:12
-
-
Save steveperkins/85dbcc909d462ca3dd18bd33e3d39de1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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