private MessageRequest createMessageRequestFCM(PushMessageRequest pushMessageRequest) {
AddressConfiguration addressConfiguration = new AddressConfiguration().withChannelType(ChannelType.GCM);
BasicAWSCredentials awsCredentials = new BasicAWSCredentials(awsAccessKeyId, awsSecretAccessKey);
AmazonSimpleEmailService client = AmazonSimpleEmailServiceClientBuilder.standard()
.withCredentials(new AWSStaticCredentialsProvider(awsCredentials))
.withRegion(region).build();
GetTemplateRequest templateRequest = new GetTemplateRequest().withTemplateName("Testas");
GetTemplateResult template = client.getTemplate(templateRequest);
return new MessageRequest()
.withTraceId(UUID.randomUUID().toString())
.withAddresses(getAddresses(pushMessageRequest.getDeviceTokens(), addressConfiguration))
.withContext(getData(pushMessageRequest))
.withMessageConfiguration(
new DirectMessageConfiguration()
.withGCMMessage(
new GCMMessage()
.withTitle(template.getTemplate().getSubjectPart())
.withBody(template.getTemplate().getTextPart())
.withTimeToLive(Math.toIntExact(pushMessageRequest.getTimeToLiveSeconds()))
)
);
}
我正在Amazon Pinpoint控制台上创建消息模板。通过消息模板名称,我正在获取模板,但在发送GCM通知时不知道此模板的用法。我的问题是可以在邮件reuqest上设置邮件模板吗?
更新: 无法将模板直接用于MessageRequest对象。一种情况是手动使用(上面代码中的示例)。首先需要获取模板,然后您才能获取模板数据(主题,正文),该数据可用于形成通知请求。模板用于电子邮件发送。有一个类(SendBulkTemplatedEmailRequest),该类可以使用模板并用于形成电子邮件请求。