Skip to main content

A proxy that redirects Twilio SDK calls to Telnyx's API

Project description

Twilnyx

A proxy that redirects Twilio SDK calls to use Telnyx's API. Keep using your existing Twilio code and webhook server - just add two lines to use Telnyx instead!

Installation

pip install twilnyx

Usage

Your existing Twilio code:

from twilio.rest import Client

client = Client('TWILIO_ACCOUNT_SID', 'TWILIO_AUTH_TOKEN')

call = client.calls.create(
    url='https://your-server.com/voice',  # Your webhook server
    to='+1234567890',
    from_='+1987654321'
)

To use Telnyx instead, just add:

# Add these two lines at the start of your code
import twilnyx
twilnyx.use_telnyx(
    api_key='YOUR_TELNYX_API_KEY',
    voice_profile_id='YOUR_VOICE_PROFILE_ID',  # From Telnyx Portal > Voice > API Profiles
    connection_id='YOUR_CONNECTION_ID',  # From Telnyx Portal > Call Control > Apps
    debug=False  # Set to True for detailed logging
)

# Then use your existing Twilio code as-is!
from twilio.rest import Client
...

How It Works

  1. Basic Flow:

    Your Code -> Twilio SDK -> Twilnyx Proxy -> Telnyx API
                                     |
                                     v
                              Parameter Mapping
                              Add Voice Profile
                              Convert Response
    
  2. Complete Flow:

    +-------------+    +------------+    +-------------+    +-----------+
    |  Your Code  |    |Twilio SDK |    |Twilnyx Proxy|    |Telnyx API |
    |             |--->|           |--->|             |--->|           |
    +-------------+    +------------+    +-------------+    +-----------+
                                             |
                                             v
                                     +---------------+
                                     | Map Params    |
                                     | Add Profile   |
                                     | Map Response  |
                                     +---------------+
    
  3. Webhook Flow:

    +-------------+    +------------+    +------------+
    |  Your App   |    |Telnyx API |    |Your Server |
    |client.calls |    |           |    |  /voice    |
    |             |--->|           |--->|            |
    |             |    |           |    |            |
    |             |    |           |<---|   TwiML    |
    +-------------+    +------------+    +------------+
    
  4. Parameter Mapping:

    # Twilio format
    {
        'To': '+1234567890',
        'From': '+1987654321',
        'Url': 'https://your-server.com/voice'
    }
    
    # Converted to Telnyx format
    {
        'to': '+1234567890',
        'from': '+1987654321',
        'webhook_url': 'https://your-server.com/voice',
        'voice_profile_id': 'your_profile_id'  # Added automatically
    }
    
  5. Response Conversion:

    # Telnyx response
    {
        'call_control_id': 'xyz',
        'state': 'ringing'
    }
    
    # Converted to Twilio format
    {
        'sid': 'xyz',
        'status': 'ringing'
    }
    

Required Setup

  1. Telnyx API Key (Required):

    • Create in Telnyx Portal > Auth > API Keys
    • Used for authentication with Telnyx API
    • Pass to use_telnyx() as api_key
  2. Telnyx Voice Profile (Required):

    • Create in Telnyx Portal > Voice > API Profiles
    • Used for outbound calling configuration
    • Pass the ID to use_telnyx() as voice_profile_id
  3. Telnyx Call Control App (Required for calls):

    • Create in Telnyx Portal > Call Control > Apps
    • Configure with your webhook URL
    • Pass the ID to use_telnyx() as connection_id
  4. Your Webhook Server:

    • Keep using your existing webhook server
    • It should return TwiML just like with Twilio
    • No changes needed to your webhooks

Features

  • Uses your existing Twilio code
  • Uses your existing webhook server
  • No code changes needed
  • Automatic parameter mapping
  • Proper response conversion
  • Detailed logging for debugging
  • Support for calls and messages
  • Error handling and reporting

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

twilnyx-0.2.0.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

twilnyx-0.2.0-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file twilnyx-0.2.0.tar.gz.

File metadata

  • Download URL: twilnyx-0.2.0.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.22

File hashes

Hashes for twilnyx-0.2.0.tar.gz
Algorithm Hash digest
SHA256 a2bba55f24f57db64dca47c7b49d3d292b14873f58a94ba0bade0472b2c6fa0d
MD5 550b80ff21d44a18314361d8c05a8c86
BLAKE2b-256 31a83b2f96fe0fd7dc9ec0fc313ca940534e0adbc69ce16a5a44765a62676365

See more details on using hashes here.

File details

Details for the file twilnyx-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: twilnyx-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.22

File hashes

Hashes for twilnyx-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ce3c3d30396a5b20faa7a52d9cfe8b9e0394f2221e46ff667a8e0fc73388fb29
MD5 c62dbfa1c21a9583963373cd329a2118
BLAKE2b-256 e6a8edac6e349852f8bea16a94f77743fb3b110fe022f22c21a03242ed9fec09

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page