githubEdit

Auto-Close After Handoff

Automatically close the chat widget after a conversation is transferred to a human agent.

This example shows how to automatically close the chat widget after a conversation has been transferred to a human agent. This is useful for cleaning up the UI once support handoff is complete.

What You'll Learn

  • Listen for the ticket:agent_handoff event

  • Use closeTicket() to end the conversation

  • Use close() to hide the widget

Use Case

When a customer is transferred to a human agent, you may want to:

  1. Keep the widget open briefly so the user sees the confirmation

  2. Automatically close the widget after a delay

  3. Start fresh for the next interaction

This prevents abandoned chat widgets from cluttering the screen after support handoff.

Prerequisites

  • Alhena SDK installed on your website

  • Helpdesk integration configured (Zendesk, Freshdesk, etc.)

Code Example

How It Works

  1. Event fires: When a user submits their email and a ticket is created in your helpdesk, the ticket:agent_handoff event fires

  2. Delay: We wait 60 seconds (configurable) to give the user time to see the confirmation

  3. Close ticket: closeTicket() ends the current conversation, preparing the widget for a new conversation

  4. Hide widget: close() minimizes the widget

Customization

Change the delay

Adjust the timeout value (in milliseconds):

Show a notification before closing

Keep widget visible but reset conversation

If you want to close just the ticket but keep the widget visible:

Last updated