Decagon AI
Search
K
Comment on page

Advanced widget functionality

Note that for any of the window.duet functions to work, you must wait until the primary <script> is loaded. Consult the intro guide to see how to do that.

Passing in Metadata

If you want to send arbitrary metadata (e.g. other details about the user), you may call window.duet.setMetadata({...}). Anything sent as metadata will be passed to Decagon servers and will be visible in the admin console for each conversation. For example:
window.duet.setMetadata({
username: 'Zezima',
fullName: 'Joe Smith',
isTrial: true,
points: 6,
// any fields that you want
})
If you are setting user email and id via metadata, please use the fields email and userId respectively.

Tracking events

If you want to track events, you may set a listener via window.duet.setEventListener so that your callback is called every time there is a meaningful user action.
For example:
window.duet.setEventListener((event) => console.log(event))
// Here, `event` is of the form {eventName: "DUET_INITIALIZE"}
Here are the events we currently support:
  • User clicks the icon to open a chatbot window:
    {eventName: "DUET_INITIALIZE"}
  • User closes the chatbot window: {eventName: "DUET_DEINITIALIZE"}
  • User begins typing:
    {eventName: "DUET_USER_INPUT"}
  • User sends a message:
    {eventName: "DUET_USER_SEND"}
  • Bot responds:
    {eventName: "DUET_RESPONSE"}

Dynamically opening/closing the widget

This should rarely be needed, but you can dynamically open/close the widget using these functions:
// Open the widget
window.duet.open()
// Close the widget
window.duet.close()
Optionally, you may also specify that when the widget is closed, it should be hidden. Note that this will not affect the widget when it is open. You can toggle the hidden mode like so:
// Enable hidden mode
window.duet.hide()
// Disable hidden mode
window.duet.unhide()