Skip to main content
The agent answers your number, works out who the caller needs, and passes the call to a person on your team. On your own Plivo account you can make that handover yourself: Plivo transfers the call, and Mirai leaves it. Once Mirai releases the call, the agent stops speaking and listening, recording and transcription stop, and Mirai’s billing ends. The caller stays on the line, and the rest of the call is between your Plivo account and your team.
This is for numbers on your own Plivo account. On a number rented through Mirai, or on a SIP trunk, use a live human takeover: Mirai rings the person and joins them to the caller.

What you’ll build

  • A webhook tool, transfer_to_team, that the agent calls once it knows which team the caller needs.
  • A handler on your server that starts a Plivo transfer to that team and then releases the call from Mirai.

How it works

  1. A caller rings your Plivo number. Mirai’s agent answers on an audio stream that Plivo keeps the call on.
  2. The agent finds out what the caller needs and calls transfer_to_team.
  3. Your server asks Plivo to transfer the call to your own XML, for example a <Dial> to the team’s number. Plivo holds the transfer while Mirai’s stream is still on the call.
  4. Your server releases the call with POST /v2/calls/{id}/release. Mirai stops its stream and never hangs up. Plivo then runs your transfer.
  5. The call ends in Mirai as completed with ended_reason: "released". Your call.completed webhook and post-call analysis arrive as for any call.

Step 1: Give the agent a transfer tool

Add a webhook tool that sends your server the call id, the caller’s number, your number and the team. The agent’s prompt tells it when to call the tool, for example once the caller has said which team and agreed to hold.
transfer-to-team.json
Save it on the agent with PUT /v2/agents/{agent_id}/tools/transfer_to_team, as in Tools. Have the agent tell the caller it is putting them through before it calls the tool. Once the call is released, the agent says nothing more.

Step 2: Start the Plivo transfer, then release

Your handler does two things, in this order. First, start the transfer on Plivo. Find the live call on your Plivo account with the two numbers, then transfer it to your XML:
The XML at aleg_url is yours, for example:
Then release the call from Mirai:
202 Accepted
Mirai stops its audio stream on the call and leaves it. Plivo runs your transfer straight away. Answer the agent’s tool call with a short result, such as { "ok": true }. The agent doesn’t speak after the release.
Releasing first and transferring a moment later also works. After Mirai’s stream ends, the call waits 15 seconds before it hangs up, and a Plivo transfer in that time takes the caller. Transfer first if you can: the caller then hears no gap at all.

Stopping the stream yourself

If your server already stops Mirai’s audio stream with Plivo (DELETE /v1/Account/{auth_id}/Call/{call_uuid}/Stream/) after starting the transfer, Mirai doesn’t hang up either. The call is recorded as released at that moment, with billing ending there too. POST /release does the same thing in one call and confirms it.

Step 3: Read the result

The released call is an ordinary completed call:
  • status: "completed", ended_reason: "released".
  • duration_secs and the charge run from when the call was answered to the release.
  • The transcript and recording cover the conversation with the agent, up to the release. The rest of the call isn’t recorded by Mirai.
  • call.completed fires, and post-call analysis runs on the agent’s part of the conversation.

Errors

A release you repeat for a call that is already released answers the same 202.

Privacy and compliance

  • Tell callers they are being transferred, and that the call with the agent is recorded and transcribed, if your rules require it.
  • After the release, Mirai holds no audio from the call. Recording the rest of it is up to your Plivo setup.

Calls API

Release, abort and read a call.

Live human takeover

Hand a call to a person on any number: Mirai rings them and joins them in.

Receive inbound calls

Connect your own Plivo number and assign an agent.

Tools

Webhook tools the agent calls during a call.