The following methods can be invoked on the global variable collectchat to perform actions on the chatbot widget.
Note: Make sure to wrap these methods inside collectchat.ready if you use them in a <script> tag.
collectchat.open()
Opens the chatbot widget on the click of a button or link.
<a href="#" onclick="collectchat.open()">Open Chat</a>collectchat.open(formID)
Opens a chatbot widget by passing the Chatbot ID as a parameter. Useful when you want to open a second chatbot widget on a button/link click (this hides the first chatbot widget). Both chatbots' snippet codes must be present on the page.
<a href="#" onclick="collectchat.open('5ad8c8e32ffab091351b113d')">Open Chat</a>collectchat.close()
Closes a chatbot widget that is in an open state, when a user clicks a button or link.
<a href="#" onclick="collectchat.close()">Close Chat</a>collectchat.toggle()
Toggles the state of the current chatbot widget. Closes it if open, and vice versa.
<a href="#" onclick="collectchat.toggle()">Open Chat</a>collectchat.load(formID)
Loads the chatbot widget launcher on a given webpage by passing the Chatbot ID. This does not open the widget. If a chatbot widget has been destroyed using unload, you can only bring it back using this method.
<a href="#" onclick="collectchat.load('5ad8c8e32ffab091351b113d')">Start Chat</a>collectchat.unload()
Completely removes the chatbot (both launcher and widget) from the page.
<a href="#" onclick="collectchat.unload()">Hide Chat</a>collectchat.clear()
Clears the chat history or previous conversation. Useful when you don't want the visitor to continue where they left off and instead start from the first message.
<a href="#" onclick="collectchat.clear()">Clear Chat History</a>collectchat.set(key, value)
Adds custom data to the response. See Sending Custom Data for the full explanation and a code sample.
collectchat.message(message)
Jumps to any question number in your script, or shows custom message type messages inside the conversation. Useful for customizing the conversation based on user interactions on the webpage.
<a href="#" onclick="collectchat.message(2)">Go to question 2</a>
<a href="#" onclick="collectchat.message('Thanks for clicking the link')">Display Message</a>