# Telnyx Integration

> Configure Telnyx for voice communication in Menace Voice

## What you need

- A [Telnyx account](https://telnyx.com/).
- One Telnyx number with Voice capability.
- A Telnyx **API Key**.
- A Call Control Application. Menace Voice can create this for you.

## Estimated price

Telnyx lists local and toll-free numbers from **$1 per month**, plus usage,
carrier passthrough fees, and taxes. Your cart shows the actual upfront and
monthly cost before you place the order. Check [current Telnyx number pricing](https://telnyx.com/pricing/numbers).

## Set up Telnyx step by step

### 1. Buy a number

1. Sign in to the [Mission Control Portal](https://portal.telnyx.com/).
2. Open **Numbers → My Numbers**, then click **Buy Number**.
3. Choose a country, select the capabilities you need, and choose a local or
   toll-free number type.
4. Add a number to the cart. Review both **Upfront Cost** and **Monthly Cost**.
5. Place the order and complete any requested regulatory documents.

See Telnyx's current [Search and Buy Numbers guide](https://support.telnyx.com/en/articles/4380325-search-and-buy-numbers).

### 2. Create an API key

1. In Mission Control, open **API Keys & Credentials**.
2. Create or copy an API key and store it securely.
3. Copy the **Public Key** on the same page. Menace Voice uses this optional
   value to verify that webhooks really came from Telnyx.

### 3. Connect Telnyx in Menace Voice

1. Open **Phone numbers** and click **Add phone number**.
2. Choose **Telnyx**, then continue.
3. Paste the **API Key** and, when available, the **Webhook Public Key**.
4. Leave **Call Control App ID** blank unless you already created a dedicated
   Call Control Application. Menace Voice creates one and stores its ID when
   the field is blank.
5. Enter your purchased number with its country code.
6. Choose an agent for incoming calls and finish setup.

### 4. Assign the number to the application

If Menace Voice created the application, return to **Numbers → My Numbers** in
Telnyx and assign the number to the new application named `dograh-<random>`.
Telnyx documents number assignment on its [My Numbers page](https://support.telnyx.com/en/articles/4349113-my-numbers-page).

### 5. Test the number

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

## Inbound Calling Setup

Telnyx delivers inbound webhooks at the **Call Control Application** level — the webhook URL is configured once on the application, and applies to every number assigned to it. **When you save an inbound workflow on a phone number, Menace Voice automatically pushes the webhook URL to your Call Control Application's `webhook_event_url`** (provided the credentials are correct). If Menace Voice auto-created the application during configuration save, the webhook URL is already set and this step is a no-op.

### Step 1: Assign an Inbound Workflow to the Phone Number

1. Go to **/telephony-configurations** and open your Telnyx 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 2: Verify the Webhook URL on the Call Control Application

1. Go to **Call Control** → **Applications** in the Telnyx Portal
2. Open the application whose Connection ID you configured in Menace Voice
3. In **Webhook Settings**, confirm:
   - **Webhook URL** is set to: `https://voice.menaceui.com/api/v1/telephony/inbound/run`
   - **HTTP Method** is `POST`
4. Make sure the phone numbers you want to use for inbound are assigned to this application

   <Note>
     Menace Voice pushed this URL automatically when you saved the inbound workflow
     in Step 1. The same URL is shared across every number on the Call
     Control Application — Menace Voice matches the inbound call to the right
     agent using 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 API
     Key or Connection ID in Menace Voice is incorrect. Paste the URL into the
     field yourself, set the method to `POST`, and save. On self-hosted
     Menace Voice, replace `voice.menaceui.com` with your backend domain.
   </Note>

### Step 3: Verify Setup

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

### Test Inbound Calling

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

## 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 the API Key is correct and active - Check for extra spaces in the
    key - Ensure the key hasn't been revoked in the Telnyx Portal
  </Accordion>

  <Accordion title="Webhook signature validation failing">
    - Telnyx signs webhooks with Ed25519 - confirm the public key on the
    application hasn't changed - Verify the webhook URL matches what Telnyx
    sends - Check if you're behind a proxy that modifies request bodies
  </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 aren't answered">
    - Verify the Call Control Application's webhook URL is set to
    `https://voice.menaceui.com/api/v1/telephony/inbound/run` - Ensure the webhook
    URL is publicly accessible from the internet - Confirm the called number
    is assigned to the same Call Control Application whose Connection ID is
    configured in Menace Voice - Confirm the called number exists in your Menace Voice
    telephony configuration and has an **Inbound workflow** assigned - 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 - Verify the API Key matches the one stored in
    your Menace Voice telephony configuration - 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 the Telnyx Portal for usage and billing
- Use a dedicated Call Control Application for Menace Voice so the shared webhook URL doesn't conflict with other systems
