AgentSkillsCN

telnyx-voice-gather-python

通过呼叫控制功能进行呼入呼出、转接、桥接,并管理通话生命周期。包含应用管理和通话事件。本技能提供 JavaScript SDK 示例。

SKILL.md
--- frontmatter
name: telnyx-voice-gather-python
description: >-
  Collect DTMF input and speech from callers using standard gather or AI-powered
  gather. Build interactive voice menus and AI voice assistants. This skill
  provides Python SDK examples.
metadata:
  author: telnyx
  product: voice-gather
  language: python

Telnyx Voice Gather - Python

Installation

bash
pip install telnyx

Setup

python
import os
from telnyx import Telnyx

client = Telnyx(
    api_key=os.environ.get("TELNYX_API_KEY"),  # This is the default and can be omitted
)

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

Add messages to AI Assistant

Add messages to the conversation started by an AI assistant on the call.

POST /calls/{call_control_id}/actions/ai_assistant_add_messages

python
response = client.calls.actions.add_ai_assistant_messages(
    call_control_id="call_control_id",
)
print(response.data)

Start AI Assistant

Start an AI assistant on the call.

POST /calls/{call_control_id}/actions/ai_assistant_start

python
response = client.calls.actions.start_ai_assistant(
    call_control_id="call_control_id",
)
print(response.data)

Stop AI Assistant

Stop an AI assistant on the call.

POST /calls/{call_control_id}/actions/ai_assistant_stop

python
response = client.calls.actions.stop_ai_assistant(
    call_control_id="call_control_id",
)
print(response.data)

Gather stop

Stop current gather.

POST /calls/{call_control_id}/actions/gather_stop

python
response = client.calls.actions.stop_gather(
    call_control_id="call_control_id",
)
print(response.data)

Gather using AI

Gather parameters defined in the request payload using a voice assistant.

POST /calls/{call_control_id}/actions/gather_using_ai — Required: parameters

python
response = client.calls.actions.gather_using_ai(
    call_control_id="call_control_id",
    parameters={
        "properties": "bar",
        "required": "bar",
        "type": "bar",
    },
)
print(response.data)

Gather using audio

Play an audio file on the call until the required DTMF signals are gathered to build interactive menus.

POST /calls/{call_control_id}/actions/gather_using_audio

python
response = client.calls.actions.gather_using_audio(
    call_control_id="call_control_id",
)
print(response.data)

Gather using speak

Convert text to speech and play it on the call until the required DTMF signals are gathered to build interactive menus.

POST /calls/{call_control_id}/actions/gather_using_speak — Required: voice, payload

python
response = client.calls.actions.gather_using_speak(
    call_control_id="call_control_id",
    payload="say this on call",
    voice="male",
)
print(response.data)

Gather

Gather DTMF signals to build interactive menus.

POST /calls/{call_control_id}/actions/gather

python
response = client.calls.actions.gather(
    call_control_id="call_control_id",
)
print(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).

EventDescription
callGatherEndedCall Gather Ended
CallAIGatherEndedCall AI Gather Ended
CallAIGatherMessageHistoryUpdatedCall AI Gather Message History Updated
CallAIGatherPartialResultsCall AI Gather Partial Results
CallConversationEndedCall Conversation Ended
callPlaybackStartedCall Playback Started
callPlaybackEndedCall Playback Ended
callDtmfReceivedCall Dtmf Received