fascinating-indigo•17mo ago
API - event listening
Is there a way to add a block that would listen to events coming from an API?
For example once a status update would be sent to voiceflow through the block, then we could continue the flow
46 Replies
Yes, you can add a block that listens to events coming from an API in Voiceflow. This can be achieved using the "Global Listen" feature and "Custom Actions" in Voiceflow.
The "Global Listen" feature in Voiceflow listens for user events until an event is detected. When this setting is enabled, the "Custom Actions" elements continue to listen for a user event like a button click. This can be useful when you want to select a Carousel Button later. The user events are captured in the
lastevent
system variable, which can trace the last user event like a button selection, carousel button, or when an intent is triggered.
A "Custom Action" step is similar to an event handler. When a Voiceflow application is commanded to stop on a "Custom Action" step, it waits for the client application to send back an event, or a "Custom Action" request, to the Voiceflow diagram. Before sending the event, the client application can perform tasks like triggering navigation on a website, processing a credit card payment, opening windows on a car, handing off a call to a human, or rendering a custom user interface element for the "Custom Action".
When a user interacts with the client app, for example, to talk to a human, the client app can send an event to the Voiceflow diagram, which can then continue the flow based on the event received.
Please note that the type of the lastevent
system variable is a string, and its payload can be an object or a string.
For more detailed information, you can refer to the Voiceflow documentation here.fair-rose•17mo ago
No, but you can do the other way around, query the dialog API from an external system
fascinating-indigoOP•16mo ago
any documentation about it ?
can you elaborate please or give some examples ?
would be helpful. Thanks a lot @MikeG
fair-rose•16mo ago
Maybe i miss interpreted, can you elaborate on what your trying to achieve?
fascinating-indigoOP•16mo ago
ok
lets say my user have to do some actions outside of the flow (ex : fill a form on typeform, or pay with a credit card on paypal, or whatever ...). We've built our flow in a way that if this step (external action) is not completed by the user, the user can not progress in the flow.
My question is : is the API block in VoiceFlow in Event listening mode ?
If the API block is in event listening mode, it means that as soon as the action will be completed by the user outside of the flow ( ex : paypal payment), the flow would get "unlocked" so the user would be allowed to jump on the next step in the flow.
On the contrary, if the API block is not in event listening mode, how to manage external actions and use it to trigger steps in my flow ?
clearer ? @MikeG
fair-rose•16mo ago
Ah, you could do this with the new listen option in a custom function https://developer.voiceflow.com/docs/functions#following-a-specific-path-based-on-user-input
It'll wait to continue until you hit the API 🙂
fascinating-indigoOP•16mo ago
thanks @MikeG
the Listen funtion works only with buttons ?
or can it be used with any kind of blocks in VoiceFlow ?
fair-rose•16mo ago
I believe it would be anything, i dont think there's a restriction on it
fascinating-indigoOP•16mo ago
ok thanks @MikeG
so you confirm that standard API blocks in VoiceFlow are not in Listen mode by default ?
fair-rose•16mo ago
Indeed they are not
fascinating-indigoOP•16mo ago
got it thanks @MikeG
@MikeG
From what I understand, i can make a POST request to the following endpoint https://api.voiceflow.com/v2/versions/{versionID}/export,
is that right?
And how to i fetch it from voiceflow and trigger a flow?
fair-rose•16mo ago
No you would need to hit the
/interact
endpointfascinating-indigoOP•16mo ago
Let's say a user makes a payment, my API get updated with a new event /new_payment_done and i want this endpoint /new_payment_done to trigger an intent in VoiceFlow.
@MikeG You confirm that the right VoiceFlow endpoint is /interact ?
fair-rose•16mo ago
/interact
is indeed what moves the build forwardfascinating-indigoOP•16mo ago
thanks @MikeG
So each we get paid, we would be able to trigger an intent via /interact endpoint without requiring any action from the user, right ?
fair-rose•16mo ago
You can ye, the interact would move the state forward
but it wouldnt show anything to the user
fascinating-indigoOP•16mo ago
what do you mean by "wouldn't show anything to the user" ?
fair-rose•16mo ago
Well, you'd be hitting the interact route, so it would advance the state of the user. But there is no actual way of sending a message to the client of the user natively
So you'd advanced the user to the next step, but he wouldnt get a response or anything like that on the client side
fascinating-indigoOP•16mo ago
I don’t get your point sorry. @MikeG any example ?
fair-rose•16mo ago
So lets say user is on your chat bot. He sais "Hi", this is going to hit the
/interact
endpoint and continue your flow. So maybe the next step of your flow is "Please enter your name"
Now, lets say you from an external system hit the /interact
endpoint now with the same session ID as from your the user using your chatbot. And included in that /interact
you set the name of the user
It's going to advance the state of the user to the next step (Maybe its "What is your age?")
The external system you used to hit that /interact
endpoint will get the response of "What is your age?"
But the user on the chatbot never willl
That's what I was trying to explain 🙂
You cant send messages natively from server to client.. So in this scenario, the user state is at the question "What is your age?" even though the last thing the user see's in the chat is "Please enter your name?"
If the user now tries to reply to the "Please enter your name?", the chat bot will hit the /interact
endpoint again, but the user state is now on the question "What is your age?" thus his name will be filled in for that question, and the user state advances again to the next stepfascinating-indigoOP•16mo ago
We only want to use /interact to trigger Intents, not messages.
In your example, you only talk about messages. How does /interact works if instead of triggering messages, it triggers Intents ?
fair-rose•16mo ago
ye the interact endpoint is all dialog related stuff
that included intents
fascinating-indigoOP•16mo ago
So it means that we can trigger any intent thanks to /interact. Then if a message is set up in VoiceFlow to be sent once the intent is triggered, could we expect this following flow :
1/ we use interact to launch an intent from our external API
2/ once the intent is launched, the pre set-up message is automatically sent to the user
3/ the user can answer anything to this just-received message
Your confirm @MikeG
fair-rose•16mo ago
So, if im understanding that correctly, it wouldnt work, because it cant send a message to the user upon your interaction, the user itself needs to send a message
fascinating-indigoOP•16mo ago
It’s not /interact that trigger the message but the intent triggering itself. /interact triggers the intent then the intent triggers the message.
fair-rose•16mo ago
Right, and Voiceflow can not send a message natively to the user unless the user itself has triggered that interaction
So you could trigger an intent, and it would set the user state there so the next message the user sends will continue the flow in that intent
But it wont be able to send a message to the user upon your interaction to hit that intent
fascinating-indigoOP•16mo ago
So how to to do it ?
How an external api can trigger an intent as a user would do it ?
fair-rose•16mo ago
Requires programming. You would need to adapt the react-chat package on the voiceflow github to accept something like websockets, then once you trigger the intent, send a websocket from your server to the client of the user to show the message you get as a response from the interact endpoint
It's pretty complex to do
fascinating-indigoOP•16mo ago
Any documentation about it ?
We can program 🙂
FYI we don’t want to use the chat in a corner of the website but in WhatsApp
fair-rose•16mo ago
No documentation about it, its a thing needed to be done manually
Right, makes sense
fascinating-indigoOP•16mo ago
Sure that’s the plan
fair-rose•16mo ago
Though definitely possible, we're also working on something like that for https://flowbridge.app
fascinating-indigoOP•16mo ago
Where to find the react chat package ?
fair-rose•16mo ago
fascinating-indigoOP•16mo ago
ETA ?
What we are supposed to do with that ? You mentioned the web sockets but does it makes sense as we plan to deploy voiceflow through WhatsApp ?
fair-rose•16mo ago
Its a different use case, human handoff, so clients of agencies can take over the conversation live
ah yeah with whatsapp thats not needed
then you can just send the response from the interact directly back to the whatsapp user
so then your use case works fine
You can just hit the interact endpoint with the intent and send back the response to the user 🙂
fascinating-indigoOP•16mo ago
100% sure ? 😊
what i did not mention is that when we trigger the intent through an external API, the flow in voiceflow has already started minuts or hours before. So as the flow is not ended, the discussion is supposed to be still "opened" to recieve messages from us as it is continuing the discussion with the user, already initiated by him/her earlier.
don't know if what i'm saying is clear enough ...
fair-rose•16mo ago
Ye that's fine then
Just remember WhatsApp api only has a 24hour window to reply
Otherwise it becomes paid an requires a custom template to respond
fascinating-indigoOP•16mo ago
Yes we know that thanks @MikeG
In the case there is no communication over the 24h, how to re-launch a flow in voiceflow , sending a paid message with WhatsApp ? Is there any « re-activation » intent in VoiceFlow for this specific purpose ?
fair-rose•16mo ago
Not sure I understand
fascinating-indigoOP•16mo ago
ok
Is there any way to trigger an intent in VoiceFlow from an external API if the flow has been ended ?
fair-rose•16mo ago
Hmm
I guess an intent would always work as its always listening for it
So i think yes, but don't quote me on that
fascinating-indigoOP•16mo ago
in the function /interact the documentation asks me for an User ID. How to test what we are crafting with a "test" User ID ? @MikeG
fair-rose•16mo ago
i think thats the session id?
like which user state you want to be using basically
fascinating-indigoOP•16mo ago
alright @MikeG
i'll keep you up to date on how we progress
thanks for the help bro
fair-rose•16mo ago
No worries 🙂