Template Examples#

Tip

This page contains examples of template messages.

You can find the code in the tests/data/templates directory of the repository.

Example of a template with buttons#

Python Code#
  1from pywa.types.templates import *  # noqa: F403
  2
  3seasonal_promotion = Template(
  4    name="seasonal_promotion",
  5    language=TemplateLanguage.ENGLISH_US,
  6    category=TemplateCategory.MARKETING,
  7    components=[
  8        HeaderText(
  9            "Our {{1}} is on!",
 10            "Summer Sale",
 11        ),
 12        BodyText(
 13            "Shop now through {{1}} and use code {{2}} to get {{3}} off of all merchandise.",
 14            "the end of August",
 15            "25OFF",
 16            "25%",
 17        ),
 18        FooterText(text="Use the buttons below to manage your MARKETING subscriptions"),
 19        Buttons(
 20            buttons=[
 21                QuickReplyButton(text="Unsubscribe from Promos"),
 22                QuickReplyButton(text="Unsubscribe from All"),
 23            ]
 24        ),
 25    ],
 26)
 27
 28order_confirmation = Template(
 29    name="order_confirmation",
 30    language=TemplateLanguage.ENGLISH_US,
 31    category=TemplateCategory.UTILITY,
 32    components=[
 33        HeaderDocument(
 34            example="4::YX...",
 35        ),
 36        BodyText(
 37            "Thank you for your order, {{1}}! Your order number is {{2}}. Tap the PDF linked above to view your receipt. If you have any questions, please use the buttons below to contact support. Thank you for being a customer!",
 38            "Pablo",
 39            "860198-230332",
 40        ),
 41        Buttons(
 42            buttons=[
 43                PhoneNumberButton(text="Call", phone_number="15550051310"),
 44                URLButton(
 45                    text="Contact Support", url="https://www.luckyshrub.com/support"
 46                ),
 47            ]
 48        ),
 49    ],
 50)
 51
 52order_delivery_update = Template(
 53    name="order_delivery_update",
 54    language=TemplateLanguage.ENGLISH_US,
 55    category=TemplateCategory.UTILITY,
 56    components=[
 57        HeaderLocation(),
 58        BodyText(
 59            "Good news {{1}}! Your order #{{2}} is on its way to the location above. Thank you for your order!",
 60            "Mark",
 61            "566701",
 62        ),
 63        FooterText(text="To stop receiving delivery updates, tap the button below."),
 64        Buttons(
 65            buttons=[
 66                QuickReplyButton(text="Stop Delivery Updates"),
 67            ]
 68        ),
 69    ],
 70)
 71
 72abandoned_cart_offer = Template(
 73    name="abandoned_cart_offer",
 74    language=TemplateLanguage.ENGLISH_US,
 75    category=TemplateCategory.MARKETING,
 76    components=[
 77        HeaderProduct(),
 78        BodyText(
 79            "Use code {{1}} to get {{2}} off our newest succulent!", "25OFF", "25%"
 80        ),
 81        FooterText(text="Offer ends September 30, 2024"),
 82        Buttons(
 83            buttons=[
 84                SPMButton(text="View"),
 85            ]
 86        ),
 87    ],
 88)
 89
 90intro_catalog_offer = Template(
 91    name="intro_catalog_offer",
 92    language=TemplateLanguage.ENGLISH_US,
 93    category=TemplateCategory.MARKETING,
 94    components=[
 95        BodyText(
 96            "Now shop for your favourite products right here on WhatsApp! Get Rs {{1}} off on all orders above {{2}}Rs! Valid for your first {{3}} orders placed on WhatsApp!",
 97            "100",
 98            "400",
 99            "3",
100        ),
101        FooterText(text="Best grocery deals on WhatsApp!"),
102        Buttons(
103            buttons=[
104                CatalogButton(text="View catalog"),
105            ]
106        ),
107    ],
108)
109
110coupon_code_fall2023_25off = Template(
111    name="coupon_code_fall2023_25off",
112    language=TemplateLanguage.ENGLISH_US,
113    category=TemplateCategory.MARKETING,
114    components=[
115        HeaderText(text="Our Fall Sale is on!"),
116        BodyText(
117            "Shop now through November and use code {{1}} to get {{2}} off of all merchandise!",
118            "25OFF",
119            "25%",
120        ),
121        Buttons(
122            buttons=[
123                QuickReplyButton(text="Unsubscribe"),
124                CopyCodeButton(example="250FF"),
125            ]
126        ),
127    ],
128)
129
130abandoned_cart = Template(
131    name="abandoned_cart",
132    language=TemplateLanguage.ENGLISH_US,
133    category=TemplateCategory.MARKETING,
134    components=[
135        HeaderText(
136            "Forget something, {{1}}?",
137            "Pablo",
138        ),
139        BodyText(
140            "Looks like you left these items in your cart, still interested? Use code {{1}} to get 10% off!",
141            "10OFF",
142        ),
143        Buttons(buttons=[MPMButton(text="View items")]),
144    ],
145)
JSON Code#
  1{
  2  "seasonal_promotion": {
  3    "name": "seasonal_promotion",
  4    "language": "en_US",
  5    "category": "MARKETING",
  6    "components": [
  7      {
  8        "type": "HEADER",
  9        "format": "TEXT",
 10        "text": "Our {{1}} is on!",
 11        "example": {
 12          "header_text": [
 13            "Summer Sale"
 14          ]
 15        }
 16      },
 17      {
 18        "type": "BODY",
 19        "text": "Shop now through {{1}} and use code {{2}} to get {{3}} off of all merchandise.",
 20        "example": {
 21          "body_text": [
 22            [
 23              "the end of August",
 24              "25OFF",
 25              "25%"
 26            ]
 27          ]
 28        }
 29      },
 30      {
 31        "type": "FOOTER",
 32        "text": "Use the buttons below to manage your MARKETING subscriptions"
 33      },
 34      {
 35        "type": "BUTTONS",
 36        "buttons": [
 37          {
 38            "type": "QUICK_REPLY",
 39            "text": "Unsubscribe from Promos"
 40          },
 41          {
 42            "type": "QUICK_REPLY",
 43            "text": "Unsubscribe from All"
 44          }
 45        ]
 46      }
 47    ]
 48  },
 49  "order_confirmation": {
 50    "name": "order_confirmation",
 51    "language": "en_US",
 52    "category": "UTILITY",
 53    "components": [
 54      {
 55        "type": "HEADER",
 56        "format": "DOCUMENT",
 57        "example": {
 58          "header_handle": [
 59            "4::YX..."
 60          ]
 61        }
 62      },
 63      {
 64        "type": "BODY",
 65        "text": "Thank you for your order, {{1}}! Your order number is {{2}}. Tap the PDF linked above to view your receipt. If you have any questions, please use the buttons below to contact support. Thank you for being a customer!",
 66        "example": {
 67          "body_text": [
 68            [
 69              "Pablo",
 70              "860198-230332"
 71            ]
 72          ]
 73        }
 74      },
 75      {
 76        "type": "BUTTONS",
 77        "buttons": [
 78          {
 79            "type": "PHONE_NUMBER",
 80            "text": "Call",
 81            "phone_number": "15550051310"
 82          },
 83          {
 84            "type": "URL",
 85            "text": "Contact Support",
 86            "url": "https://www.luckyshrub.com/support"
 87          }
 88        ]
 89      }
 90    ]
 91  },
 92  "order_delivery_update": {
 93    "name": "order_delivery_update",
 94    "language": "en_US",
 95    "category": "UTILITY",
 96    "components": [
 97      {
 98        "type": "HEADER",
 99        "format": "LOCATION"
100      },
101      {
102        "type": "BODY",
103        "text": "Good news {{1}}! Your order #{{2}} is on its way to the location above. Thank you for your order!",
104        "example": {
105          "body_text": [
106            [
107              "Mark",
108              "566701"
109            ]
110          ]
111        }
112      },
113      {
114        "type": "FOOTER",
115        "text": "To stop receiving delivery updates, tap the button below."
116      },
117      {
118        "type": "BUTTONS",
119        "buttons": [
120          {
121            "type": "QUICK_REPLY",
122            "text": "Stop Delivery Updates"
123          }
124        ]
125      }
126    ]
127  },
128  "abandoned_cart_offer": {
129    "name": "abandoned_cart_offer",
130    "language": "en_US",
131    "category": "MARKETING",
132    "components": [
133      {
134        "type": "HEADER",
135        "format": "PRODUCT"
136      },
137      {
138        "type": "BODY",
139        "text": "Use code {{1}} to get {{2}} off our newest succulent!",
140        "example": {
141          "body_text": [
142            [
143              "25OFF",
144              "25%"
145            ]
146          ]
147        }
148      },
149      {
150        "type": "FOOTER",
151        "text": "Offer ends September 30, 2024"
152      },
153      {
154        "type": "BUTTONS",
155        "buttons": [
156          {
157            "type": "SPM",
158            "text": "View"
159          }
160        ]
161      }
162    ]
163  },
164  "intro_catalog_offer": {
165    "name": "intro_catalog_offer",
166    "language": "en_US",
167    "category": "MARKETING",
168    "components": [
169      {
170        "type": "BODY",
171        "text": "Now shop for your favourite products right here on WhatsApp! Get Rs {{1}} off on all orders above {{2}}Rs! Valid for your first {{3}} orders placed on WhatsApp!",
172        "example": {
173          "body_text": [
174            [
175              "100",
176              "400",
177              "3"
178            ]
179          ]
180        }
181      },
182      {
183        "type": "FOOTER",
184        "text": "Best grocery deals on WhatsApp!"
185      },
186      {
187        "type": "BUTTONS",
188        "buttons": [
189          {
190            "type": "CATALOG",
191            "text": "View catalog"
192          }
193        ]
194      }
195    ]
196  },
197  "coupon_code_fall2023_25off": {
198    "name": "coupon_code_fall2023_25off",
199    "language": "en_US",
200    "category": "MARKETING",
201    "components": [
202      {
203        "type": "HEADER",
204        "format": "TEXT",
205        "text": "Our Fall Sale is on!"
206      },
207      {
208        "type": "BODY",
209        "text": "Shop now through November and use code {{1}} to get {{2}} off of all merchandise!",
210        "example": {
211          "body_text": [
212            [
213              "25OFF",
214              "25%"
215            ]
216          ]
217        }
218      },
219      {
220        "type": "BUTTONS",
221        "buttons": [
222          {
223            "type": "QUICK_REPLY",
224            "text": "Unsubscribe"
225          },
226          {
227            "type": "COPY_CODE",
228            "example": "250FF"
229          }
230        ]
231      }
232    ]
233  },
234  "abandoned_cart": {
235    "name": "abandoned_cart",
236    "language": "en_US",
237    "category": "MARKETING",
238    "components": [
239      {
240        "type": "HEADER",
241        "format": "TEXT",
242        "text": "Forget something, {{1}}?",
243        "example": {
244          "header_text": [
245            "Pablo"
246          ]
247        }
248      },
249      {
250        "type": "BODY",
251        "text": "Looks like you left these items in your cart, still interested? Use code {{1}} to get 10% off!",
252        "example": {
253          "body_text": [
254            [
255              "10OFF"
256            ]
257          ]
258        }
259      },
260      {
261        "type": "BUTTONS",
262        "buttons": [
263          {
264            "type": "MPM",
265            "text": "View items"
266          }
267        ]
268      }
269    ]
270  }
271}

