下面是使用AWS Pinpoint SMS消息属性/元数据的代码示例:
import boto3
# 创建Pinpoint客户端
client = boto3.client('pinpoint', region_name='us-west-2')
# 定义消息属性/元数据
message_attributes = {
'CustomerID': {
'DataType': 'String',
'StringValue': '12345'
},
'OrderID': {
'DataType': 'String',
'StringValue': '67890'
}
}
# 发送短信消息
response = client.send_messages(
ApplicationId='YOUR_PINPOINT_APP_ID',
MessageRequest={
'Addresses': {
'PhoneNumber': {
'ChannelType': 'SMS',
'PhoneNumber': '+1234567890'
}
},
'MessageConfiguration': {
'SMSMessage': {
'Body': 'Hello, World!',
'MessageType': 'TRANSACTIONAL',
'OriginationNumber': '+0987654321',
'MessageType': 'TRANSACTIONAL',
'MessageAttributes': message_attributes
}
}
}
)
print(response)
using Amazon.Pinpoint;
using Amazon.Pinpoint.Model;
// 创建Pinpoint客户端
var client = new AmazonPinpointClient();
// 定义消息属性/元数据
var messageAttributes = new Dictionary
{
{ "CustomerID", "12345" },
{ "OrderID", "67890" }
};
// 发送短信消息
var request = new SendMessagesRequest
{
ApplicationId = "YOUR_PINPOINT_APP_ID",
MessageRequest = new MessageRequest
{
Addresses = new Dictionary
{
{ "PhoneNumber", new AddressConfiguration { ChannelType = "SMS", PhoneNumber = "+1234567890" } }
},
MessageConfiguration = new DirectMessageConfiguration
{
SMSMessage = new SMSMessage
{
Body = "Hello, World!",
MessageType = "TRANSACTIONAL",
OriginationNumber = "+0987654321",
MessageAttributes = messageAttributes
}
}
}
};
var response = await client.SendMessagesAsync(request);
Console.WriteLine(response);
请确保替换代码示例中的YOUR_PINPOINT_APP_ID
、PhoneNumber
、OriginationNumber
等参数值为实际的值。