telnyx-voice-streaming-go

📁 team-telnyx/telnyx-ext-agent-skills 📅 Today
3
总安装量
1
周安装量
#58449
全站排名
安装命令
npx skills add https://github.com/team-telnyx/telnyx-ext-agent-skills --skill telnyx-voice-streaming-go

Agent 安装分布

windsurf 1
amp 1
opencode 1
cursor 1
kimi-cli 1
kiro-cli 1

Skill 文档

Telnyx Voice Streaming – Go

Installation

go get github.com/team-telnyx/telnyx-go

Setup

import (
  "context"
  "fmt"
  "os"

  "github.com/team-telnyx/telnyx-go"
  "github.com/team-telnyx/telnyx-go/option"
)

client := telnyx.NewClient(
  option.WithAPIKey(os.Getenv("TELNYX_API_KEY")),
)

All examples below assume client is already initialized as shown above.

Forking start

Call forking allows you to stream the media from a call to a specific target in realtime.

POST /calls/{call_control_id}/actions/fork_start

Optional: client_state (string), command_id (string), rx (string), stream_type (enum), tx (string)

	response, err := client.Calls.Actions.StartForking(
		context.TODO(),
		"call_control_id",
		telnyx.CallActionStartForkingParams{},
	)
	if err != nil {
		panic(err.Error())
	}
	fmt.Printf("%+v\n", response.Data)

Forking stop

Stop forking a call.

POST /calls/{call_control_id}/actions/fork_stop

Optional: client_state (string), command_id (string), stream_type (enum)

	response, err := client.Calls.Actions.StopForking(
		context.TODO(),
		"call_control_id",
		telnyx.CallActionStopForkingParams{},
	)
	if err != nil {
		panic(err.Error())
	}
	fmt.Printf("%+v\n", response.Data)

Streaming start

Start streaming the media from a call to a specific WebSocket address or Dialogflow connection in near-realtime.

POST /calls/{call_control_id}/actions/streaming_start

Optional: client_state (string), command_id (string), custom_parameters (array[object]), dialogflow_config (object), enable_dialogflow (boolean), stream_auth_token (string), stream_bidirectional_codec (enum), stream_bidirectional_mode (enum), stream_bidirectional_sampling_rate (enum), stream_bidirectional_target_legs (enum), stream_codec (enum), stream_track (enum), stream_url (string)

	response, err := client.Calls.Actions.StartStreaming(
		context.TODO(),
		"call_control_id",
		telnyx.CallActionStartStreamingParams{},
	)
	if err != nil {
		panic(err.Error())
	}
	fmt.Printf("%+v\n", response.Data)

Streaming stop

Stop streaming a call to a WebSocket.

POST /calls/{call_control_id}/actions/streaming_stop

Optional: client_state (string), command_id (string), stream_id (uuid)

	response, err := client.Calls.Actions.StopStreaming(
		context.TODO(),
		"call_control_id",
		telnyx.CallActionStopStreamingParams{},
	)
	if err != nil {
		panic(err.Error())
	}
	fmt.Printf("%+v\n", response.Data)

Transcription start

Start real-time transcription.

POST /calls/{call_control_id}/actions/transcription_start

Optional: client_state (string), command_id (string), transcription_engine (enum), transcription_engine_config (object), transcription_tracks (string)

	response, err := client.Calls.Actions.StartTranscription(
		context.TODO(),
		"call_control_id",
		telnyx.CallActionStartTranscriptionParams{
			TranscriptionStartRequest: telnyx.TranscriptionStartRequestParam{},
		},
	)
	if err != nil {
		panic(err.Error())
	}
	fmt.Printf("%+v\n", response.Data)

Transcription stop

Stop real-time transcription.

POST /calls/{call_control_id}/actions/transcription_stop

Optional: client_state (string), command_id (string)

	response, err := client.Calls.Actions.StopTranscription(
		context.TODO(),
		"call_control_id",
		telnyx.CallActionStopTranscriptionParams{},
	)
	if err != nil {
		panic(err.Error())
	}
	fmt.Printf("%+v\n", response.Data)

Webhooks

The following webhook events are sent to your configured webhook URL. All webhooks include telnyx-timestamp and telnyx-signature-ed25519 headers for verification (Standard Webhooks compatible).

