Creating and Sending Template Messages#
Create Template#
1from pywa.types import NewTemplate as NewTemp
2wa = WhatsApp(...)
3
4wa.create_template(
5 template=NewTemp(
6 name='buy_new_iphone_x',
7 category=NewTemp.Category.MARKETING,
8 language=NewTemp.Language.ENGLISH_US,
9 header=NewTemp.Text('The New iPhone {15} is here!'),
10 body=NewTemp.Body('Buy now and use the code {WA_IPHONE_15} to get {15%} off!'),
11 footer=NewTemp.Footer('Powered by PyWa'),
12 buttons=[
13 NewTemp.UrlButton(title='Buy Now', url='https://example.com/shop/{iphone15}'),
14 NewTemp.PhoneNumberButton(title='Call Us', phone_number='1234567890'),
15 NewTemp.QuickReplyButton('Unsubscribe from marketing messages'),
16 NewTemp.QuickReplyButton('Unsubscribe from all messages'),
17 ],
18 ),
19)
Create Authentication Template#
1from pywa.types import NewTemplate as NewTemp
2wa = WhatsApp(...)
3
4wa.create_template(
5 template=NewTemp(
6 name='auth_with_otp',
7 category=NewTemp.Category.AUTHENTICATION,
8 language=NewTemp.Language.ENGLISH_US,
9 body=NewTemp.AuthBody(
10 code_expiration_minutes=5,
11 add_security_recommendation=True,
12 ),
13 buttons=NewTemp.OTPButton(
14 otp_type=NewTemp.OTPButton.OtpType.ZERO_TAP,
15 title='Copy Code',
16 autofill_text='Autofill',
17 package_name='com.example.app',
18 signature_hash='1234567890ABCDEF1234567890ABCDEF12345678'
19 )
20 ),
21)
Sending Template Messages#
1from pywa.types import Template as Temp
2wa = WhatsApp(...)
3wa.send_template(
4 to='1234567890',
5 template=Temp(
6 name='buy_new_iphone_x',
7 language=Temp.Language.ENGLISH_US,
8 header=Temp.TextValue(value='15'),
9 body=[
10 Temp.TextValue(value='John Doe'),
11 Temp.TextValue(value='WA_IPHONE_15'),
12 Temp.TextValue(value='15%'),
13 ],
14 buttons=[
15 Temp.UrlButtonValue(value='iphone15'),
16 Temp.QuickReplyButtonData(data='unsubscribe_from_marketing_messages'),
17 Temp.QuickReplyButtonData(data='unsubscribe_from_all_messages'),
18 ],
19 ),
20)
Sending Authentication Template Messages#
1from pywa.types import Template as Temp
2wa = WhatsApp(...)
3wa.send_template(
4 to='1234567890',
5 template=Temp(
6 name='auth_with_otp',
7 language=Temp.Language.ENGLISH_US,
8 buttons=Temp.OTPButtonCode(code='123456'),
9 ),
10)