问题
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:
This one works:
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 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)
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.
回答1:
“text”: “some string”
or ”attachment”: []
is required when using quick replies.
Check the fields required in the FB Docs
回答2:
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"
}]
}
}
来源:https://stackoverflow.com/questions/45899936/how-to-use-quick-replies-fb-in-a-python-chatbot