TL; DR 无需即时设置交易/促销消息类型(作为参数),而不必每次都设置消息属性。>
所以我想使用Amazon SNS将OTP发送给客户,这是以下代码:
import boto3
client = boto3.client('sns')
response = client.publish(
PhoneNumber='some_phone_number',
Message='some_message'
)
根据他们的documentation,有2种消息类型:
1.事务性(时间紧迫的交付)
2.促销(非关键时间交付且具有成本效益)
我可以选择使用set_sms_attributes()
来设置默认消息属性,如下所示:
client.set_sms_attributes(
attributes={"DefaultSMSType": "Transactional" | "Promotional" }
)
我不想继续更改此参数,因为它们是默认值。我无法在publish()
我签出了MessageAttributes
,但根据他们的docs,不是指定消息类型,而是包含供客户端在处理消息之前处理消息的元数据。
是否可以快速切换消息类型,而不必使用set_sms_attributes
将消息类型设置为默认设置?
答案 0 :(得分:2)
您可以使用Blaze.renderWithData()
中的'AWS.SNS.SMS.SMSType'
进行设置。 here描述了此属性,例如:
publish()
注意:在某些地区,这两种类型之间没有成本差异。
答案 1 :(得分:0)
您可以将属性作为地图传递
Map<String, MessageAttributeValue> smsAttributes = new HashMap<String,
MessageAttributeValue>();
smsAttributes.put("AWS.SNS.SMS.SMSType",new
MessageAttributeValue().withStringValue("Transactional").withDataType("String"));