31951: Stream - Protocol - Invalid Message
VOICE
WARNING
Twilio sends warning 31951 once per Stream when your WebSocket server sends a message that does not comply with the Media Streams protocol. For bidirectional Streams, Twilio only accepts the documented media, mark, and clear message types, and each message must include the expected fields for that event.
- The message was not valid JSON.
- The message used an unsupported event type. Twilio only accepts
media,mark, andclearmessages from your server on a bidirectional Stream. - The message was missing required fields, included unexpected fields, or used the wrong object structure for the selected event.
- The
streamSidin the message did not match the active Stream.
- Serialize each outbound message as valid JSON before you send it over the WebSocket connection.
- If you need to send messages back to Twilio, use
<Connect><Stream>and send only the supportedmedia,mark, andclearevents. - Validate each message against the documented schema before sending it. Include
event,streamSid, and the correct event payload object for that message type. - Use the
streamSidfrom Twilio'sstartmessage for the current Stream, and do not reuse a SID from another call or stream.