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({
  email: 'joe@example.com',
  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.

You may call setMetadata multiple times if you'd like but know that each time you call it, the metadata will be set to exactly what you pass in. So if you drop fields in subsequent calls, they will be removed from the metadata. This is to give you control over deleting fields if you want to.

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()

Send a proactive message (or set the welcome message)

Use this to customize the initial message in a new conversation with a user. Set the 2nd argument to try if you want to trigger a proactive message bubble above the chat widget to invite the user to chat. The message will them appear as the welcome message in the chat when the widget is opened.

// Send a proactive trigger message
window.duet.setTriggerMessage("Hi there! It seems like you need help with...", true)

// Just customize the welcome message
window.duet.setTriggerMessage("Welcome to Apple Support! ...")

Last updated