sendTextMessage method
- required String destinationPhoneNumber,
- String? configurationSetName,
- Map<
String, String> ? context, - Map<
DestinationCountryParameterKey, String> ? destinationCountryParameters, - bool? dryRun,
- String? keyword,
- String? maxPrice,
- String? messageBody,
- bool? messageFeedbackEnabled,
- MessageType? messageType,
- String? originationIdentity,
- String? protectConfigurationId,
- int? timeToLive,
Creates a new text message and sends it to a recipient's phone number. SendTextMessage only sends an SMS message to one recipient each time it is invoked.
SMS throughput limits are measured in Message Parts per Second (MPS). Your MPS limit depends on the destination country of your messages, as well as the type of phone number (origination number) that you use to send the message. For more information about MPS, see Message Parts per Second (MPS) limits in the End User Messaging SMS User Guide.
May throw AccessDeniedException.
May throw ConflictException.
May throw InternalServerException.
May throw ResourceNotFoundException.
May throw ServiceQuotaExceededException.
May throw ThrottlingException.
May throw ValidationException.
Parameter destinationPhoneNumber :
The destination phone number in E.164 format.
Parameter configurationSetName :
The name of the configuration set to use. This can be either the
ConfigurationSetName or ConfigurationSetArn.
Parameter context :
You can specify custom data in this field. If you do, that data is logged
to the event destination.
Parameter destinationCountryParameters :
This field is used for any country-specific registration requirements.
Currently, this setting is only used when you send messages to recipients
in India using a sender ID. For more information see Special
requirements for sending SMS messages to recipients in India.
-
IN_ENTITY_IDThe entity ID or Principal Entity (PE) ID that you received after completing the sender ID registration process. -
IN_TEMPLATE_IDThe template ID that you received after completing the sender ID registration process.
Parameter dryRun :
When set to true, the message is checked and validated, but isn't sent to
the end recipient. You are not charged for using DryRun.
The Message Parts per Second (MPS) limit when using DryRun is
five. If your origination identity has a lower MPS limit then the lower
MPS limit is used. For more information about MPS limits, see Message
Parts per Second (MPS) limits in the End User Messaging SMS User
Guide..
Parameter keyword :
When you register a short code in the US, you must specify a program name.
If you don’t have a US short code, omit this attribute.
Parameter maxPrice :
The maximum amount that you want to spend, in US dollars, per each text
message. If the calculated amount to send the text message is greater than
MaxPrice, the message is not sent and an error is returned.
Parameter messageBody :
The body of the text message.
Parameter messageFeedbackEnabled :
Set to true to enable message feedback for the message. When a user
receives the message you need to update the message status using
PutMessageFeedback.
Parameter messageType :
The type of message. Valid values are for messages that are critical or
time-sensitive and PROMOTIONAL for messages that aren't critical or
time-sensitive.
Parameter originationIdentity :
The origination identity of the message. This can be either the
PhoneNumber, PhoneNumberId, PhoneNumberArn, SenderId, SenderIdArn, PoolId,
or PoolArn.
Parameter protectConfigurationId :
The unique identifier for the protect configuration.
Parameter timeToLive :
How long the text message is valid for, in seconds. By default this is 72
hours. If the messages isn't handed off before the TTL expires we stop
attempting to hand off the message and return TTL_EXPIRED
event.
Implementation
Future<SendTextMessageResult> sendTextMessage({
required String destinationPhoneNumber,
String? configurationSetName,
Map<String, String>? context,
Map<DestinationCountryParameterKey, String>? destinationCountryParameters,
bool? dryRun,
String? keyword,
String? maxPrice,
String? messageBody,
bool? messageFeedbackEnabled,
MessageType? messageType,
String? originationIdentity,
String? protectConfigurationId,
int? timeToLive,
}) async {
_s.validateNumRange(
'timeToLive',
timeToLive,
5,
259200,
);
final headers = <String, String>{
'Content-Type': 'application/x-amz-json-1.0',
'X-Amz-Target': 'PinpointSMSVoiceV2.SendTextMessage'
};
final jsonResponse = await _protocol.send(
method: 'POST',
requestUri: '/',
exceptionFnMap: _exceptionFns,
// TODO queryParams
headers: headers,
payload: {
'DestinationPhoneNumber': destinationPhoneNumber,
if (configurationSetName != null)
'ConfigurationSetName': configurationSetName,
if (context != null) 'Context': context,
if (destinationCountryParameters != null)
'DestinationCountryParameters':
destinationCountryParameters.map((k, e) => MapEntry(k.value, e)),
if (dryRun != null) 'DryRun': dryRun,
if (keyword != null) 'Keyword': keyword,
if (maxPrice != null) 'MaxPrice': maxPrice,
if (messageBody != null) 'MessageBody': messageBody,
if (messageFeedbackEnabled != null)
'MessageFeedbackEnabled': messageFeedbackEnabled,
if (messageType != null) 'MessageType': messageType.value,
if (originationIdentity != null)
'OriginationIdentity': originationIdentity,
if (protectConfigurationId != null)
'ProtectConfigurationId': protectConfigurationId,
if (timeToLive != null) 'TimeToLive': timeToLive,
},
);
return SendTextMessageResult.fromJson(jsonResponse.body);
}