Example of authentication templates#

Python Code#
 1from pywa.types.templates import *  # noqa: F403
 2
 3authentication_code_autofill_button = Template(
 4    name="authentication_code_autofill_button",
 5    language=TemplateLanguage.ENGLISH_US,
 6    category=TemplateCategory.AUTHENTICATION,
 7    message_send_ttl_seconds=60,
 8    components=[
 9        AuthenticationBody(add_security_recommendation=True),
10        AuthenticationFooter(code_expiration_minutes=10),
11        Buttons(
12            buttons=[
13                OneTapOTPButton(
14                    text="Copy Code",
15                    autofill_text="Autofill",
16                    supported_apps=[
17                        OTPSupportedApp(
18                            package_name="com.example.luckyshrub",
19                            signature_hash="K8a/AINcGX7",
20                        ),
21                        OTPSupportedApp(
22                            package_name="com.example.luckyshrub",
23                            signature_hash="K8a/AINcGX7",
24                        ),
25                    ],
26                )
27            ]
28        ),
29    ],
30)
31
32authentication_code_copy_code_button = Template(
33    name="authentication_code_copy_code_button",
34    language=TemplateLanguage.ENGLISH_US,
35    category=TemplateCategory.AUTHENTICATION,
36    message_send_ttl_seconds=60,
37    components=[
38        AuthenticationBody(add_security_recommendation=True),
39        AuthenticationFooter(code_expiration_minutes=5),
40        Buttons(
41            buttons=[
42                CopyCodeOTPButton(
43                    text="Copy Code",
44                )
45            ]
46        ),
47    ],
48)
49
50zero_tap_auth_template = Template(
51    name="zero_tap_auth_template",
52    language=TemplateLanguage.ENGLISH_US,
53    category=TemplateCategory.AUTHENTICATION,
54    message_send_ttl_seconds=60,
55    components=[
56        AuthenticationBody(add_security_recommendation=True),
57        AuthenticationFooter(code_expiration_minutes=5),
58        Buttons(
59            buttons=[
60                ZeroTapOTPButton(
61                    text="Copy Code",
62                    autofill_text="Autofill",
63                    zero_tap_terms_accepted=True,
64                    supported_apps=[
65                        OTPSupportedApp(
66                            package_name="com.example.luckyshrub",
67                            signature_hash="K8a/AINcGX7",
68                        ),
69                    ],
70                )
71            ]
72        ),
73    ],
74)
JSON Code#
 1{
 2  "authentication_code_autofill_button": {
 3    "name": "authentication_code_autofill_button",
 4    "language": "en_US",
 5    "category": "AUTHENTICATION",
 6    "message_send_ttl_seconds": 60,
 7    "components": [
 8      {
 9        "type": "BODY",
10        "add_security_recommendation": true
11      },
12      {
13        "type": "FOOTER",
14        "code_expiration_minutes": 10
15      },
16      {
17        "type": "BUTTONS",
18        "buttons": [
19          {
20            "type": "OTP",
21            "otp_type": "ONE_TAP",
22            "text": "Copy Code",
23            "autofill_text": "Autofill",
24            "supported_apps": [
25              {
26                "package_name": "com.example.luckyshrub",
27                "signature_hash": "K8a/AINcGX7"
28              },
29              {
30                "package_name": "com.example.luckyshrub",
31                "signature_hash": "K8a/AINcGX7"
32              }
33            ]
34          }
35        ]
36      }
37    ]
38  },
39  "authentication_code_copy_code_button": {
40    "name": "authentication_code_copy_code_button",
41    "language": "en_US",
42    "category": "AUTHENTICATION",
43    "message_send_ttl_seconds": 60,
44    "components": [
45      {
46        "type": "BODY",
47        "add_security_recommendation": true
48      },
49      {
50        "type": "FOOTER",
51        "code_expiration_minutes": 5
52      },
53      {
54        "type": "BUTTONS",
55        "buttons": [
56          {
57            "type": "OTP",
58            "otp_type": "COPY_CODE",
59            "text": "Copy Code"
60          }
61        ]
62      }
63    ]
64  },
65  "zero_tap_auth_template": {
66    "name": "zero_tap_auth_template",
67    "language": "en_US",
68    "category": "AUTHENTICATION",
69    "message_send_ttl_seconds": 60,
70    "components": [
71      {
72        "type": "BODY",
73        "add_security_recommendation": true
74      },
75      {
76        "type": "FOOTER",
77        "code_expiration_minutes": 5
78      },
79      {
80        "type": "BUTTONS",
81        "buttons": [
82          {
83            "type": "OTP",
84            "otp_type": "ZERO_TAP",
85            "text": "Copy Code",
86            "autofill_text": "Autofill",
87            "zero_tap_terms_accepted": true,
88            "supported_apps": [
89              {
90                "package_name": "com.example.luckyshrub",
91                "signature_hash": "K8a/AINcGX7"
92              }
93            ]
94          }
95        ]
96      }
97    ]
98  }
99}

