implementation-examples
implementation-examples copied to clipboard
Rasa multiple responses not working with live chat
It's only returning a single-line response. I made a change in the code to return multiple lines but without buttons
Original Code - rasa_flask_router.py:
def send_to_bot(sender, message):
data = {
'sender': sender,
'message': message
}
headers = {"Content-Type": "application/json",
"Accept": "application/json"}
r = requests.post(f'{rasa_url}/webhooks/rest/webhook',
json=data, headers=headers)
return r.json()[0]['text']
My Code:
def send_to_bot(sender, message):
data = {
'sender': sender,
'message': message
}
headers = {"Content-Type": "application/json",
"Accept": "application/json"}
r = requests.post(f'{rasa_url}/webhooks/rest/webhook',
json=data, headers=headers)
print(r.text)
resposta = json.loads(r.text)
#print(resposta)
resposta_final = ''
for x in resposta:
for y in x.keys():
if y != 'text':
continue
resposta_final += (x['text']) + '\n'
print(resposta_final)
return resposta_final