🎤Micdrop

Transfer a Phone Call to a Person, Cold or Warm

transferCallTool() lets the agent hand a phone call to a person or another line. The assistant says it transfers the caller, then the transport sends the call through the API of its provider and leaves.

import { endCallTool, MicdropServer } from '@micdrop/server'
import { transferCallTool, TwilioTransport } from '@micdrop/telephony'
const transport = new TwilioTransport(socket, {
accountSid: process.env.TWILIO_ACCOUNT_SID,
authToken: process.env.TWILIO_AUTH_TOKEN,
})
new MicdropServer(transport, {
turns: { vad: 'silero' },
agent: new OpenaiAgent({
apiKey,
systemPrompt: 'You answer the phone for Acme...',
tools: [endCallTool(), transferCallTool({ to: '+14155550100' })],
}),
stt,
tts,
})

The transfer waits for the answer that announces it to be played, so the caller hears “I’m transferring you to a colleague” before the line moves. The call transfer tutorial builds a complete Twilio receptionist around it.

Cold and warm transfers

ModeWhat happens
cold, the defaultThe call goes to the number at once, and the assistant leaves
warmThe assistant asks the caller to hold and calls the person. Once they pick up, they hear a summary of the call, then the caller joins them

In warm mode, the model writes the summary as a parameter of the tool: who calls and what for. The voice of the provider reads it to the person before the caller joins, so they start the conversation knowing the case.

transferCallTool({ to: '+14155550100', mode: 'warm' })

While the phone rings, the caller stays on the line with the assistant. When nobody picks up, the line is busy or the person hangs up before joining, the assistant keeps the call and the model hears why, so it can tell the caller and offer another way to help.

Several destinations

With destinations, the model picks one by name, guided by its description:

transferCallTool({
destinations: [
{ name: 'sales', to: '+14155550100', description: 'to buy or upgrade a plan' },
{ name: 'support', to: '+14155550199', description: 'for a problem with the service' },
{ name: 'desk', to: 'sip:desk@pbx.example.com' },
],
})

A destination is a phone number in E.164 format or a SIP URI. Anything else throws when the tool is created, so a typo shows at startup rather than during a call.

Options

OptionDescription
toThe one destination
destinationsDestinations the model picks from, by name, with an optional description
modecold (default) or warm
fromNumber the person reached sees, one of your account
timeoutHow long to let the phone ring, in seconds, 30 by default
nameName of the tool, transfer_call by default
descriptionTells the model when to transfer, in place of the default wording

By provider

Each transport transfers through the API of its provider, with the credentials it was given. A transport without them throws a clear error when the agent tries.

ProviderCredentialsColdWarm
TwilioaccountSid, authTokenUpdates the call with a <Dial>The person is called into a conference with a <Say> of the summary, then the caller joins it
VonageapplicationId, privateKeyMoves the call to a connect NCCOThe person is called into a named conversation after a talk of the summary, then the caller joins it
TelnyxapiKey, and connectionId for warmThe transfer command of Call ControlThe person is dialed, hears the summary with speak, then both calls are bridged
PlivoauthId, authToken, transferUrlTransfers the call to the XML of transferUrlNot available

Twilio

from defaults to the caller ID of the caller for a cold transfer, and to the number of your account on the call for a warm one. While the person hears the summary, the caller hears the hold music of Twilio, or the holdMusicUrl of the transport ('' for silence). If the person hangs up before joining, the caller hears transferFallbackTwiml, an apology and a hang up by default.

Vonage

from defaults to the number of your account on the call, which Vonage requires to be one of yours. The transport has to know the call, which vonageConnectNcco({ call }) or vonageCall() passes along. holdMusicUrl plays to the caller during the summary.

Telnyx

Telnyx reports the steps of a call (picked up, summary spoken, hung up) to the webhook of the application only. Hand its events to a TelephonyCalls, which routes them to the transport:

import { TelephonyCalls, TelnyxTransport } from '@micdrop/telephony'
const calls = new TelephonyCalls()
// The stream
calls.add(new TelnyxTransport(socket, { apiKey, connectionId }))
// The webhook of the Call Control application
app.post('/telnyx/webhook', async (request) => {
if (calls.telnyxWebhook(request.body)) return
// ... the events of your own application
})

briefingVoice and briefingLanguage choose the voice of the summary, AWS.Polly.Joanna-Neural by default.

Plivo

Plivo transfers a call only to an XML it fetches. Give the transport a transferUrl that points to a route of your server, which answers with plivoTransferXml():

const transport = new PlivoTransport(socket, {
authId,
authToken,
transferUrl: ({ to }) =>
`https://example.com/plivo/transfer?to=${encodeURIComponent(to)}`,
})
app.post('/plivo/transfer', async (request, reply) => {
reply.type('text/xml')
return plivoTransferXml({ to: request.query.to })
})

From your own code

The transport transfers without the tool too, for instance from a rule of your application:

await transport.transfer({ to: '+14155550100' })
const result = await transport.warmTransfer({
to: '+14155550100',
briefing: 'Jane Doe, about a refund on order 1234.',
})
if (!result.transferred) console.log(result.reason) // busy, no-answer...

The transport emits Transferred with the destination, and the call ends for Micdrop: MicdropServer emits End while the caller goes on talking with the person.