APIs & Integrations

AustinR
Member | Diamond Partner
Member | Diamond Partner

Execute custom JS event based on Chatbot response

Does anyone know if there's a way to execute a custom Javascript event on the customer browser when a customer selects a certain chatbot response? 

 

We are looking to open a video chat window (using OnSip.com) on a customer browser if they select a certain response in our Hubspot Chatbot workflow.

 

From looking at current Hubspot response actions, I can't see anything that would help. We can execute a Webhook, or execute a Node.js code snippet, but neither of these options would be able in interact with the customer browser. 

 

The only option I can see is to use the Conversations Live Chat Window API. However, this only seems to support 3 events (conversationStarted, conversationEnded, conversationUnreadChange). 

 

Ideally it would be useful if the chatbot could fire a custom event using a name (e.g. hs_chatbot_response_xx_received) that we can specifiy in the workflow action. On the customer browser, we can have Javascript that can listen for that custom event, and when received, can then close down the Hubspot chat window and open up the OnSip video chat window.

 

This doesn't appear to be possible, or is there some other way I can achieve the same result via some other approach with Hubspot. Have tried everything and can't see a way to do this!

 

2 Replies 2
awright415
Contributor

Execute custom JS event based on Chatbot response

I was hoping for similar functionality. So far, the only idea I've come up with (but would require a heavy lift) is having some sort of parallel system that can communicate w/ the browser via websockets.

 

A code snippet or webhook chatbot step would pass along info to that second system, which could then relay events back to the browser.

 

But you'd need a good correlation ID to pass between the systems. The chat widget SDK does give you a conversation ID that you can listen for, but it doesn't appear conversation ID is passed to either code snippet or webhook actions. What is passed to those actions is a contact VID for known contacts. So, if your use case doesn't need to support anonymous visitors, that might be your best bet.

 

Otherwise, I think we're left with lobbying Hubspot to either: 1) include conversation ID in the webhook and/or code snippet payloads, or 2) let us set custom state for the conversation from the client side that could be passed along to the appropriate chatbot actions.

WendyGoh
HubSpot Employee
HubSpot Employee

Execute custom JS event based on Chatbot response

Hey @AustinR,

 

Thanks for the detailed write up!

 

At the moment, this is not supported. The closest workaround that I can think of is probably to use the window.hsConversationsOnReady function: Execute functions when HubSpotConversations loads

 

However, this would means that the script is executed whenever the chat widget loads and not based by response.