-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy path07_whatsapp_interactive_message.py
More file actions
50 lines (37 loc) · 2.56 KB
/
07_whatsapp_interactive_message.py
File metadata and controls
50 lines (37 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import os
from cm_text import TextClient
from cm_text import MessageBuilder
# fetch the API key from environment variables
UNIQUE_API_KEY = os.getenv("CM_API_KEY")
if UNIQUE_API_KEY is None:
print('Please fill an environment variable named CM_API_KEY with your API key.')
to = ['your-phone-number']
# Instantiate client with your own api-key
client = TextClient(apikey=UNIQUE_API_KEY)
mb_header = MessageBuilder.create_interactive_message_header(type='text', text='my-header', media=None)
mb_body = MessageBuilder.create_interactive_message_body(text='my-body-text')
mb_footer = MessageBuilder.create_interactive_message_footer(text='my-footer-text')
# Create rows for when the user clicks on the button
mb_rows = [MessageBuilder.create_interactive_message_action_row(title='row1-content',
id='sect1-id1',
description='row1-description'),
MessageBuilder.create_interactive_message_action_row(title='row2-content',
id='sect1-id2',
description='row2-description')]
mb_rows2 = [MessageBuilder.create_interactive_message_action_row(title='row1-content',
id='sect2-id1',
description='row1-description'),
MessageBuilder.create_interactive_message_action_row(title='row2-content',
id='sect2-id2',
description='row2-description')]
# Divide the rows into different sections
section1 = MessageBuilder.create_interactive_message_action_section(title='section1', rows=mb_rows)
section2 = MessageBuilder.create_interactive_message_action_section(title='section2', rows=mb_rows2)
mb_section = [section1, section2]
mb_action = MessageBuilder.create_interactive_message_action(button='cta-button-content', buttons=[], sections=mb_section)
mb_interactive = MessageBuilder.create_interactive_message(type='list', header=mb_header, body=mb_body, footer=mb_footer, action=mb_action)
client.add_whatsapp_interactive_message(from_="pythonSDK", body='fallback-body', interactive=mb_interactive, to=to)
# Instantiate client with your own api-key
response = client.send()
# Response is an object of type: https://www.w3schools.com/python/ref_requests_response.asp
print(response.text)