# Actions

The following methods can be invoked on the global variable collectchat to
perform actions on the chat widget.

Note: Make sure to wrap these methods inside collectchat.ready
[https://collect.chat/help/developer/article/1179] if you use them in a <script>
tag.


COLLECTCHAT.OPEN()

Opens the chat widget on the click of a button or link.

<a href="#" onclick="collectchat.open()">Open Chat</a>


COLLECTCHAT.OPEN(FORMID)

Opens a chat widget by passing the Form ID as a parameter. Useful when you want
to open a second chat widget on a button/link click (this hides the first chat
widget). Both forms' snippet codes must be present on the page.

<a href="#" onclick="collectchat.open('5ad8c8e32ffab091351b113d')">Open Chat</a>


COLLECTCHAT.CLOSE()

Closes a chat 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 chat widget. Closes it if open, and vice versa.

<a href="#" onclick="collectchat.toggle()">Open Chat</a>


COLLECTCHAT.LOAD(FORMID)

Loads the chat widget launcher on a given webpage by passing the Form ID. This
does not open the widget. If a chat 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 form (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
[https://collect.chat/help/developer/article/1184] for the full explanation and
a code sample.


COLLECTCHAT.MESSAGE(MESSAGE)

Jumps to any question number in your script, or shows custom message type
[https://collect.chat/help/article/1028-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>