I am creating a Facebook messenger chatbot with pymessenger
, flask
and wit.at
. I want to add buttons as options in my chatbot conversation.
For example
" Generic Offer 1"+"\n"+" Generic Offer 2"+"\n"+" Generic Offer 3"
is what I want to show up as a button to user instead of just text. So the user can select one offer. Facebook has the option to add buttons https://developers.facebook.com/docs/messenger-platform/send-messages/template/button/ via JSON.
I want to do the similar thing. But I don't know how to do it. I can do simple text thing but now this, because I don't know JSON. As of now, my chatbot is replying via bot.send_text_message(sender_id, response)
.
def webhook():
data = request.get_json()
log(data)
if data['object'] == 'page':
for entry in data['entry']:
for messaging_event in entry['messaging']:
sender_id = messaging_event['sender']['id']
recipient_id = messaging_event['recipient']['id']
if messaging_event.get('message'):
if 'text' in messaging_event['message']:
messaging_text = messaging_event['message']['text']
else:
messaging_text = 'no text'
response = None
entity, value = wit_response(messaging_text)
if entity == 'newstype':
response = "OK. I will send you {} news".format(str(value))
elif entity == 'cust_greet':
response = get_message()
elif entity == 'cust_greet2':
response = get_message2()
elif entity == 'cust_offer':
#response = offer_response
response = " Generic Offer 1"+"\n"+" Generic Offer 2"+"\n"+" Generic Offer 3"+"\n"+" ️ for more offer enter your cust id"
#val_off = test.val_off
bot.send_text_message(sender_id, response)