# Hand over to a human

Source: https://docs.revoplyai.com/guides/hand-over-to-a-human/

> Open a ticket in your helpdesk when the assistant hands a conversation to your team, using the conversation.handover event.

When the assistant cannot or should not carry on (the customer asks for a person, is upset,
or asks something only your team can do) it hands the conversation to your team. The
[`conversation.handover`](/webhooks/events/conversation-handover/) event tells your
systems at that moment, so you can open a ticket, page someone or post to a channel.

## 1. Choose the events [#1-choose-the-events]

Add an endpoint under **Integrations → Webhooks**, or edit one, and choose **Handed over to
your team**. Add **Conversation assigned** and **Conversation resolved** to follow the
conversation afterwards. Build the receiver as in
[Receive messages with webhooks](/guides/receive-messages-with-webhooks/).

## 2. Read the event [#2-read-the-event]

It fires when the conversation is handed over: the customer asked for a person, the
assistant was missing information, a flow reached a handover step, a lead qualified for a
handover, or loop protection stepped in. It fires once per handover: a customer who asks
twice while the handover is open raises it once.

| Field               | Holds                                                                                                                                                                                                                         |
| ------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `data.reason`       | Why, as a stable code: `customer_asked_for_person`, `missing_information`, `needs_staff_action`, `customer_upset`, `qualified_lead`, `flow_handover`, `message_burst`, `unsupported_media`… Treat an unknown code as "other". |
| `data.reasonText`   | The assistant's own words, when it gave any. For people; often Arabic.                                                                                                                                                        |
| `data.conversation` | The conversation's `id`, `channelId` and `channelType`                                                                                                                                                                        |
| `data.contact`      | The customer's `id`, `name`, `phone` and `whatsAppId`, where the channel knows them                                                                                                                                           |

## 3. Open a ticket [#3-open-a-ticket]

Turn the event into a ticket, keyed on the event `id` so a repeated delivery opens one
ticket:

```js
export function ticketFromHandover(event) {
  if (event.type !== 'conversation.handover' || event.test) return null;

  const { conversation, contact, reason, reasonText } = event.data;
  return {
    // One ticket per event, however often the event is delivered.
    externalId: event.id,
    subject: `Handover (${reason}): ${contact?.name ?? contact?.phone ?? 'a customer'}`,
    // The assistant's own words, when it gave any; often Arabic.
    description: reasonText ?? '',
    priority: reason === 'customer_upset' ? 'high' : 'normal',
    channelType: conversation.channelType,
    conversationId: conversation.id,
    phone: contact?.phone ?? null,
    openedAt: event.createdAt,
  };
}
```

Answer `200` first, then call your helpdesk from a queue: a helpdesk that is slow to answer
must not make the delivery time out.

## 4. Follow the conversation [#4-follow-the-conversation]

* [`conversation.assigned`](/webhooks/events/conversation-assigned/) fires when a team
  member assigns, reassigns or unassigns it; `data.assignee` is `null` when unassigned.
* [`conversation.resolved`](/webhooks/events/conversation-resolved/) fires when a team
  member resolves or closes it. Close the ticket then. A bulk close sends only the
  conversation `id`, so key tickets on it.

Your team answers the customer from the RevoplyAI inbox.
