$npx -y skills add team-telnyx/ai --skill telnyx-ai-assistants-rubyAI voice assistants with custom instructions, knowledge bases, and tool integrations.
| 1 | <!-- Auto-generated from Telnyx OpenAPI specs. Do not edit. --> |
| 2 | |
| 3 | # Telnyx AI Assistants - Ruby |
| 4 | |
| 5 | ## Installation |
| 6 | |
| 7 | ```bash |
| 8 | gem install telnyx |
| 9 | ``` |
| 10 | |
| 11 | ## Setup |
| 12 | |
| 13 | ```ruby |
| 14 | require "telnyx" |
| 15 | |
| 16 | client = Telnyx::Client.new( |
| 17 | api_key: ENV["TELNYX_API_KEY"], # This is the default and can be omitted |
| 18 | ) |
| 19 | ``` |
| 20 | |
| 21 | All examples below assume `client` is already initialized as shown above. |
| 22 | |
| 23 | ## Error Handling |
| 24 | |
| 25 | All API calls can fail with network errors, rate limits (429), validation errors (422), |
| 26 | or authentication errors (401). Always handle errors in production code: |
| 27 | |
| 28 | ```ruby |
| 29 | assistant = client.ai.assistants.create(instructions: "You are a helpful assistant.", name: "my-resource", model: "openai/gpt-4o") |
| 30 | puts(assistant) |
| 31 | ``` |
| 32 | |
| 33 | Common error codes: `401` invalid API key, `403` insufficient permissions, |
| 34 | `404` resource not found, `422` validation error (check field formats), |
| 35 | `429` rate limited (retry with exponential backoff). |
| 36 | |
| 37 | ## Important Notes |
| 38 | |
| 39 | - **Phone numbers** must be in E.164 format (e.g., `+13125550001`). Include the `+` prefix and country code. No spaces, dashes, or parentheses. |
| 40 | - **Pagination:** Use `.auto_paging_each` for automatic iteration: `page.auto_paging_each { |item| puts item.id }`. |
| 41 | |
| 42 | ## Reference Use Rules |
| 43 | |
| 44 | Do not invent Telnyx parameters, enums, response fields, or webhook fields. |
| 45 | |
| 46 | - If the parameter, enum, or response field you need is not shown inline in this skill, read [references/api-details.md](references/api-details.md) before writing code. |
| 47 | - Before using any operation in `## Additional Operations`, read [the optional-parameters section](references/api-details.md#optional-parameters) and [the response-schemas section](references/api-details.md#response-schemas). |
| 48 | |
| 49 | ## Core Tasks |
| 50 | |
| 51 | ### Create an assistant |
| 52 | |
| 53 | Assistant creation is the entrypoint for any AI assistant integration. Agents need the exact creation method and the top-level fields returned by the SDK. |
| 54 | |
| 55 | `client.ai.assistants.create()` — `POST /ai/assistants` |
| 56 | |
| 57 | | Parameter | Type | Required | Description | |
| 58 | |-----------|------|----------|-------------| |
| 59 | | `name` | string | Yes | | |
| 60 | | `instructions` | string | Yes | System instructions for the assistant. | |
| 61 | | `tags` | array[string] | No | Tags associated with the assistant. | |
| 62 | | `model` | string | No | ID of the model to use when `external_llm` is not set. | |
| 63 | | `tools` | array[object] | No | Deprecated for new integrations. | |
| 64 | | ... | | | +23 optional params in [references/api-details.md](references/api-details.md) | |
| 65 | |
| 66 | ```ruby |
| 67 | assistant = client.ai.assistants.create(instructions: "You are a helpful assistant.", name: "my-resource", model: "openai/gpt-4o") |
| 68 | puts(assistant) |
| 69 | ``` |
| 70 | |
| 71 | Primary response fields: |
| 72 | - `assistant.id` |
| 73 | - `assistant.name` |
| 74 | - `assistant.model` |
| 75 | - `assistant.instructions` |
| 76 | - `assistant.created_at` |
| 77 | - `assistant.conversation_flow` |
| 78 | |
| 79 | ### Chat with an assistant |
| 80 | |
| 81 | Chat is the primary runtime path. Agents need the exact assistant method and the response content field. |
| 82 | |
| 83 | `client.ai.assistants.chat()` — `POST /ai/assistants/{assistant_id}/chat` |
| 84 | |
| 85 | | Parameter | Type | Required | Description | |
| 86 | |-----------|------|----------|-------------| |
| 87 | | `content` | string | Yes | The message content sent by the client to the assistant | |
| 88 | | `conversation_id` | string (UUID) | Yes | A unique identifier for the conversation thread, used to mai... | |
| 89 | | `assistant_id` | string (UUID) | Yes | Unique identifier of the assistant. | |
| 90 | | `name` | string | No | The optional display name of the user sending the message | |
| 91 | |
| 92 | ```ruby |
| 93 | response = client.ai.assistants.chat( |
| 94 | "assistant_id", |
| 95 | content: "Tell me a joke about cats", |
| 96 | conversation_id: "42b20469-1215-4a9a-8964-c36f66b406f4" |
| 97 | ) |
| 98 | |
| 99 | puts(response) |
| 100 | ``` |
| 101 | |
| 102 | Primary response fields: |
| 103 | - `response.content` |
| 104 | |
| 105 | ### Create an assistant test |
| 106 | |
| 107 | Test creation is the main validation path for production assistant behavior before deployment. |
| 108 | |
| 109 | `client.ai.assistants.tests.create()` — `POST /ai/assistants/tests` |
| 110 | |
| 111 | | Parameter | Type | Required | Description | |
| 112 | |-----------|------|----------|-------------| |
| 113 | | `name` | string | Yes | A descriptive name for the assistant test. | |
| 114 | | `destination` | string | Yes | The target destination for the test conversation. | |
| 115 | | `instructions` | string | Yes | Detailed instructions that define the test scenario and what... | |
| 116 | | `rubric` | array[object] | Yes | Evaluation criteria used to assess the assistant's performan... | |
| 117 | | `description` | string | No | Optional detailed description of what this test evaluates an... | |
| 118 | | `telnyx_conversation_channel` | object | No | The communication channel through which the test will be con... | |
| 119 | | `max_duration_seconds` | integer | No | Maximum duration in seconds that the test conversation shoul... | |
| 120 | | ... | | | +1 optional params in [references/api-details.md](references/api-deta |