"Payload" option on Facebook Bots buttons

Matheus208 picture Matheus208 · Apr 25, 2016 · Viewed 12.4k times · Source

Facebook Send API mentions a "payload" type you can set for buttons on the Generic Response Template. However, they don't say how it works, other than:

For postback buttons, this data will be sent back to you via webhook

But how is it sent back? I don't receive any messages when I click the payload button. Has anyone successfully used it?

Answer

Juergen picture Juergen · Apr 27, 2016

I tested it and it works for me. The payload of a button acts like the value on a html button. This means it's not visible to the user but it's the value that's send back to you.

If you create a button like that:

'attachment': {
    'type': 'template',
    'payload': {
        'template_type': 'button',
        'text': 'This is the description',
        'buttons': [
             {
                 'type': 'postback',
                 'title': 'This is the visible text',
                 'payload': 'This is the value you get back'
             }
        ]
 }

A callback including a payload looks like that:

{'timestamp': 1461697120850, 'postback': {'payload': 'this is the value you get back'}, 'recipient': {'id': xxxxxxxx}, 'sender': {'id': xxxxxxxx}}