$sitegpt Methods
An in-depth guide on how to use $sitegpt to control the SiteGPT chatbot from your javascript code.
The $sitegpt
object allows you to interact with and control the SiteGPT chatbot widget embedded on your website. You can use it to customize appearance, provide context, manage user sessions, and control the widget’s visibility.
Commands are sent using the push
method: window.$sitegpt.push([command, ...args])
.
Customize Widget Appearance
Add custom CSS
- Description: Apply your own CSS to the chatbot widget and style it according to your branding.
- Syntax:
window.$sitegpt.push(["set", "css", "css_string"])
Enhance Chatbot Context
Give extra context
- Description: Provide additional information to your SiteGPT bot for more relevant and contextual conversations, such as the current page the user is on.
- Syntax:
window.$sitegpt.push(["set", "context", ["prompt_prefix_string", "prompt_suffix_string"]])
Manage User Sessions
Automatically log the user in
- Description: Automatically log the user into the chatbot widget using their verified email address, eliminating the need for manual entry. This requires generating a secure signature on your backend.
- Syntax:
window.$sitegpt.push(["set", "user:email", ["email_string", "email_signature_string"]])
To generate the signature, you can use the following Node.js example:
Make sure you generate signatures with the HMAC-SHA256 algorithm.
Any other HMAC digest is not accepted and will be refused by the SiteGPT chatbot.
Security of User Verification
User Verification uses the HMAC-SHA256
signature algorithm, a standard and secure method for authenticating data.
When setting a user email via the $sitegpt
object, you must provide the signature computed on your backend. This signature uses your secret API key, known only to you and SiteGPT. Because only you and SiteGPT can generate valid signatures for a given email, an attacker without your API key cannot impersonate users.
Never generate signatures directly in your front-end code.
Doing so would expose your API key in the browser, allowing anyone to impersonate
your users.
Always generate signatures on your backend server and never leak your
API key.
Control Widget Visibility
You can programmatically control the chat widget’s visibility, which is especially useful if you have hidden the default chat bubble (hideBubble=true
in the embed script) and want to trigger the chat from your own UI elements (like a button).
Open the chat widget
- Description: Programmatically opens the chat widget window.
- Syntax:
window.$sitegpt.push(["open"])
Close the chat widget
- Description: Programmatically closes the chat widget window.
- Syntax:
window.$sitegpt.push(["close"])
Toggle the chat widget
- Description: Programmatically opens the chat widget if it’s closed, and closes it if it’s open.
- Syntax:
window.$sitegpt.push(["toggle"])