Viber API allows to send some message on conversation_started
event type to allow user to subscribe. From documentation about "welcome message", I see following code, that successfully sends text and image:
{
"sender": {
"name": "John McClane",
"avatar": "http://avatar.example.com"
},
"tracking_data": "tracking data",
"type": "text",
"text": "Welcome to our bot!",
"media": "http://www.images.com/img.jpg",
"thumbnail": "http://www.images.com/thumb.jpg"
}
But how to add some buttons there?
I want my users to be able to press them to subscribe and start conversation with my bot.
I tried to add following to message, but it didn't work:
"keyboard": {
"Type": "keyboard",
"DefaultHeight": true,
"Buttons": [{
"ActionType": "reply",
"ActionBody": "reply to me",
"Text": "Key text",
"TextSize": "regular"
}]
}
After some tries I figured out that can't use both media
+ thumbnail
and keyboard
in the same "Welcome message". So I removed media
and thumbnail
keys. Now the following code works:
{
"sender": {
"name": "John McClane",
"avatar": "http://avatar.example.com"
},
"tracking_data": "tracking data",
"type": "text",
"text": "Welcome to our bot!",
"keyboard": {
"Type": "keyboard",
"DefaultHeight": true,
"Buttons": [{
"ActionType": "reply",
"ActionBody": "reply to me",
"Text": "Key text",
"TextSize": "regular"
}]
}
}