# Plivo Integration

> Configure Plivo for voice communication in Menace Voice

## What you need

- A [Plivo account](https://www.plivo.com/) with enough credit to rent a
  number.
- One Plivo number with Voice capability.
- The **Auth ID** and **Auth Token** shown in Plivo Console.
- A Plivo Application. Menace Voice can create this for you.

## Estimated price

Plivo lists US local numbers from **$0.50 per month** and US toll-free numbers
from **$1 per month**, plus call usage. Other countries and number types can
have different monthly and one-time setup fees. Confirm the live amount on
[Plivo Phone Number Pricing](https://www.plivo.com/phone-numbers/pricing/).

## Set up Plivo step by step

### 1. Buy a voice-capable number

1. Sign in to [Plivo Console](https://console.plivo.com/).
2. Open **Phone Numbers → Buy Numbers**.
3. Filter by country, number type, and **Voice** capability.
4. Select a number, review its charges, and click **Buy Number**.
5. Complete any country-specific compliance application Plivo requests.

See Plivo's official [Phone Numbers overview](https://docs.plivo.com/docs/numbers).

### 2. Copy your credentials

On the Plivo Console dashboard, copy the **Auth ID** and **Auth Token** for the
account that owns the number. Keep the Auth Token private.

### 3. Connect Plivo in Menace Voice

1. Open **Phone numbers** and click **Add phone number**.
2. Choose **Plivo** and continue.
3. Paste the **Auth ID** and **Auth Token**.
4. Leave **Application ID** blank unless you already have a dedicated Plivo
   Application. Menace Voice creates one with the correct answer URL when the
   field is blank.
5. Enter the purchased number with its country code.
6. Choose an agent for incoming calls and finish setup.

### 4. Link the number to the Plivo Application

In Plivo Console, open **Phone Numbers → Your Numbers**, select the number, and
assign it to the Application used by Menace Voice. If Menace Voice created the
Application, use the Application ID shown on the saved provider connection.

### 5. Test the number

Call the number from another phone and confirm the selected agent answers.
Then place one outbound test call before starting a campaign.

## Inbound Calling Setup

Plivo numbers don't carry an `answer_url` directly — the URL lives on a Plivo **Application**, and each number is linked to one application. **When you save an inbound workflow on a phone number, Menace Voice automatically pushes the webhook URL to your Plivo Application's `answer_url`** (provided the credentials are correct). You don't need to set the webhook by hand. If Menace Voice auto-created the application during configuration save, the `answer_url` is already set and this push is a no-op.

### Step 1: Link the Phone Number to Your Plivo Application

1. Go to **Phone Numbers** → **Your Numbers** in the [Plivo Console](https://console.plivo.com/)
2. Open the number you want to use for inbound calls
3. Set its **Application** to the same application whose ID you configured in Menace Voice
4. Save

### Step 2: Assign an Inbound Workflow to the Phone Number in Menace Voice

1. Go to **/telephony-configurations** and open your Plivo configuration
2. In the **Phone numbers** section, edit the number that should receive inbound calls
3. Set its **Inbound workflow** to the agent that should answer
4. Save

### Step 3: Verify the Answer URL on the Plivo Application

1. Open your Plivo Application in the [Plivo Console](https://console.plivo.com/) under **Voice** → **Applications**
2. Confirm:
   - **Answer URL** is set to: `https://voice.menaceui.com/api/v1/telephony/inbound/run`
   - **Answer Method** is `POST`

   <Note>
     Menace Voice pushed this URL automatically when you saved the inbound workflow
     in Step 2. The same URL is shared across every number linked to that
     application — Menace Voice routes each inbound call to the right agent based
     on the called number's inbound workflow assignment. If the field is
     empty, shows a different URL, or Menace Voice surfaced a sync warning on
     save, the auto-push failed — most often because the Auth ID/Token or
     Application ID in Menace Voice is incorrect. Paste the URL into the field
     yourself, set the method to `POST`, and save the application. On
     self-hosted Menace Voice, replace `voice.menaceui.com` with your backend domain.
   </Note>

### Step 4: Verify Setup

- Ensure your Menace Voice instance is publicly accessible
- Verify any firewalls allow Plivo's IP ranges

### Test Inbound Calling

1. Call your configured Plivo phone number from another phone
2. Verify your Menace Voice agent answers and responds
3. Check call logs in both Menace Voice dashboard and Plivo Console

## Troubleshooting

<AccordionGroup>
  <Accordion title="Invalid phone number error">
    Ensure phone numbers include country code in E.164 format: `+1234567890`
  </Accordion>

  <Accordion title="Authentication failed">
    - Verify Auth ID and Auth Token are correct - Check for extra spaces in
    credentials - Ensure credentials haven't been regenerated in Plivo Console
  </Accordion>

  <Accordion title="Webhook signature validation failing">
    - Confirm your Auth Token matches exactly - Verify the webhook URL matches
    what Plivo sends - Check if you're behind a proxy that modifies requests
  </Accordion>

  <Accordion title="No audio on calls">
    - Verify WebSocket connection is established - Check firewall rules for
    WebSocket traffic - Ensure audio pipeline is configured correctly
  </Accordion>

  <Accordion title="Inbound calls go to voicemail or aren't answered">
    - Verify the phone number is linked to the same Plivo Application whose
    ID you configured in Menace Voice - Confirm the called number exists in your
    Menace Voice telephony configuration and has an **Inbound workflow** assigned
    - After assigning the inbound workflow, confirm Menace Voice successfully
    updated the application's `answer_url` (no warning shown on save) -
    Verify Menace Voice instance is running and responding
  </Accordion>

  <Accordion title="Voice agent doesn't respond to inbound calls">
    - Confirm the phone number has an **Inbound workflow** assigned in
    /telephony-configurations - Check webhook signature validation is working
    (Auth Token in Menace Voice matches Plivo Console) - Verify WebSocket connection
    establishes successfully - Review call logs for error messages
  </Accordion>
</AccordionGroup>

## Best Practices

- Test your configuration with a single call before running campaigns
- Monitor Plivo Console for usage and billing
- Use a dedicated Plivo Application for Menace Voice so the shared `answer_url` doesn't conflict with other systems
