def post_button_template(fbid, text, buttons):
""" Sends a button template with the specified text and buttons
(/docs/messenger-platform/send-api-reference/button-template).
:param str fbid: User id to send the buttons.
:param str text: Message to be displayed with the buttons (320 Chars).
:param list buttons: Dict of buttons that appear as call-to-actions, \
format :
>>> buttons = [
{
'type': 'web_url',
'url': 'https://petersapparel.parseapp.com',
'title': 'Show Website'
},
{
'type': 'postback',
'title': 'Start Chatting',
'payload': 'USER_DEFINED_PAYLOAD'
}
]
:return: `Response object <http://docs.python-requests.org/en/\
master/api/#requests.Response>`_.
"""
url = MSG_URL + PAGE_ACCESS_TOKEN
data = {}
data['recipient'] = {'id': fbid}
payload = {}
payload['template_type'] = 'button'
payload['text'] = text
payload['buttons'] = buttons
attachment = {"type": 'template', "payload": payload}
data['message'] = {"attachment": attachment}
data = json.dumps(data)
status = requests.post(url, headers=HEADER, data=data)
return status
评论列表
文章目录