

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 使用 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"
        }
      ]
    }
  ]
}'
```