Sending Interactive Messages#

Send a message with selection keyboard#

  • You can use selection keyboard only with text messages.

  • The maximum number of section rows is 10.

Color selection message#
 1from pywa import WhatsApp
 2from pywa.types import SectionList, Section, SectionRow
 3
 4wa = WhatsApp(phone_id='972123456789', token='xxxxx')
 5recipient = '972987654321'
 6
 7wa.send_message(
 8    to=recipient,
 9    header='Select your favorite color',
10    text='Tap a button to select your favorite color:',
11    footer='⚡ Powered by PyWa',
12    buttons=SectionList(
13        button_title='Colors',
14        sections=[
15            Section(
16                title='Popular Colors',
17                rows=[
18                    SectionRow(
19                        title='🟥 Red',
20                        callback_data='color:red',
21                        description='The color of blood',
22                    ),
23                    SectionRow(
24                        title='🟩 Green',
25                        callback_data='color:green',
26                        description='The color of grass',
27                    ),
28                    SectionRow(
29                        title='🟦 Blue',
30                        callback_data='color:blue',
31                        description='The color of the sky',
32                    )
33                ],
34            ),
35            Section(
36                title='Other Colors',
37                rows=[
38                    SectionRow(
39                        title='🟧 Orange',
40                        callback_data='color:orange',
41                        description='The color of an orange',
42                    ),
43                    SectionRow(
44                        title='🟪 Purple',
45                        callback_data='color:purple',
46                        description='The color of a grape',
47                    ),
48                    SectionRow(
49                        title='🟨 Yellow',
50                        callback_data='color:yellow',
51                        description='The color of the sun',
52                    )
53                ]
54            )
55        ]
56    )
57)

Send a message with buttons keyboard#

  • You can attach up to 3 buttons to a message.

YouTube video info message#
 1from pywa import WhatsApp
 2from pywa.types import Button
 3
 4wa = WhatsApp(phone_id='972123456789', token='xxxxx')
 5
 6recipient = '972987654321'
 7requested_vid_id = 'T9RRe4ZsSGw'
 8
 9wa.send_image(
10    to=recipient,
11    image=f'https://i.ytimg.com/vi/{requested_vid_id}/hqdefault.jpg',
12    caption='Chandler Jokes | Friends • 2.9M views • 1 year ago',
13    footer='⚡ Powered by PyWa',
14    buttons=[
15        Button(title='⬇️ Download', callback_data=f'dl:{requested_vid_id}'),
16        Button(title='💬 Comments', callback_data=f'cmnts:{requested_vid_id}'),
17        Button(title='🎬 Info', callback_data=f'info:{requested_vid_id}'),
18    ]
19)