Vonage / vonage-python-sdk

Vonage Server SDK for Python. API support for Voice, SMS, WhatsApp, Verify (2FA), Video Meetings and more.
https://developer.vonage.com
Apache License 2.0
185 stars 112 forks source link

fix: change ncco websocket endpoint contentType to content-type #292

Closed rhbuckley closed 2 months ago

rhbuckley commented 5 months ago

When using the NCCO builder to create a Websocket Connect Endpoint, it serializes to have a field 'contentType', whilst the API expects a field of 'content-type'

Expected Behavior

{ "content-type": "...." }

Current Behavior

{ "contentType": "...." }

Possible Solution

Code

# Where BITRATE=16, and FREQUENCY=16000
ws = ConnectEndpoints.WebsocketEndpoint(
    uri=some_url,
    contentType=f"audio/l{StreamingConfig.BITRATE};rate={StreamingConfig.FREQUENCY}"
)

c = Ncco.Connect(endpoint=ws, eventType="synchronous")
ncco = Ncco.build_ncco(c)
print(json.dumps(ncco, indent=4))

Response to Voice API

[
    {
        "action": "connect",
        "endpoint": [
            {
                "type": "websocket",
                "uri": "wss://***.ngrok-free.app/ws",
                "contentType": "audio/l16;rate=8000"
            }
        ],
        "eventType": "synchronous"
    }
]

Websocket Connected Message

{
    "content-type": "audio/l16;rate=16000",
    "event": "websocket:connected"
}

After Applying Fix

{
    "content-type": "audio/l16;rate=8000",
    "event": "websocket:connected"
}

Your Environment