

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 傳送 RCS 訊息
<a name="rcs-send-message"></a>

AWS 最終使用者傳訊會針對 RCS 和 SMS 交付使用相同的 `SendTextMessage` API。服務路由訊息的方式取決於您在請求中指定的起始身分。您可以透過電話集區 （建議）、帳戶層級或直接透過 AWS RCS 代理程式 ARN 傳送訊息。

本節說明三種傳送模式、如何解譯交付收據，並提供程式碼範例。如需黏性傳送、原始身分優先順序和自動簡訊備用的詳細資訊，請參閱 [使用電話集區的 RCS 到 SMS 備用](rcs-sms-fallback.md)。如需管理 AWS RCS 代理程式的詳細資訊，請參閱 [管理 RCS 代理程式](rcs-agents.md)。

**Topics**
+ [傳送模式](#rcs-send-message-patterns)
+ [黏性傳送、優先順序和 SMS 備用](#rcs-send-message-fallback-summary)
+ [程式碼範例](#rcs-send-message-examples)
+ [傳送 RCS 訊息的 AI 代理器提示](#rcs-send-message-ai-prompt)
+ [交付接收處理](#rcs-send-message-delivery-receipts)

## 傳送模式
<a name="rcs-send-message-patterns"></a>

AWS 最終使用者傳訊支援三種傳送 RCS 訊息的模式。每個模式都會決定服務如何選取起始身分，以及是否提供自動簡訊備用。


**RCS 傳送模式**  

| 模式 | 運作方式 | SMS 備用 | 使用情況 | 
| --- | --- | --- | --- | 
| 以集區為基礎的 （建議） | 指定集區 ID 做為起始身分。服務會從集區中選取最佳身分。 | 是 | 所有使用案例。提供自動頻道選擇和具有合規安全路由的 SMS 備用。 | 
| 帳戶層級 | 省略起始身分。此服務會從您帳戶中的所有可用身分中選取。 | 是 | 單一使用案例的簡單設定。不建議具有多個使用案例的帳戶使用。 | 
| 直接傳送 | 指定 AWS RCS 代理程式 ARN 做為起始身分。訊息只會透過 RCS 傳送。 | 否 | RCS-or-nothing使用案例，或當您在 AWS 最終使用者傳訊外部管理簡訊後援時。 | 

### 以集區為基礎的傳送 （建議）
<a name="rcs-send-message-pool-based"></a>

對於所有 RCS 使用案例，建議採用以集區為基礎的傳送方法。當您在`SendTextMessage`請求中將集區 ID 指定為起始身分時， AWS 最終使用者傳訊會根據目的地、頻道可用性和黏性傳送歷史記錄，從集區中選取最佳起始身分。

如果集區同時包含 AWS RCS 代理程式和簡訊電話號碼，則服務會先嘗試 RCS 交付。如果 RCS 交付失敗，服務會使用相同集區的電話號碼自動回復為 SMS。由於集區中的所有身分都會註冊相同的使用案例，因此後援訊息一律會從適當的號碼傳送。

如需使用 AWS RCS 代理程式建立和設定集區的詳細資訊，請參閱 [使用電話集區的 RCS 到 SMS 備用](rcs-sms-fallback.md)。

### 帳戶層級傳送
<a name="rcs-send-message-account-level"></a>

當您省略`SendTextMessage`請求中的起始身分時， AWS 最終使用者傳訊會從您帳戶中所有可用的身分中選取起始身分。服務會使用起始身分優先順序來決定要使用的身分。如需詳細資訊，請參閱[備用邏輯和優先順序](rcs-sms-fallback.md#rcs-sms-fallback-logic)。

**重要**  
如果您的帳戶包含針對不同使用案例註冊的電話號碼，帳戶層級傳送會產生合規風險。當 RCS 交付失敗且服務落回 SMS 時，可能會選取與您訊息內容不相符的電話號碼。例如，OTP 訊息可能會回到為預約提醒註冊的免付費電話號碼，違反該號碼的註冊條款。為了避免此風險，請針對每個使用案例使用以集區為基礎的傳送與一個集區。如需詳細資訊，請參閱[帳戶層級傳送的合規風險](rcs-sms-fallback.md#rcs-sms-fallback-compliance-risk)。

### 直接傳送 （僅限RCS)
<a name="rcs-send-message-direct"></a>

當您在`SendTextMessage`請求中將 AWS RCS 代理程式 ARN 指定為起始身分時， AWS 最終使用者傳訊只會透過 RCS 傳送訊息。沒有自動簡訊備用。如果 RCS 交付失敗，訊息不會在其他頻道上重試。

在下列情況下使用直接傳送：
+ 您想要 RCS-or-nothing交付。訊息應僅透過 RCS 傳遞，而且您偏好不要交付簡訊。
+ 您可以在 AWS 最終使用者傳訊之外管理 SMS 退信。您的應用程式會獨立處理備用邏輯，例如偵測 RCS 交付失敗，並透過不同的系統或供應商傳送個別簡訊。

**注意**  
直接傳送會略過所有 SMS 備用邏輯。如果收件人的裝置或電信業者不支援 RCS，則不會傳遞訊息。對於大多數使用案例，建議使用以集區為基礎的傳送，因為它提供自動簡訊備用功能，無需額外費用。

## 黏性傳送、優先順序和 SMS 備用
<a name="rcs-send-message-fallback-summary"></a>

當您透過集區或帳戶層級傳送訊息時， AWS 最終使用者傳訊會使用黏性傳送 (25 小時路由最佳化）、起始身分優先順序，以及自動簡訊備用，為每個訊息選取最佳管道和身分。如需這些機制運作方式的完整詳細資訊，包括自動後援、後援期間的交付收據，以及帳單影響，請參閱 [使用電話集區的 RCS 到 SMS 備用](rcs-sms-fallback.md)。

## 程式碼範例
<a name="rcs-send-message-examples"></a>

下列 Python 範例示範如何使用三種傳送模式的每一個來傳送 RCS 訊息。所有範例都使用 boto3 `pinpoint-sms-voice-v2`用戶端和 `SendTextMessage` API。

### 以集區為基礎的傳送範例
<a name="rcs-send-message-example-pool"></a>

下列範例會透過電話集區傳送訊息。服務會從集區中選取最佳起始身分，如果無法進行 RCS 交付，則會自動回復為 SMS。

```
import boto3

client = boto3.client('pinpoint-sms-voice-v2')

response = client.send_text_message(
    DestinationPhoneNumber='+12065550100',
    OriginationIdentity='pool-a1b2c3d4e5f6g7h8i',
    MessageBody='Your appointment is confirmed for tomorrow at 2:00 PM.',
    MessageType='TRANSACTIONAL'
)

print(f"Message ID: {response['MessageId']}")
```

### 帳戶層級傳送範例
<a name="rcs-send-message-example-account"></a>

下列範例會省略起始身分，在帳戶層級傳送訊息。此服務會使用優先順序從您帳戶中的所有可用身分中選取身分。

```
import boto3

client = boto3.client('pinpoint-sms-voice-v2')

response = client.send_text_message(
    DestinationPhoneNumber='+12065550100',
    MessageBody='Your verification code is 123456.',
    MessageType='TRANSACTIONAL'
)

print(f"Message ID: {response['MessageId']}")
```

**重要**  
如果您的帳戶包含針對不同使用案例註冊的電話號碼，帳戶層級傳送可能會透過不符合訊息內容的號碼來路由 SMS 退信。每個使用案例使用以集區為基礎的傳送搭配一個集區，以避免合規風險。

### 直接傳送範例
<a name="rcs-send-message-example-direct"></a>

下列範例會直接透過 AWS RCS 代理程式 ARN 傳送訊息。訊息僅透過 RCS 傳送，沒有 SMS 退信。

```
import boto3

client = boto3.client('pinpoint-sms-voice-v2')

response = client.send_text_message(
    DestinationPhoneNumber='+12065550100',
    OriginationIdentity='arn:aws:sms-voice:us-east-1:123456789012:rcs-agent/rcs-a1b2c3d4',
    MessageBody='Welcome to our RCS channel! Reply HELP for assistance.'
)

print(f"Message ID: {response['MessageId']}")
```

**注意**  
如果收件人的裝置或電信業者不支援 RCS，則不會傳遞訊息。不會嘗試 SMS 退信。只有在您希望 RCS-or-nothing交付，或在 AWS 最終使用者傳訊外部管理簡訊後援時，才使用此模式。

## 傳送 RCS 訊息的 AI 代理器提示
<a name="rcs-send-message-ai-prompt"></a>

如果您使用生成式 AI 編碼助理或 AI 代理器，您可以使用下列提示來取得使用 CLI 或 SDK AWS 傳送 RCS 訊息的協助。

**注意**  
複製下列提示並將其貼到您的 AI 代理器或編碼助理：  

```
## RCS Messaging Assistant Prompt

Help me send RCS messages using AWS End User Messaging SMS with the
`pinpoint-sms-voice-v2` service. Show me exact CLI commands and Python/boto3
examples. Ask me for my details before generating any commands.

**Important rules for generating commands:**
- The API is `send-text-message` — the same command used for SMS. There is
  NO separate RCS send API.
- There is NO `describe-messages` API. Do not generate it.
- The boto3 method is `send_text_message` on the
  `pinpoint-sms-voice-v2` client.
- Use the term "testing" — NOT "sandbox".

**Prerequisites:** I have an existing RCS agent (created via the setup process)
and a verified test device.

### Pattern 1: Direct RCS sending (simplest, good for testing)

Send directly through my RCS Agent ARN. RCS-only delivery, no SMS fallback.
If the recipient's device doesn't support RCS, the message is not delivered.

CLI: `send-text-message --destination-phone-number <E.164>
--origination-identity <agent-arn> --message-body "<text>"
--message-type <TRANSACTIONAL|PROMOTIONAL>`

Returns `MessageId`.

### Pattern 2: Pool-based sending (recommended for production)

Send through a phone pool containing my RCS agent (and optionally SMS phone
numbers for fallback). The service tries RCS first, then falls back to SMS
asynchronously if no RCS signal within 25 seconds. This is NOT synchronous
fallback — the SMS is sent as a separate attempt after the timeout.

To set up a pool:
- `create-pool --origination-identity <rcs-agent-id> --message-type TRANSACTIONAL` → returns `PoolId`
- Optionally add SMS numbers: `associate-origination-identity --pool-id <id>
  --origination-identity <phone-number-id>`

CLI: `send-text-message --destination-phone-number <E.164>
--origination-identity <pool-id> --message-body "<text>"
--message-type <TRANSACTIONAL|PROMOTIONAL>`

### Pattern 3: Account-level sending

Send without specifying `--origination-identity`. The service auto-selects
the best identity from the account.

CLI: `send-text-message --destination-phone-number <E.164>
--message-body "<text>" --message-type <TRANSACTIONAL|PROMOTIONAL>`

**Compliance warning:** If the account has multiple RCS agents, SMS numbers,
or different use cases, the service picks an identity automatically — which
may not be the intended one. Use pool-based or direct sending for explicit
control over which identity is used.

### Delivery verification

- For testing: check the test device directly — the message appears from
  the branded RCS agent.
- For production: configure event destinations BEFORE sending using
  `create-event-destination` (SNS, CloudWatch Logs, or Firehose). Event
  destinations do not retroactively capture events for already-sent messages.
- CloudWatch metrics in `AWS/SMSVoice` namespace provide aggregate delivery
  statistics.

### Behavioral notes

- Sticky sending: the service remembers the last successful identity per
  destination number for 25 hours.
- Pool-based sending is recommended for production because it provides
  automatic SMS fallback.
- All three patterns use the same `send-text-message` API — the only
  difference is what you pass (or don't pass) as `--origination-identity`.

---

**Before generating commands, ask me for:**
- Which sending pattern I want to use (direct, pool-based, or account-level)
- My RCS Agent ARN
- My pool ID (if using pool-based sending)
- Destination phone number in E.164 format
- Message type (TRANSACTIONAL or PROMOTIONAL)
- Message text
```

## 交付接收處理
<a name="rcs-send-message-delivery-receipts"></a>

AWS 最終使用者傳訊透過 Amazon EventBridge 和組態集事件目的地提供 RCS 訊息的交付回條。交付回條指出訊息的最終狀態，以及用於交付的管道。若要了解如何設定事件目的地以擷取交付回條和其他訊息事件，請參閱 [AWS 最終使用者傳訊簡訊中的事件目的地](configuration-sets-event-destinations.md)。

### 交付狀態值
<a name="rcs-send-message-delivery-status"></a>

下列交付狀態值適用於 RCS 訊息：

已交付  
訊息已成功交付至收件人的裝置。

待定  
RCS 基礎設施已接受訊息，但尚未收到交付確認。訊息仍可能交付。

已過期  
訊息未在允許的時段內傳遞。對於具有 SMS 後援的 RCS 訊息，此狀態適用於發生後援之前的 RCS 嘗試。

無法交付  
訊息無法傳遞。當收件人的裝置永久無法連線或電話號碼無效時，就會發生這種情況。

REJECTED  
RCS 基礎設施或電信業者已拒絕該訊息。這可能是因為內容政策違規或電信業者層級篩選而發生。

### 頻道屬性
<a name="rcs-send-message-channel-attribution"></a>

交付回條包含通道屬性，指出訊息是透過 RCS 或 SMS 交付。這對於了解您的交付組合和用於計費非常重要。
+ 透過 RCS 交付訊息時，交付接收會指出 RCS 為交付管道，並包含 AWS RCS 代理程式身分。
+ 當訊息落回 SMS 時，交付接收會指出 SMS 做為交付管道，並包含用於交付的 SMS 電話號碼身分。
+ 當直接傳送 (AWS RCS 代理程式 ARN) 失敗時，交付接收會指出 RCS 為失敗狀態的嘗試頻道。不會產生簡訊後援接收。

如需 RCS CloudWatch 指標和監控交付模式的詳細資訊，請參閱 [RCS CloudWatch 指標和監控](rcs-monitoring.md)。如需交付管道如何影響帳單的資訊，請參閱 [RCS 計費和定價模型](rcs-billing.md)。