Example of a limited time offer template#

Python Code#
 1from pywa.types.templates import *  # noqa: F403
 2
 3limited_time_offer_caribbean_pkg_2023 = Template(
 4    name="limited_time_offer_caribbean_pkg_2023",
 5    language=TemplateLanguage.ENGLISH_US,
 6    category=TemplateCategory.MARKETING,
 7    components=[
 8        HeaderImage(example="4::aW..."),
 9        LimitedTimeOffer(text="Expiring offer!", has_expiration=True),
10        BodyText(
11            "Good news, {{1}}! Use code {{2}} to get 25% off all Caribbean Destination packages!",
12            "Pablo",
13            "CARIBE25",
14        ),
15        Buttons(
16            buttons=[
17                CopyCodeButton(example="CARIBE25"),
18                URLButton(
19                    text="Book now!",
20                    url="https://awesomedestinations.com/offers?code={{1}}",
21                    example="https://awesomedestinations.com/offers?ref=n3mtql",
22                ),
23            ]
24        ),
25    ],
26)
JSON Code#
 1{
 2  "limited_time_offer_caribbean_pkg_2023": {
 3    "name": "limited_time_offer_caribbean_pkg_2023",
 4    "language": "en_US",
 5    "category": "MARKETING",
 6    "components": [
 7      {
 8        "type": "HEADER",
 9        "format": "IMAGE",
10        "example": {
11          "header_handle": [
12            "4::aW..."
13          ]
14        }
15      },
16      {
17        "type": "LIMITED_TIME_OFFER",
18        "limited_time_offer": {
19          "text": "Expiring offer!",
20          "has_expiration": true
21        }
22      },
23      {
24        "type": "BODY",
25        "text": "Good news, {{1}}! Use code {{2}} to get 25% off all Caribbean Destination packages!",
26        "example": {
27          "body_text": [
28            [
29              "Pablo",
30              "CARIBE25"
31            ]
32          ]
33        }
34      },
35      {
36        "type": "BUTTONS",
37        "buttons": [
38          {
39            "type": "COPY_CODE",
40            "example": "CARIBE25"
41          },
42          {
43            "type": "URL",
44            "text": "Book now!",
45            "url": "https://awesomedestinations.com/offers?code={{1}}",
46            "example": [
47              "https://awesomedestinations.com/offers?ref=n3mtql"
48            ]
49          }
50        ]
51      }
52    ]
53  }
54}