//native
type Telnyx = {
apiKey: string
}
/**
* Streaming start
* Start streaming the media from a call to a specific WebSocket address or Dialogflow connection in near-realtime. Audio will be delivered as base64-encoded RTP payload (raw audio), wrapped in JSON payloads.
Please find more details about media streaming messages specification under the [link](https://developers.telnyx.com/docs/voice/programmable-voice/media-streaming).
*/
export async function main(
auth: Telnyx,
call_control_id: string,
body: {
stream_url?: string
stream_track?: 'inbound_track' | 'outbound_track' | 'both_tracks'
stream_bidirectional_mode?: 'mp3' | 'rtp'
stream_bidirectional_codec?: 'PCMU' | 'PCMA' | 'G722'
stream_bidirectional_target_legs?: 'both' | 'self' | 'opposite'
enable_dialogflow?: false | true
dialogflow_config?: {
analyze_sentiment?: false | true
partial_automated_agent_reply?: false | true
}
client_state?: string
command_id?: string
}
) {
const url = new URL(`https://api.telnyx.com/v2/calls/${call_control_id}/actions/streaming_start`)
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: 'Bearer ' + auth.apiKey
},
body: JSON.stringify(body)
})
if (!response.ok) {
const text = await response.text()
throw new Error(`${response.status} ${text}`)
}
return await response.json()
}
Submitted by hugo697 428 days ago