---
title: "Plivo Voice Agent in Node.js with Audio Streaming | Micdrop"
description: "Answer Plivo phone calls with a Micdrop voice agent, over a bidirectional audio stream: the XML that starts it, the transport, and the hang up."
url: "https://micdrop.dev/docs/transports/plivo"
---

# Plivo Voice Agent in Node.js with Audio Streaming

`PlivoTransport` runs a Micdrop call on a bidirectional [Plivo audio stream](https://www.plivo.com/docs/voice-agents/audio-streaming/concepts/audio-streaming-reference). The caller arrives in μ-law at 8 kHz, and the assistant goes back the same way. Read [phone calls](/docs/transports/telephony) first for what every provider shares.

## Answer the call

Set the answer URL of your Plivo application to a route that answers with the XML of `plivoStreamXml`:

```typescript
import { plivoStreamXml } from '@micdrop/telephony'

app.post('/plivo/answer', async (request, reply) => {
  reply.type('text/xml')
  return plivoStreamXml({
    url: 'wss://example.com/plivo/stream',
    parameters: { lang: 'en' },
  })
})
```

The parameters travel as the extra headers of the stream. Plivo accepts only letters and digits in them, 512 bytes in all, so keep them to identifiers and look the rest up on your server.

## Run the stream

```typescript
import { MicdropServer, waitForParams } from '@micdrop/server'
import { PlivoTransport } from '@micdrop/telephony'
import '@micdrop/vad/node'

app.get('/plivo/stream', { websocket: true }, async (socket) => {
  const transport = new PlivoTransport(socket, {
    authId: process.env.PLIVO_AUTH_ID,
    authToken: process.env.PLIVO_AUTH_TOKEN,
  })
  const { lang } = await waitForParams(transport, (params) => params)

  new MicdropServer(transport, {
    vad: 'silero',
    firstMessage: 'Hello, thanks for calling. How can I help?',
    agent,
    stt,
    tts,
  })
})
```

## Hanging up

The XML of `plivoStreamXml` sets `keepCallAlive`, so the stream runs alone and Plivo moves on once it closes. With nothing after it, the call ends. When the agent ends the call, the transport sends a checkpoint after the goodbye and closes once Plivo confirms it played. Given your `authId` and `authToken`, it also hangs up through the API, which ends the call whatever the XML says after the stream.

## Security

Plivo signs the WebSocket request with the `X-Plivo-Signature-V3` and `X-Plivo-Signature-V3-Nonce` headers. Check them with the Plivo SDK before accepting the stream.
