Enhance Your Communication Strategy: Deliver Multimedia Messages With AWS Pinpoint
Incorporate AWS Pinpoint in communication microservice to send multimedia messages with attachments like images and PDFs.
Join the DZone community and get the full member experience.
Join For FreeIn today's digital world, email is the go-to channel for effective communication, with attachments containing flyers, images, PDF documents, etc. However, there could be business requirements for building a service for sending an SMS with an attachment as an MMS (Multimedia Messaging Service). This article delves into how to send multiple media messages (MMS), their limitations, and implementation details using the AWS Pinpoint cloud service.
Setting Up AWS Pinpoint Service
Setting Up Phone Pool
In the AWS console, we navigate to AWS End User Messaging and set up the Phone pool. The phone pool comprises the phone numbers from which we will send the message; these are the numbers from which the end user will receive the MMS message.
Figure 1: AWS End User Messaging
Figure 2: Phone Pool
We can add the origination numbers once the phone pool has been created. The originating numbers are 10DLC (10-digit long code). A2P (application-to-person) 10DLC is a method businesses use to send direct text messages to customers. It is the new US-wide system and standard for companies to communicate with customers via SMS or MMS messages.
Configure Configuration Set for Pinpoint MMS Messages
After creating the phone pool, we create the configuration set required to send the Pinpoint message.
Figure 3: Configuration Set
Configuration sets help us log our messaging events, and we can configure where to publish events by adding event destinations. In our case, we configure the destination as CloudWatch and add all MMS events.
Figure 4: Configuration Set Event destinations
Now that all the prerequisites for sending MMS messages are complete let's move on to the implementation part of sending the MMS message in our Spring Microservice.
Sending MMS
Implementations in Spring Microservice
To send the multimedia attachment, we first need to save the attachment to AWS S3 and then share the AWS S3 path and bucket name with the routing that sends the MMS.
Below is the sample implementation in the Spring Microservice for sending the multimedia message.
@Override
public String sendMediaMessage(NotificationData notification) {
String messageId = null;
logger.info("SnsProviderImpl::sendMediaMessage - Inside send message with media");
try {
String localePreference = Optional.ofNullable(notification.getLocalePreference()).orElse("en-US");
String originationNumber = "";
if (StringUtils.hasText(fromPhone)) {
JSONObject jsonObject = new JSONObject(fromPhone);
if (jsonObject != null && jsonObject.has(localePreference)) {
originationNumber = jsonObject.getString(localePreference);
}
}
SendMediaMessageRequest request = SendMediaMessageRequest.builder()
.destinationPhoneNumber(notification.getDestination())
.originationIdentity(originationNumber)
.mediaUrls(buildS3MediaUrls(notification.getAttachments()))
.messageBody(notification.getMessage())
.configurationSetName("pinpointsms_set1")
.build();
PinpointSmsVoiceV2Client pinpointSmsVoiceV2Client = getPinpointSmsVoiceV2Client();
SendMediaMessageResponse resp = pinpointSmsVoiceV2Client.sendMediaMessage(request);
messageId = resp != null && resp.sdkHttpResponse().isSuccessful() ? resp.messageId() : null;
} catch (Exception ex) {
logger.error("ProviderImpl::sendMediaMessage, an error occurred, detail error:", ex);
}
return messageId;
}
Here, the NotificationData
object is the POJO, which contains all the required attributes for sending the message. It contains the destination number and the list of attachments that need to be sent; ideally, there would be only one attachment. The Attachment
object contains the S3 path and the bucket name. Below is the implementation for buildS3MediaUrls
. We need to send the S3 path and bucket name in a specific format, as shown in the below implementation, it has to be s3://{{bucketName}}/{{S3Path}}
:
public List<String> buildS3MediaUrls(List<Attachment> attachments) {
List<String> urls = new ArrayList<>();
for (Attachment attachment : attachments) {
String url = String.format("s3://%s/%s",
attachment.getAttachmentBucket(),
attachment.getAttachmentFilePath());
urls.add(url);
}
return urls;
}
Here is the definition for getPinpointSmsVoiceV2Client
:
protected PinpointSmsVoiceV2Client getPinpointSmsVoiceV2Client() {
return PinpointSmsVoiceV2Client.builder()
.credentialsProvider(DefaultCredentialsProvider.create())
.region(Region.of(this.awsRegion)).build();
}
The messageId
returned persists in our database and is used to track the message status further.
Types of Attachments
We can send various multimedia content using Pinpoint such as images, PDF files, audio, and video files. This enables us to cater to various business use cases, such as sending new product details, invoices, estimates, etc. Attachment size has certain limitations: a single MMS message cannot exceed 600KB in size for media files. We can send various types of content, including:
- PDF - Portable Document Format
- Image files like PDG, JPEG, GIF
- Video/Audio - MP4, MOV
Limitations and Challenges
- AWS Pinpoint, with its scalable service, is a robust platform. However, it does have certain limitations, such as the attachment file size, which is capped at 600KB. This could pose a challenge when attempting to send high-resolution image files.
- Cost: Sending attachments for MMS is comparatively costlier than just sending SMS using AWS SNS. For MMS, the cost is $0.0195 (Base Price) + $0.0062 (Carrier Fee) = $0.0257 per message, while the cost for AWS SNS SMS is $0.00581 (Base Price) + $0.00302 (Carrier Fee) = $0.00883 per message. So, the MMS is three times costlier. AWS Pinpoint has a lot of messaging capabilities, including free messaging for specific types of messages like email, email, and push notifications. MMS is not part of the free tier.
- Tracking messages for end-to-end delivery can be challenging. Usually, with the AWS Lambda and CloudWatch combination, we should be able to track it end to end, but this requires additional setup.
- Opening attachments for different types of devices could be challenging. Network carriers could block files for specific types of content.
Conclusion
AWS Pinpoint offers reliable, scalable services for sending multimedia messages. We can send various media types as long as we adhere to the file size limitation. Using Pinpoint, organizations can include multi-media messaging options as part of their overall communication strategy.
Opinions expressed by DZone contributors are their own.
Comments