VAPI-3989: map Twilio Stream <Parameter> children to StreamParam - #28
Open
mramasubramanian-bw wants to merge 1 commit into
Open
mramasubramanian-bw wants to merge 1 commit into
mramasubramanian-bw wants to merge 1 commit into
Conversation
Twilio bots attach key/value context to a media stream with <Parameter>
children on <Stream>; that is how most bots receive callSid, tenant, and
similar values when the WebSocket opens. The translator read only the
<Stream> attributes and ignored its children, so a Stream with two
Parameters produced byte-identical BXML to one with none, no finding was
raised, and the bot connected with an empty customParameters map.
Translator:
- Each <Parameter name value/> becomes a nested <StreamParam name value/>
under the emitted <StartStream>, in order, for both Connect (bidirectional)
and Start (fork) streams. Attribute values are XML-escaped by the builder.
- Bandwidth allows at most 12 StreamParam per StartStream; extras are
dropped with a Stream warning naming the count. Twilio caps name+value at
500 chars combined, so Bandwidth's 256/2048 per-attribute limits cannot
be exceeded by valid TwiML and are not re-checked.
- A <Parameter> missing name or value, or any non-Parameter child, is
dropped with a warning instead of emitting BXML Bandwidth would reject.
Bridge:
- Add customParametersFromBwStart(), which maps Bandwidth's StartStream
"start" event (streamParams: flat name->value map) to the Twilio
customParameters map the bridge already forwards in its own "start"
message. Values are coerced to strings; malformed input yields {}.
Wiring a live Bandwidth source that calls it is VAPI-3991.
Docs: update the Stream matrix note and AGENTS.md. Tests cover ordering,
nesting inside StartStream, the fork case, escaping, the 12 cap, invalid
Parameters, unknown children, and the bridge mapper end to end.
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Twilio bots attach key/value context to a media stream with
<Parameter>children on<Stream>. That is how most bots receivecallSid, tenant, and similar values when the WebSocket opens. The translator read only the<Stream>attributes and ignored its children, so a Stream with two Parameters produced byte-identical BXML to one with none, no finding was raised, and the bot connected with an emptycustomParametersmap.Each
<Parameter name value/>now becomes a nested<StreamParam name value/>under the emitted<StartStream>, in order. Bandwidth echoes those in its WebSocketstartevent asstreamParams, and a new bridge helper maps that to the TwiliocustomParametersthe bot expects.Changes
Translator (
src/translator/translate.ts)<Parameter>children map to nested<StreamParam/>for both Connect (bidirectional) and Start (fork) streams. Values are XML-escaped by the builder.StreamParamperStartStream. Extras are dropped with a Stream warning that names the count. Twilio caps name plus value at 500 characters combined, so Bandwidth's 256 / 2048 per-attribute limits cannot be exceeded by valid TwiML and are not re-checked.<Parameter>missingnameorvalue, or any non-Parameter child, is dropped with a warning instead of emitting BXML Bandwidth would reject.Bridge (
src/streams/bridge.ts)customParametersFromBwStart()maps Bandwidth'sstartevent (streamParams, a flat name to value map) to the TwiliocustomParametersmap the bridge already forwards in its ownstartmessage. Values are coerced to strings and malformed input yields an empty object.Docs: Stream matrix note and
AGENTS.md.Before / after
Input:
Before:
After:
Verification
npm run typecheck && npx vitest run: 44 files, 315 passed, 6 skipped.test/translate-stream-conference.test.tscover ordering, nesting inside StartStream, the fork case, escaping, the 12 cap, invalid Parameters, and unknown children.test/streams-wire.test.tspush a Bandwidth-shapedstartevent through the mapper and assert the bot receives it ascustomParameters.Reference: StartStream docs, StreamParam.