https://discord.gg/botpress logo
How to get the right Chat API repsonse to external...
# 🤝help
g
Hi there! I am trying out Chat API with to recieve query and transmit reply to an external service. The flow looks like this: External Service User Input Query -> Chat API -> Botpress -> Botpress response -> Chat API - External Service Display -> Loop Back to User Input Query Field I am able to follow the guide to send query to Botpress. However I am stuck at the step of transmitting the right response from Botpress back to my external service. In actual execution, the response always equals to user input, which is incorrect. Eg. If user enter "test" as query, the response is "test" too. But when I debug listMessages, the output is correct, there is always the latest correct response tagged in [0] payload. So I thought this was because botpress might need time to think of a response, so I added a 10s wait block, but still the same. Now I also read in discord that some users sort of encounter the same issue. I wonder if anyone had managed to get the right response back from chat api timely and correctly? Thanks!
c
The issue you're seeking-where the response echoes the user input-usually happens because the external service fetches the message before Botpress has processed it.
g
You are right! I did try a wait 10s block before listMessage but its still the same. 😅
c
I think you can solve it by using the Botpress Webhook
- Configure an event webhook in Botpress - Botpress will POST the bot's reply to your external service as soon as it's ready - Your external service doesn't need to "poll" at all - it just listens for replies.
g
Thank you! Offhand, i don’t remember coming across this webhook in chat api documentation. Will go through it again. 🙂
c
Botpress does support webhooks.
g
I found the listenConversation webhook from chat api. I tested it from the chat api playground with a correct x-user and conv ID but there are no responses being GET when i sent in a new query to the same convID with the playground listening in.
c
> The
listenConversation
webhook doesn't return messages with GET. It only sends events to your webhook URL when new messages are created in that conversation. To test, set up a server endpoint, register it as the webhook, and then send a message into the conversation. You'll see the webhook fire withthe new message payload.
g
Do you mean setting another webhook node after the listenConversation webhook node?
c
You don't need to add another webhook node after
listerConversation
.
g
Right. So I tested it and sent a new input query to the relevant conversation ID. But that webhook is not showing any output. 🥲
c
It sounds like your webhook isn't firing because the server endpoint you provided either isn't reachable or not set up to receive POST request
You should make sure you webhook URL is publicly accessible.
3 Views