如何在python chatbot中使用快速答复(FB)? [英] How to use quick replies (FB) in a python chatbot?

查看:105
本文介绍了如何在python chatbot中使用快速答复(FB)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用Python构建一个Facebook Messenger机器人,尽管我已经知道如何发送简单的文本消息和通用模板,但是用于快速回复的脚本无法正常工作。到目前为止,这是我的代码:

I'm building a Facebook Messenger bot in Python and my script for quick replies is not working event though I already know how to send simple text messages and generic templates. This is my code so far:

text = {
    "recipient": {
        "id": user_id
    },
    "message": {
        "text": "some text"
    }
}



这不是:



This one doesn't:

question = {
    "recipient": {
        "id": user_id
    },
    "message": {
        "quick_replies": [{
            "content_type": "location"
            # "title": "RED",
            # "text": "red",
            # "payload": "red"
         }]
    }
}



POST两者:



POST for both:

headers={"Content-Type": "application/json"}
requests.post('url', data = json.dumps(text), headers=headers)
requests.post('url', data = json.dumps(question), headers=headers)

在此示例中,由于我试图更改标题,文本和有效内容使脚本的工作与位置一样基本...但是我不断收到问题的回复400;

In the example, title, text and payload are commented since I'm trying to make the script work with something as basic as location... but I keep receiving a response 400 for 'question'; 'text' works just fine.

推荐答案

解决方案是将文本键放在 quick_replies旁边;否则-在FB文档中提到的列表/字典 quick_replies(对于JavaScript)中-无法正常工作:

The solution is putting "text" key alongside "quick_replies"; otherwise - inside list/dict "quick_replies" as mentioned in FB Docs (for JavaScript) - it won't work:

question = {
    "recipient": {
        "id": user_id
    },
    "message": {
        "text": "<THIS_IS_WHERE_THE_ACTUAL_TEXT_GOES>,
        "quick_replies": [{
            "content_type": "text"
            "title": "Option 1",
            "payload": "option1"
         }]
    }
}

这篇关于如何在python chatbot中使用快速答复(FB)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