Skip to content

send_text_message

send_text_message(
    destination_phone_number: PhoneNumber,
    *,
    config_overrides: Optional[PinpointSMSVoiceV2ClientConfig] = None,
    origination_identity: Optional[TextMessageOriginationIdentity] = None,
    message_body: Optional[TextMessageBody] = None,
    message_type: Optional[MessageType] = None,
    keyword: Optional[Keyword] = None,
    configuration_set_name: Optional[ConfigurationSetNameOrArn] = None,
    max_price: Optional[MaxPrice] = None,
    time_to_live: Optional[TimeToLive] = None,
    context: Optional[ContextMap] = None,
    destination_country_parameters: Optional[DestinationCountryParameters] = None,
    dry_run: Optional[bool] = None,
    protect_configuration_id: Optional[ProtectConfigurationIdOrArn] = None,
    message_feedback_enabled: Optional[bool] = None,
) -> SendTextMessageResult

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.

Parameters:

  • destination_phone_number (PhoneNumber) –

    The destination phone number in E.164 format.

  • origination_identity (Optional[TextMessageOriginationIdentity], default: None ) –

    The origination identity of the message. This can be either the PhoneNumber, PhoneNumberId, PhoneNumberArn, RcsAgentId, RcsAgentArn, SenderId, SenderIdArn, PoolId, or PoolArn.

    If you are using a shared End User Messaging SMS resource then you must use the full Amazon Resource Name(ARN).

  • message_body (Optional[TextMessageBody], default: None ) –

    The body of the text message.

  • message_type (Optional[MessageType], default: None ) –

    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.

  • keyword (Optional[Keyword], default: None ) –

    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.

  • configuration_set_name (Optional[ConfigurationSetNameOrArn], default: None ) –

    The name of the configuration set to use. This can be either the ConfigurationSetName or ConfigurationSetArn.

  • max_price (Optional[MaxPrice], default: None ) –

    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.

  • time_to_live (Optional[TimeToLive], default: None ) –

    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.

  • context (Optional[ContextMap], default: None ) –

    You can specify custom data in this field. If you do, that data is logged to the event destination.

  • destination_country_parameters (Optional[DestinationCountryParameters], default: None ) –

    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_ID The entity ID or Principal Entity (PE) ID that you received after completing the sender ID registration process.

    • IN_TEMPLATE_ID The template ID that you received after completing the sender ID registration process.

      Make sure that the Template ID that you specify matches your message template exactly. If your message doesn't match the template that you provided during the registration process, the mobile carriers might reject your message.

  • dry_run (Optional[bool], default: None ) –

    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..

  • protect_configuration_id (Optional[ProtectConfigurationIdOrArn], default: None ) –

    The unique identifier for the protect configuration.

  • message_feedback_enabled (Optional[bool], default: None ) –

    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.

Raises:

  • AccessDeniedException –

    The request was denied because you don't have sufficient permissions to access the resource.

  • ConflictException –

    Your request has conflicting operations. This can occur if you're trying to perform more than one operation on the same resource at the same time or it could be that the requested action isn't valid for the current state or configuration of the resource.

  • InternalServerException –

    The API encountered an unexpected error and couldn't complete the request. You might be able to successfully issue the request again in the future.

  • ResourceNotFoundException –

    A requested resource couldn't be found.

  • ServiceQuotaExceededException –

    The request would cause a service quota to be exceeded.

  • ThrottlingException –

    An error that occurred because too many requests were sent during a certain amount of time.

  • ValidationException –

    A validation exception for a field.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Source code in docs_src/capo_pinpoint_sms_voice_v2/_services/pinpoint_sms_voice_v2.py
