TL;Wan博士无需在每次设置消息属性的情况下动态指定事务性/促销性消息类型(作为param)。
因此,我想使用amazon向客户发送OTP,这是以下代码:
import boto3
client = boto3.client('sns')
response = client.publish(
PhoneNumber='some_phone_number',
Message='some_message'
)根据他们的文档,有两种消息类型:
我可以选择使用set_sms_attributes()设置默认消息属性,如下所示:
client.set_sms_attributes(
attributes={"DefaultSMSType": "Transactional" | "Promotional" }
)我不想继续改变这个参数,因为它们是默认的。我不希望在publish()中动态指定消息类型为参数
我签出了MessageAttributes,但是根据他们的文档,它不是指定消息类型,而是包含元数据,以便客户端在处理消息之前处理它。
是否有一种方法可以动态切换消息类型,而不必使用set_sms_attributes将其设置在默认设置中?
发布于 2018-12-31 06:36:08
您可以使用'AWS.SNS.SMS.SMSType'在publish()中设置它。这个属性被描述为这里,例如:
client = boto3.client('sns')
response = client.publish(
PhoneNumber='some_phone_number',
Message='some_message',
MessageAttributes = {
'AWS.SNS.SMS.SMSType': {
'DataType': 'String',
'StringValue': 'Promotional' # or 'Transactional'
}
}
)注:对于某些地区,这两种类型之间没有成本差异。
发布于 2020-07-16 04:09:39
您可以将属性作为Map传递
Map<String, MessageAttributeValue> smsAttributes = new HashMap<String,
MessageAttributeValue>();
smsAttributes.put("AWS.SNS.SMS.SMSType",new
MessageAttributeValue().withStringValue("Transactional").withDataType("String"));https://stackoverflow.com/questions/53984135
复制相似问题