

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

# 使用 CreateWhatsAppMessageTemplate API 建立訊息範本
<a name="create-message-templates-api"></a>

您可以使用 API 建立自訂的 WhatsApp 訊息範本。本主題說明如何使用 [CreateWhatsAppMessageTemplate](https://docs.aws.amazon.com/social-messaging/latest/APIReference/API_CreateWhatsAppMessageTemplate.html) 來建立各種訊息範本。

## 訊息範本元件
<a name="message-template-components"></a>

 訊息範本可以包含下列元件：
+ **標題**：標題文字顯示在頂端
+ **內文**：具有可變預留位置的主要訊息內容
+ **頁尾**：底部的其他資訊
+ **按鈕**：連結至 URLs可點選元素

在下列範例中，將 {{ENDPOINT}} 和 {{WABA\_ID}} 取代為您實際的端點 URL 和 ID。

## 建立基本英文公用程式範本
<a name="simple-body-only-utility-template"></a>

此範例會建立僅使用 `BODY`元件的英文公用程式訊息範本，且不包含 `HEADER`、 `FOOTER`或 `BUTTON`元件。內文文字使用變數預留位置。

```
$ aws socialmessaging create-whatsapp-message-template --region {{us-east-1}} --endpoint-url {{ENDPOINT_URL}} \ 
--id {{WABA_ID}} \ 
--template-definition '{
    "name": "order_update_basic",
    "language": "en_US",
    "allow_category_change": true,
    "category": "UTILITY",
    "components": [
        {
            "type": "BODY",
            "text": "Hi {{1}}, your order #{{2}} has been shipped. Track your delivery below."
        }
    ]
}'
```

## 使用 按鈕建立基本英文公用程式範本
<a name="utility-template-with-button-example"></a>

此範例會建立包含 `BODY`和 `BUTTON`元件的英文公用程式訊息範本。

```
$ aws socialmessaging create-whatsapp-message-template --region {{us-east-1}} --endpoint-url {{ENDPOINT_URL}} \
--id {{WABA_ID}} \
--template-definition '{
    "name": "order_update_with_button",
    "language": "en_US",
    "allow_category_change": true,
    "category": "UTILITY",
    "components": [
        {
            "type": "BODY",
            "text": "Hi {{1}}, your order #{{2}} has been shipped. Track your delivery below."
        },
        {
            "type": "BUTTONS",
            "buttons": [
                {
                    "type": "URL",
                    "text": "Track Order",
                    "url": "https://example.com/track"
                }
            ]
        }
    ]
}'
```

## 使用標頭、內文和按鈕建立複雜的英文公用程式訊息範本
<a name="utility-template-button-header"></a>

此範例會建立包含 `HEADER``BODY`、 和 `BUTTON`元件的英文公用程式訊息範本。

```
$ aws socialmessaging create-whatsapp-message-template --region {{us-east-1}} --endpoint-url {{ENDPOINT_URL}} \
--id {{WABA_ID}} \
--template-definition '{
  "name": "account_creation_confirmation_3333",
  "category": "UTILITY",
  "language": "en_US",
  "status": "APPROVED",
  "components": [
    {
      "type": "HEADER",
      "format": "TEXT",
      "text": "Finalize account set-up"
    },
    {
      "type": "BODY",
      "text": "Hi {{1}},\n\nYour new account has been created successfully. \n\nPlease verify {{2}} to complete your profile.",
      "example": {
        "body_text": [
          [
            "John",
            "your email address"
          ]
        ]
      }
    },
    {
      "type": "BUTTONS",
      "buttons": [
        {
          "type": "URL",
          "text": "Verify account",
          "url": "https://www.example.com/"
        }
      ]
    }
  ]
}'
```

## 建立基本行銷訊息範本
<a name="simple-marketing-template"></a>

此範例會建立僅包含`BODY`元件的基本行銷訊息範本。

```
$ aws socialmessaging create-whatsapp-message-template --region us-east-1 --endpoint-url {{ENDPOINT_URL}} \
--id {{WABA_ID}} \ 
--template-definition '{
  "id": "1290345849293233",
  "name": "holiday_special_1395238",
  "category": "MARKETING",
  "language": "en_US",
  "status": "PENDING",
  "components": [
    {
      "type": "BODY",
      "text": "Season's Greetings {{1}}!\n\nCelebrate {{2}} with amazing deals up to {{3}} off.\n\nPlus, get free gift wrapping on all orders above $50.",
      "example": {
        "body_text": [
          [
            "Pawan",
            "Christmas",
            "30%"
          ]
        ]
      }
    }
  ],
  "metaTemplateId": "1290345849293233"
}'
```

## 建立複雜的行銷訊息範本
<a name="full-marketing-template"></a>

此範例會建立包含 `HEADER``BODY`、 和 `BUTTON`元件的英文行銷訊息範本。

```
$ aws socialmessaging create-whatsapp-message-template --region us-east-1 \
--endpoint-url {{ENDPOINT_URL}} \ 
--id {{WABA_ID}} \
--template-definition '{
  "name": "summer_sale_1",
  "category": "MARKETING",
  "language": "en_US",
  "status": "APPROVED",
  "components": [
    {
      "type": "HEADER",
      "format": "TEXT",
      "text": "Summer Sale!"
    },
    {
      "type": "BODY",
      "text": "Hi {{1}}! Get {{2}} off all summer items. Shop now before stock runs out!"
    },
    {
      "type": "FOOTER",
      "text": "Valid until August 31st"
    },
    {
      "type": "BUTTONS",
      "buttons": [
        {
          "type": "URL",
          "text": "Shop Now",
          "url": "https://example.com/sale"
        }
      ]
    }
  ]
}'
```