def send_text_message(
    self,
    destination_phone_number: "capo_pinpoint_sms_voice_v2.types.phone_number.PhoneNumber",
    *,
    config_overrides: Optional[PinpointSMSVoiceV2ClientConfig] = None,
    origination_identity: Optional[
        "capo_pinpoint_sms_voice_v2.types.text_message_origination_identity.TextMessageOriginationIdentity"
    ] = None,
    message_body: Optional[
        "capo_pinpoint_sms_voice_v2.types.text_message_body.TextMessageBody"
    ] = None,
    message_type: Optional[
        "capo_pinpoint_sms_voice_v2.types.message_type.MessageType"
    ] = None,
    keyword: Optional["capo_pinpoint_sms_voice_v2.types.keyword.Keyword"] = None,
    configuration_set_name: Optional[
        "capo_pinpoint_sms_voice_v2.types.configuration_set_name_or_arn.ConfigurationSetNameOrArn"
    ] = None,
    max_price: Optional[
        "capo_pinpoint_sms_voice_v2.types.max_price.MaxPrice"
    ] = None,
    time_to_live: Optional[
        "capo_pinpoint_sms_voice_v2.types.time_to_live.TimeToLive"
    ] = None,
    context: Optional[
        "capo_pinpoint_sms_voice_v2.types.context_map.ContextMap"
    ] = None,
    destination_country_parameters: Optional[
        "capo_pinpoint_sms_voice_v2.types.destination_country_parameters.DestinationCountryParameters"
    ] = None,
    dry_run: Optional[bool] = None,
    protect_configuration_id: Optional[
        "capo_pinpoint_sms_voice_v2.types.protect_configuration_id_or_arn.ProtectConfigurationIdOrArn"
    ] = None,
    message_feedback_enabled: Optional[bool] = None,
) -> "capo_pinpoint_sms_voice_v2.types.send_text_message_result.SendTextMessageResult":
    """<p>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.</p> <p>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 <a href="https://docs.aws.amazon.com/sms-voice/latest/userguide/sms-limitations-mps.html">Message Parts per Second (MPS) limits</a> in the <i>End User Messaging SMS User Guide</i>.</p>

    Args:
        destination_phone_number: <p>The destination phone number in E.164 format.</p>
        origination_identity: <p>The origination identity of the message. This can be either the PhoneNumber, PhoneNumberId, PhoneNumberArn, RcsAgentId, RcsAgentArn, SenderId, SenderIdArn, PoolId, or PoolArn.</p> <important> <p>If you are using a shared End User Messaging SMS resource then you must use the full Amazon Resource Name(ARN).</p> </important>
        message_body: <p>The body of the text message.</p>
        message_type: <p>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.</p>
        keyword: <p>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.</p>
        configuration_set_name: <p>The name of the configuration set to use. This can be either the ConfigurationSetName or ConfigurationSetArn.</p>
        max_price: <p>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 <code>MaxPrice</code>, the message is not sent and an error is returned.</p>
        time_to_live: <p>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 <code>TTL_EXPIRED</code> event.</p>
        context: <p>You can specify custom data in this field. If you do, that data is logged to the event destination.</p>
        destination_country_parameters: <p>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 <a href="https://docs.aws.amazon.com/pinpoint/latest/userguide/channels-sms-senderid-india.html">Special requirements for sending SMS messages to recipients in India</a>. </p> <ul> <li> <p> <code>IN_ENTITY_ID</code> The entity ID or Principal Entity (PE) ID that you received after completing the sender ID registration process.</p> </li> <li> <p> <code>IN_TEMPLATE_ID</code> The template ID that you received after completing the sender ID registration process.</p> <important> <p>Make sure that the Template ID that you specify matches your message template exactly. If your message doesn't match the template that you provided during the registration process, the mobile carriers might reject your message.</p> </important> </li> </ul>
        dry_run: <p>When set to true, the message is checked and validated, but isn't sent to the end recipient. You are not charged for using <code>DryRun</code>.</p> <p>The Message Parts per Second (MPS) limit when using <code>DryRun</code> 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 <a href="https://docs.aws.amazon.com/sms-voice/latest/userguide/sms-limitations-mps.html">Message Parts per Second (MPS) limits</a> in the <i>End User Messaging SMS User Guide</i>..</p>
        protect_configuration_id: <p>The unique identifier for the protect configuration.</p>
        message_feedback_enabled: <p>Set to true to enable message feedback for the message. When a user receives the message you need to update the message status using <a>PutMessageFeedback</a>.</p>

    Raises:
        capo_pinpoint_sms_voice_v2.errors.access_denied_exception.AccessDeniedException: <p>The request was denied because you don't have sufficient permissions to access the resource.</p>
        capo_pinpoint_sms_voice_v2.errors.conflict_exception.ConflictException: <p>Your request has conflicting operations. This can occur if you're trying to perform more than one operation on the same resource at the same time or it could be that the requested action isn't valid for the current state or configuration of the resource.</p>
        capo_pinpoint_sms_voice_v2.errors.internal_server_exception.InternalServerException: <p>The API encountered an unexpected error and couldn't complete the request. You might be able to successfully issue the request again in the future.</p>
        capo_pinpoint_sms_voice_v2.errors.resource_not_found_exception.ResourceNotFoundException: <p>A requested resource couldn't be found.</p>
        capo_pinpoint_sms_voice_v2.errors.service_quota_exceeded_exception.ServiceQuotaExceededException: <p>The request would cause a service quota to be exceeded.</p>
        capo_pinpoint_sms_voice_v2.errors.throttling_exception.ThrottlingException: <p>An error that occurred because too many requests were sent during a certain amount of time.</p>
        capo_pinpoint_sms_voice_v2.errors.validation_exception.ValidationException: <p>A validation exception for a field.</p>
        capo_pinpoint_sms_voice_v2.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_pinpoint_sms_voice_v2.types.send_text_message_request.SendTextMessageRequest]",
    ) -> OperationResponse[
        "capo_pinpoint_sms_voice_v2.types.send_text_message_result.SendTextMessageResult"
    ]:
        import capo_pinpoint_sms_voice_v2._operations.pinpoint_sms_voice_v2.send_text_message

        output, http_response = (
            capo_pinpoint_sms_voice_v2._operations.pinpoint_sms_voice_v2.send_text_message.send_text_message(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("SendTextMessage")
    )
    input_: capo_pinpoint_sms_voice_v2.types.send_text_message_request.SendTextMessageRequest = {
        "destination_phone_number": destination_phone_number
    }
    if origination_identity is not None:
        input_["origination_identity"] = origination_identity
    if message_body is not None:
        input_["message_body"] = message_body
    if message_type is not None:
        input_["message_type"] = message_type
    if keyword is not None:
        input_["keyword"] = keyword
    if configuration_set_name is not None:
        input_["configuration_set_name"] = configuration_set_name
    if max_price is not None:
        input_["max_price"] = max_price
    if time_to_live is not None:
        input_["time_to_live"] = time_to_live
    if context is not None:
        input_["context"] = context
    if destination_country_parameters is not None:
        input_["destination_country_parameters"] = destination_country_parameters
    if dry_run is not None:
        input_["dry_run"] = dry_run
    if protect_configuration_id is not None:
        input_["protect_configuration_id"] = protect_configuration_id
    if message_feedback_enabled is not None:
        input_["message_feedback_enabled"] = message_feedback_enabled

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output