Event Description
callForkStarted Call Fork Started
callForkStopped Call Fork Stopped
callStreamingStarted Call Streaming Started
callStreamingStopped Call Streaming Stopped
callStreamingFailed Call Streaming Failed
transcription Transcription

Webhook payload fields

callForkStarted

Field Type Description
data.record_type enum Identifies the type of the resource.
data.event_type enum The type of event being delivered.
data.id uuid Identifies the type of resource.
data.occurred_at date-time ISO 8601 datetime of when the event occurred.
data.payload.connection_id string Call Control App ID (formerly Telnyx connection ID) used in the call.
data.payload.call_control_id string Unique ID for controlling the call.
data.payload.call_leg_id string ID that is unique to the call and can be used to correlate webhook events.
data.payload.call_session_id string ID that is unique to the call session and can be used to correlate webhook events.
data.payload.client_state string State received from a command.
data.payload.stream_type enum Type of media streamed.

callForkStopped

Field Type Description
data.record_type enum Identifies the type of the resource.
data.event_type enum The type of event being delivered.
data.id uuid Identifies the type of resource.
data.occurred_at date-time ISO 8601 datetime of when the event occurred.
data.payload.connection_id string Call Control App ID (formerly Telnyx connection ID) used in the call.
data.payload.call_control_id string Unique ID for controlling the call.
data.payload.call_leg_id string ID that is unique to the call and can be used to correlate webhook events.
data.payload.call_session_id string ID that is unique to the call session and can be used to correlate webhook events.
data.payload.client_state string State received from a command.
data.payload.stream_type enum Type of media streamed.

callStreamingStarted

Field Type Description
data.record_type enum Identifies the type of the resource.
data.event_type enum The type of event being delivered.
data.id uuid Identifies the type of resource.
data.occurred_at date-time ISO 8601 datetime of when the event occurred.
data.payload.call_control_id string Call ID used to issue commands via Call Control API.
data.payload.connection_id string Call Control App ID (formerly Telnyx connection ID) used in the call.
data.payload.call_leg_id string ID that is unique to the call and can be used to correlate webhook events.
data.payload.call_session_id string ID that is unique to the call session and can be used to correlate webhook events.
data.payload.client_state string State received from a command.
data.payload.stream_url string Destination WebSocket address where the stream is going to be delivered.

callStreamingStopped

Field Type Description
data.record_type enum Identifies the type of the resource.
data.event_type enum The type of event being delivered.
data.id uuid Identifies the type of resource.
data.occurred_at date-time ISO 8601 datetime of when the event occurred.
data.payload.call_control_id string Call ID used to issue commands via Call Control API.
data.payload.connection_id string Call Control App ID (formerly Telnyx connection ID) used in the call.
data.payload.call_leg_id string ID that is unique to the call and can be used to correlate webhook events.
data.payload.call_session_id string ID that is unique to the call session and can be used to correlate webhook events.
data.payload.client_state string State received from a command.
data.payload.stream_url string Destination WebSocket address where the stream is going to be delivered.

callStreamingFailed

Field Type Description
data.record_type enum Identifies the resource.
data.event_type enum The type of event being delivered.
data.id uuid Identifies the type of resource.
data.occurred_at date-time ISO 8601 datetime of when the event occurred.
data.payload.call_control_id string Call ID used to issue commands via Call Control API.
data.payload.connection_id string Call Control App ID (formerly Telnyx connection ID) used in the call.
data.payload.call_leg_id string ID that is unique to the call and can be used to correlate webhook events.
data.payload.call_session_id string ID that is unique to the call session and can be used to correlate webhook events.
data.payload.client_state string State received from a command.
data.payload.failure_reason string A short description explaning why the media streaming failed.
data.payload.stream_id uuid Identifies the streaming.
data.payload.stream_type enum The type of stream connection the stream is performing.

transcription

Field Type Description
data.record_type enum Identifies the type of the resource.
data.event_type enum The type of event being delivered.
data.id uuid Identifies the type of resource.
data.occurred_at date-time ISO 8601 datetime of when the event occurred.
data.payload.call_control_id string Unique identifier and token for controlling the call.
data.payload.call_leg_id string ID that is unique to the call and can be used to correlate webhook events.
data.payload.call_session_id string ID that is unique to the call session and can be used to correlate webhook events.
data.payload.client_state string Use this field to add state to every subsequent webhook.
data.payload.connection_id string Call Control App ID (formerly Telnyx connection ID) used in the call.