Execute webhook on exit or timeout
# 🤝help
i
Is there a way to create a webhook that will fire if the conversation times out or if the user "unofficially" exits the conversation, for example, by closing their browser rather than selecting some type of "Exit", "I have no more questions", "All good", etc. single choice button to "officially" end the convo?
w
By a webhook, do you mean that you want Botpress to notify an external backend whenever one of these events occur. Or you mean, that we want to be able to react to these events in your bot flows ?
i
I want to send data collected to a Google sheet.
My goal is to send one webhook to google sheet for all data points collected during the convo. This is easy to do if the user "properly" ends a convo. But if they exit the convo before the webhook is sent, I will loose all data. Right now I'm having to send up to four webhooks throughout my convo after each data point is collected to ensure I don't lose the opportunity to collect the data.
a
yes, you can do that by adding an execute code in the "Timeout" conversation flow

https://cdn.discordapp.com/attachments/1135571925557583943/1135574151080448102/image.png

i
Thanks Patrick! I was thinking I could easily do this in the timeout convo flow by sending the webhook just before it times out, but is there any way to send if a user exits such as closing their browser?
w
I theory, you should not worry about this, the conversatioon will timeout at somepoint anyway. Or do you need to absolutely send the data when the browser is closed ?
i
Oh, I see. So are you saying the conversation will time out even if the user isn't currently active on a platform where the bot is installed? In other words, if a user closes their browser without "officially" ending a convo, the convo will still be active until it times out?
w
correct.
You can configure the inactivity timeout in your chatbot settings

https://cdn.discordapp.com/attachments/1135571925557583943/1135578271241752598/Screenshot_2023-07-31_at_10.21.59_AM.png

i
Excellent! Can you please suggest the best way to fire the webhook just before timeout?
w
There is no way to hook just before timeout, i would suggest to add an execute code card in the beginning of the builtin
Timeout
Flow. As shown on the screenshot

https://cdn.discordapp.com/attachments/1135571925557583943/1135591775290015905/Screenshot_2023-07-31_at_11.15.56_AM.png

i
It seems to be working well. Thanks for your assistance @witty-football-93730 ! Much appreciated!
w
pleasure is mine
i
This worked successfully on three tests yesterday morning. Stopped working yesterday afternoon and still isn't working today. Didn't change anything regarding the code or variables. Same code works correctly when triggered by the user. I thought the issue might be not being able to connect variables to the main workflow since there isn't a timeout workflow node in the main to set the variables. So I changed all my variables to bot variables and that didn't work either.
w
Do you know if in your failing tests, the conversation ended ? By conversation ended I mean, the conversation flowed on a "end" node. Or maybe the conversation flowed on a not connected transition ? In these 2 cases, it's possible that your timeout flow won't fire.
i
In my main conversation flows, I have the standard "any more questions" yes/no options throughout. If the user choose no, it transitions to a "good bye" message node, then transitions to a execute node to send data to google sheets via make.com. It then transitions to "End." As long as the user chooses any of the "no" choices which all transition to the goodbye node, all's well. But if I exit the browser or do nothing for 5 mins (reset timeout to 5 mins for testing) it doesn't execute. I have thoroughly tested the main workflow and have no failing tests.

https://cdn.discordapp.com/attachments/1135571925557583943/1135947719475724308/Convo_End.png

https://cdn.discordapp.com/attachments/1135571925557583943/1135947719719010344/Timeout.png

Also, as a side note, the execute code in the main workflow just before "end" is exactly the same as the execute code in the timeout WF.
Out of curiosity, I removed the execute code node from the main workflow entirely and moved it to the conversation end workflow as shown in the attached pic. Worked perfectly just as it does if the execute code node is in the main workflow. I didn't even have to setup any variables in the conversation end workflow.

https://cdn.discordapp.com/attachments/1135571925557583943/1135966343674478592/Convo_End_WF.png

59 Views