fbbotw.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:fbbotw 作者: JoabMendes 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号