diff --git a/api/__pycache__/_generated.cpython-312.pyc b/api/__pycache__/_generated.cpython-312.pyc deleted file mode 100644 index 291c3ac..0000000 Binary files a/api/__pycache__/_generated.cpython-312.pyc and /dev/null differ diff --git a/api/__pycache__/_schema.cpython-312.pyc b/api/__pycache__/_schema.cpython-312.pyc deleted file mode 100644 index 59d2bce..0000000 Binary files a/api/__pycache__/_schema.cpython-312.pyc and /dev/null differ diff --git a/api/__pycache__/_types.cpython-312.pyc b/api/__pycache__/_types.cpython-312.pyc deleted file mode 100644 index 26e578f..0000000 Binary files a/api/__pycache__/_types.cpython-312.pyc and /dev/null differ diff --git a/sdk/__pycache__/client.cpython-312.pyc b/sdk/__pycache__/client.cpython-312.pyc new file mode 100644 index 0000000..43028ce Binary files /dev/null and b/sdk/__pycache__/client.cpython-312.pyc differ diff --git a/sdk/assistants/__pycache__/delete.cpython-312.pyc b/sdk/assistants/__pycache__/delete.cpython-312.pyc new file mode 100644 index 0000000..893ab09 Binary files /dev/null and b/sdk/assistants/__pycache__/delete.cpython-312.pyc differ diff --git a/sdk/client.py b/sdk/client.py index d83854d..5cf0246 100644 --- a/sdk/client.py +++ b/sdk/client.py @@ -1,3 +1,5 @@ +import asyncio + from vapi import AsyncVapi import os @@ -8,10 +10,10 @@ def initialize_client(token: str) -> None: global _client - _client = Vapi(token=token) + _client = AsyncVapi(token=token) -def get_client() -> Vapi: +def get_client() -> AsyncVapi: global _client if _client is None: if VAPI_PRIVATE_TOKEN is None: diff --git a/typescript/api/_analytics/index.ts b/typescript/api/_analytics/index.ts deleted file mode 100644 index 07163a6..0000000 --- a/typescript/api/_analytics/index.ts +++ /dev/null @@ -1,76 +0,0 @@ -import { AnalyticsResponse } from '@/types/vapiAi/api/_analytics'; - -const options = { - method: 'POST', - headers: { - Authorization: 'Bearer ', - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ - queries: [ - { - table: 'call', - groupBy: ['assistantId', 'endedReason'], - name: 'callAnalyticsQuery', - timeRange: { - step: 'day', - start: '2023-01-01T00:00:00Z', - end: '2023-01-31T23:59:59Z', - timezone: 'UTC' - }, - operations: [ - { operation: 'sum', column: 'duration', alias: 'sumDuration' }, - { operation: 'avg', column: 'cost', alias: 'avgCost' } - ] - } - ] - }) -}; - -fetch('https://api.vapi.ai/analytics', options) - .then((response) => response.json()) - .then((data: AnalyticsResponse) => { - console.log(data); - data.data.forEach((queryResult) => { - console.log('Query Name:', queryResult.name); - console.log('Time Range:', queryResult.timeRange); - queryResult.result.forEach((result) => { - console.log('Date:', result.date); - console.log('Assistant ID:', result.assistantId); - console.log('Ended Reason:', result.endedReason); - console.log('Sum Duration:', result.sumDuration); - console.log('Avg Cost:', result.avgCost); - }); - }); - }) - .catch((err) => console.error(err)); - -export const exampleAnalyticsQuery = { - data: [ - { - name: 'callAnalyticsQuery', - timeRange: { - step: 'day', - start: '2023-01-01T00:00:00Z', - end: '2023-01-31T23:59:59Z', - timezone: 'UTC' - }, - result: [ - { - date: '2023-01-01', - assistantId: '123', - endedReason: 'customer-ended-call', - sumDuration: 120, - avgCost: 10.5 - }, - { - date: '2023-01-02', - assistantId: '123', - endedReason: 'customer-did-not-give-microphone-permission', - sumDuration: 0, - avgCost: 0 - } - ] - } - ] -}; diff --git a/typescript/api/_server/test.ts b/typescript/api/_server/test.ts deleted file mode 100644 index e8fe570..0000000 --- a/typescript/api/_server/test.ts +++ /dev/null @@ -1,43 +0,0 @@ -const options = { - method: 'POST', - headers: { - Authorization: 'Bearer ', - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ - message: { - type: 'assistant-request', - assistant: { - // Fill in the relevant assistant details here - id: 'assistant-123', - name: 'Assistant Name' - }, - phoneNumber: { - // Fill in the relevant phone number details here - id: 'phone-123', - number: '+14155551234' - }, - customer: { - // Fill in the relevant customer details here - id: 'customer-123', - name: 'John Doe' - }, - call: { - // Fill in the call object details here - id: 'call-123', - status: 'in-progress' - }, - artifact: { - // Add live artifacts of the call here (transcriptions, recordings, etc.) - recording: 'https://example.com/recording.mp3', - transcription: 'Hello, how can I help you?' - }, - timestamp: new Date().toISOString() // Current timestamp - } - }) -}; - -fetch('https://your-server-url.com/vapi/message', options) - .then((response) => response.json()) - .then((data) => console.log('Server response:', data)) - .catch((error) => console.error('Error:', error)); diff --git a/typescript/api/assistants/create.ts b/typescript/api/assistants/create.ts deleted file mode 100644 index 3ec910e..0000000 --- a/typescript/api/assistants/create.ts +++ /dev/null @@ -1,185 +0,0 @@ -import fetch from 'node-fetch'; - -const VAPI_URL = 'https://api.vapi.ai/assistant'; -const VAPI_API_KEY = ''; // Replace with your actual API key - -// Function to create an assistant -async function createAssistant(payload: CreateAssistantRequest): Promise { - const response = await fetch(VAPI_URL, { - method: 'POST', - headers: { - Authorization: `Bearer ${VAPI_API_KEY}`, - 'Content-Type': 'application/json' - }, - body: JSON.stringify(payload) - }); - - if (!response.ok) { - const error = await response.text(); - throw new Error(`Error creating assistant: ${error}`); - } - - return await response.json(); -} - -// Example payload to create an assistant -export const exampleCreateAssistantPayload: CreateAssistantRequest = { - transcriber: { - provider: 'deepgram', - model: 'nova-2', - language: 'en', - smartFormat: false, - keywords: ['example', 'test'], - endpointing: 255 - }, - model: { - messages: [ - { - content: 'Hello, how may I assist you today?', - role: 'assistant' // Role is required here - } - ], - tools: [ - { - async: false, - messages: [ - { - type: 'request-start', - content: 'Starting tool...', - role: 'assistant', // Add the role to avoid TypeScript errors - conditions: [ - { - value: 'start', - operator: 'eq', - param: 'status' - } - ] - } - ], - type: 'dtmf', - function: { - name: 'ProcessPayment', - description: 'This function processes payments.', - parameters: { - type: 'object', - properties: {}, - required: ['amount'] - } - }, - server: { - timeoutSeconds: 20, - url: 'https://example.com/process-payment', - secret: 'my-secret' - } - } - ], - toolIds: ['tool-123'], - provider: 'anyscale', - model: 'gpt-3', - temperature: 1, - knowledgeBase: { - provider: 'canonical', - topK: 5, - fileIds: ['file-123'] - }, - maxTokens: 500, - emotionRecognitionEnabled: true, - numFastTurns: 1 - }, - voice: { - fillerInjectionEnabled: false, - provider: 'azure', - voiceId: 'andrew', - speed: 1.25, - chunkPlan: { - enabled: true, - minCharacters: 30, - punctuationBoundaries: ['.', '!', '?'], - formatPlan: { - enabled: true, - numberToDigitsCutoff: 2025 - } - } - }, - firstMessageMode: 'assistant-speaks-first', - recordingEnabled: true, - hipaaEnabled: false, - clientMessages: ['conversation-update', 'function-call'], - serverMessages: ['conversation-update', 'end-of-call-report'], - silenceTimeoutSeconds: 30, - maxDurationSeconds: 600, - backgroundSound: 'office', - backchannelingEnabled: false, - backgroundDenoisingEnabled: false, - modelOutputInMessagesEnabled: false, - transportConfigurations: [ - { - provider: 'twilio', - timeout: 60, - record: false, - recordingChannels: 'mono' - } - ], - name: 'Test Assistant', - firstMessage: 'Hello! How can I assist you today?', - voicemailDetection: { - provider: 'twilio', - voicemailDetectionTypes: ['machine_end_beep'], - enabled: true, - machineDetectionTimeout: 31, - machineDetectionSpeechThreshold: 3500, - machineDetectionSpeechEndThreshold: 2750, - machineDetectionSilenceTimeout: 6000 - }, - voicemailMessage: 'Please leave a message after the beep.', - endCallMessage: 'Thank you for calling, goodbye!', - endCallPhrases: ['goodbye', 'bye'], - metadata: {}, - serverUrl: 'https://example.com/server-url', - serverUrlSecret: 'my-server-secret', - analysisPlan: { - summaryPrompt: 'Summarize the conversation.', - summaryRequestTimeoutSeconds: 10, - structuredDataRequestTimeoutSeconds: 10, - successEvaluationPrompt: 'Was this successful?', - successEvaluationRubric: 'NumericScale', - successEvaluationRequestTimeoutSeconds: 10, - structuredDataPrompt: 'Provide structured data.', - structuredDataSchema: { - type: 'string', - items: {}, - properties: {}, - description: 'Schema description', - required: ['requiredField'] - } - }, - artifactPlan: { - videoRecordingEnabled: true, - recordingS3PathPrefix: 's3://my-recordings/' - }, - messagePlan: { - idleMessages: ['Please hold.'], - idleMessageMaxSpokenCount: 5, - idleTimeoutSeconds: 20 - }, - startSpeakingPlan: { - waitSeconds: 0.4, - smartEndpointingEnabled: false, - transcriptionEndpointingPlan: { - onPunctuationSeconds: 0.1, - onNoPunctuationSeconds: 1.5, - onNumberSeconds: 0.5 - } - }, - stopSpeakingPlan: { - numWords: 0, - voiceSeconds: 0.2, - backoffSeconds: 1 - }, - credentialIds: ['credential-123'] -}; - -// // Call the function to create the assistant -// createAssistant(exampleCreateAssistantPayload) -// .then((response) => console.log('Assistant Created:', response)) -// .catch((error) => console.error('Error:', error)); diff --git a/typescript/api/assistants/delete.ts b/typescript/api/assistants/delete.ts deleted file mode 100644 index dc60758..0000000 --- a/typescript/api/assistants/delete.ts +++ /dev/null @@ -1,27 +0,0 @@ -import fetch from 'node-fetch'; - -// Function to delete an assistant by ID -async function deleteAssistantById(assistantId: string): Promise { - const VAPI_URL = `https://api.vapi.ai/assistant/${assistantId}`; - const VAPI_API_KEY = ''; // Replace with your actual API key - - const response = await fetch(VAPI_URL, { - method: 'DELETE', - headers: { - Authorization: `Bearer ${VAPI_API_KEY}`, - 'Content-Type': 'application/json' - } - }); - - if (!response.ok) { - const error = await response.text(); - throw new Error(`Error deleting assistant: ${error}`); - } - - console.log(`Assistant with ID ${assistantId} deleted successfully.`); -} - -// Example usage -deleteAssistantById('assistant-id-123') - .then(() => console.log('Delete complete')) - .catch((error) => console.error('Error:', error)); diff --git a/typescript/api/assistants/get.ts b/typescript/api/assistants/get.ts deleted file mode 100644 index dc272b0..0000000 --- a/typescript/api/assistants/get.ts +++ /dev/null @@ -1,73 +0,0 @@ -import { AssistantResponse } from '@/types/vapiAi/api/assistant/get'; - -// Function to get an assistant by ID -async function getAssistantById( - assistantId: string -): Promise { - const VAPI_URL = `https://api.vapi.ai/assistant/${assistantId}`; - const VAPI_API_KEY = ''; // Replace with your actual API key - - const response = await fetch(VAPI_URL, { - method: 'GET', - headers: { - Authorization: `Bearer ${VAPI_API_KEY}`, - 'Content-Type': 'application/json' - } - }); - - if (!response.ok) { - const error = await response.text(); - throw new Error(`Error fetching assistant: ${error}`); - } - - const assistant: AssistantResponse = await response.json(); - return assistant; -} - -// Example usage -getAssistantById('assistant-id-123') - .then((assistant) => console.log('Assistant fetched:', assistant)) - .catch((error) => console.error('Error:', error)); - -export const exampleGetResponseData = { - id: 'assistant-id-123', - name: 'Customer Support Assistant', - status: 'active', - createdAt: '2023-01-01T12:00:00Z', - updatedAt: '2023-09-01T15:00:00Z', - transcriber: { - provider: 'deepgram', - model: 'nova-2', - language: 'en', - smartFormat: true, - keywords: ['support', 'account'], - endpointing: 250 - }, - model: { - provider: 'openai', - model: 'gpt-4', - temperature: 0.8, - maxTokens: 1024, - emotionRecognitionEnabled: true, - numFastTurns: 2 - }, - voice: { - provider: 'azure', - voiceId: 'andrew', - speed: 1.25, - fillerInjectionEnabled: false - }, - firstMessageMode: 'assistant-speaks-first', - recordingEnabled: true, - hipaaEnabled: false, - backgroundSound: 'office', - backchannelingEnabled: false, - silenceTimeoutSeconds: 30, - maxDurationSeconds: 3600, - assistantOverrides: { - model: { - temperature: 0.7, - maxTokens: 512 - } - } -}; diff --git a/typescript/api/assistants/list.ts b/typescript/api/assistants/list.ts deleted file mode 100644 index 0af1ee6..0000000 --- a/typescript/api/assistants/list.ts +++ /dev/null @@ -1,124 +0,0 @@ -import fetch from 'node-fetch'; -import { ListAssistantsResponse } from '@/types/vapiAi/api/assistant/list'; - -// Function to list assistants with optional query parameters -async function listAssistants( - limit: number = 100, // Default limit - createdAtGt?: string, // Optional: created after this date - createdAtLt?: string, // Optional: created before this date - updatedAtGt?: string, // Optional: updated after this date - updatedAtLt?: string // Optional: updated before this date -): Promise { - const VAPI_URL = 'https://api.vapi.ai/assistant'; - const VAPI_API_KEY = ''; // Replace with your actual API key - - // Construct query parameters - const queryParams = new URLSearchParams(); - queryParams.append('limit', limit.toString()); - if (createdAtGt) queryParams.append('createdAtGt', createdAtGt); - if (createdAtLt) queryParams.append('createdAtLt', createdAtLt); - if (updatedAtGt) queryParams.append('updatedAtGt', updatedAtGt); - if (updatedAtLt) queryParams.append('updatedAtLt', updatedAtLt); - - const response = await fetch(`${VAPI_URL}?${queryParams.toString()}`, { - method: 'GET', - headers: { - Authorization: `Bearer ${VAPI_API_KEY}`, - 'Content-Type': 'application/json' - } - }); - - if (!response.ok) { - const error = await response.text(); - throw new Error(`Error listing assistants: ${error}`); - } - - // Cast the result of json() to ListAssistantsResponse - const assistantsList = (await response.json()) as ListAssistantsResponse; - - return assistantsList; -} - -// Example usage -listAssistants(50, '2023-01-01T00:00:00Z', undefined, '2023-12-31T23:59:59Z') - .then((response) => console.log('Assistants:', response)) - .catch((error) => console.error('Error:', error)); - -export const exampleListAssistantsResponse = { - assistants: [ - { - id: 'assistant-id-001', - name: 'Customer Support Assistant', - status: 'active', - createdAt: '2023-01-01T12:00:00Z', - updatedAt: '2023-06-01T15:00:00Z', - transcriber: { - provider: 'deepgram', - model: 'nova-2', - language: 'en', - smartFormat: true, - keywords: ['support', 'account'], - endpointing: 250 - }, - model: { - provider: 'openai', - model: 'gpt-4', - temperature: 0.8, - maxTokens: 1024, - emotionRecognitionEnabled: true, - numFastTurns: 2 - }, - voice: { - provider: 'azure', - voiceId: 'andrew', - speed: 1.25, - fillerInjectionEnabled: false - }, - firstMessageMode: 'assistant-speaks-first', - recordingEnabled: true, - hipaaEnabled: false, - backgroundSound: 'office', - backchannelingEnabled: false, - silenceTimeoutSeconds: 30, - maxDurationSeconds: 3600 - }, - { - id: 'assistant-id-002', - name: 'Technical Support Bot', - status: 'inactive', - createdAt: '2023-02-15T12:00:00Z', - updatedAt: '2023-07-01T15:00:00Z', - transcriber: { - provider: 'azure', - model: 'neural-en', - language: 'en', - smartFormat: false, - keywords: ['error', 'bug'], - endpointing: 200 - }, - model: { - provider: 'azure', - model: 'gpt-3', - temperature: 0.7, - maxTokens: 800, - emotionRecognitionEnabled: false, - numFastTurns: 1 - }, - voice: { - provider: 'google', - voiceId: 'samantha', - speed: 1.0, - fillerInjectionEnabled: true - }, - firstMessageMode: 'assistant-waits-for-user', - recordingEnabled: false, - hipaaEnabled: true, - backgroundSound: 'off', - backchannelingEnabled: true, - silenceTimeoutSeconds: 60, - maxDurationSeconds: 1800 - } - // More assistant objects... - ], - totalCount: 2 -}; diff --git a/typescript/api/assistants/update.ts b/typescript/api/assistants/update.ts deleted file mode 100644 index b43069c..0000000 --- a/typescript/api/assistants/update.ts +++ /dev/null @@ -1,77 +0,0 @@ -import fetch from 'node-fetch'; // Or node-fetch version 3, or axios if preferred -import { UpdateAssistantRequest } from '@/types/vapiAi/api/assistant/update'; // The extended type - -// Function to update an assistant by ID -async function updateAssistantById( - assistantId: string, - updateData: UpdateAssistantRequest -): Promise { - const VAPI_URL = `https://api.vapi.ai/assistant/${assistantId}`; - const VAPI_API_KEY = ''; // Replace with your actual API key - - const response = await fetch(VAPI_URL, { - method: 'PATCH', - headers: { - Authorization: `Bearer ${VAPI_API_KEY}`, - 'Content-Type': 'application/json' - }, - body: JSON.stringify(updateData) - }); - - if (!response.ok) { - const error = await response.text(); - throw new Error(`Error updating assistant: ${error}`); - } - - const updatedAssistant = await response.json(); - console.log('Assistant updated successfully:', updatedAssistant); -} - -// Example usage -const updateData: UpdateAssistantRequest = { - name: 'Updated Assistant Name', - model: { - temperature: 0.8 // Updating just the temperature field - } -}; - -updateAssistantById('assistant-id-123', updateData) - .then(() => console.log('Update complete')) - .catch((error) => console.error('Error:', error)); - -export const exampleUpdatedAssistantResponse = { - id: 'assistant-id-123', - name: 'Updated Assistant Name', - status: 'active', - createdAt: '2023-01-01T12:00:00Z', - updatedAt: '2023-09-08T10:00:00Z', - transcriber: { - provider: 'deepgram', - model: 'nova-2', - language: 'en', - smartFormat: true, - keywords: ['support', 'account'], - endpointing: 250 - }, - model: { - provider: 'openai', - model: 'gpt-4', - temperature: 0.8, // Updated field - maxTokens: 1024, - emotionRecognitionEnabled: true, - numFastTurns: 2 - }, - voice: { - provider: 'azure', - voiceId: 'andrew', - speed: 1.25, - fillerInjectionEnabled: false - }, - firstMessageMode: 'assistant-speaks-first', - recordingEnabled: true, - hipaaEnabled: false, - backgroundSound: 'office', - backchannelingEnabled: false, - silenceTimeoutSeconds: 30, - maxDurationSeconds: 3600 -}; diff --git a/typescript/api/calls/create.ts b/typescript/api/calls/create.ts deleted file mode 100644 index 05f5a1e..0000000 --- a/typescript/api/calls/create.ts +++ /dev/null @@ -1,247 +0,0 @@ -import { - CreateCallRequest, - MessageRole, - ToolMessageType -} from '@/types/vapiAi/api/calls/create'; - -// API call to create a call -async function createCall( - apiUrl: string, - apiKey: string, - callRequestData: CreateCallRequest -) { - const options = { - method: 'POST', - headers: { - Authorization: `Bearer ${apiKey}`, - 'Content-Type': 'application/json' - }, - body: JSON.stringify(callRequestData) - }; - - try { - const response = await fetch(apiUrl, options); - - if (!response.ok) { - // Handle non-200 responses - const errorText = await response.text(); - throw new Error(`Error creating call: ${errorText}`); - } - - // Parse the JSON response - const responseData = await response.json(); - console.log('Call created successfully:', responseData); - - return responseData; // Return the response data if needed - } catch (error) { - console.error('Error:', error); - throw error; // Re-throw the error if needed for further handling - } -} - -// Example usage of the createCall function -const apiUrl = 'https://api.vapi.ai/call'; -const apiKey = ''; // Replace with your actual API key - -const callRequestData: CreateCallRequest = { - name: 'Test Call', - assistantId: 'assistant-123', - assistant: { - transcriber: { - provider: 'deepgram', - model: 'nova-2', - language: 'bg', - smartFormat: false, - keywords: ['test'], - endpointing: 255 - }, - model: { - messages: [ - { - role: 'user', - message: 'Hello, how can I help?', - time: Date.now(), - secondsFromStart: 5, - endTime: Date.now() + 1000, - duration: 1 - } - ], - tools: [ - { - async: false, - messages: [ - { - type: ToolMessageType.ToolMessageStart, - content: 'Processing your request, please wait...', - role: MessageRole.Assistant - } - ], - type: 'dtmf', - function: { - name: 'DTMF Tool', - description: 'Tool for DTMF detection', - parameters: { - type: 'object', - properties: {}, - required: ['param1'] - } - }, - server: { - timeoutSeconds: 20, - url: 'https://tool.server.url', - secret: 'secretKey' - } - } - ], - toolIds: ['tool-1'], - provider: 'anyscale', - model: 'model-1', - temperature: 1, - maxTokens: 525, - emotionRecognitionEnabled: true, - numFastTurns: 1 - }, - voice: { - fillerInjectionEnabled: false, - provider: 'azure', - voiceId: 'andrew', - speed: 1.25, - chunkPlan: { - enabled: true, - minCharacters: 30, - punctuationBoundaries: ['.', ',', '!', '?'], - formatPlan: { - enabled: true, - numberToDigitsCutoff: 2025 - } - } - }, - firstMessageMode: 'assistant-speaks-first', - recordingEnabled: true, - hipaaEnabled: false, - clientMessages: ['conversation-update', 'function-call'], - serverMessages: ['conversation-update', 'end-of-call-report'], - silenceTimeoutSeconds: 30, - maxDurationSeconds: 600, - backgroundSound: 'office', - backchannelingEnabled: false, - backgroundDenoisingEnabled: false - }, - phoneNumberId: 'phone-number-123', - customerId: 'customer-123' -}; - -// Call the function -createCall(apiUrl, apiKey, callRequestData) - .then((response) => console.log('Call Response:', response)) - .catch((error) => console.error('Call Error:', error)); - -export const exampleCreateCallResponse = { - id: 'call-id-001', // Unique identifier for the call - name: 'Test Call', - assistantId: 'assistant-123', - squadId: null, - phoneNumberId: 'phone-number-123', - customerId: 'customer-123', - status: 'queued', // Initial status of the call - endedReason: null, // Not ended yet - type: 'outboundPhoneCall', - phoneCallProvider: 'twilio', - phoneCallTransport: 'pstn', - createdAt: '2024-09-08T12:00:00Z', - updatedAt: '2024-09-08T12:01:00Z', - startedAt: null, // Call hasn't started yet - endedAt: null, // Call hasn't ended yet - cost: 0.0, // Cost will be calculated after the call - messages: [ - { - content: 'Hello!', - role: 'assistant' // Initial assistant message - } - ], - recordingUrl: null, // Recording will be available after the call - stereoRecordingUrl: null, - transcript: null, // Transcript will be generated after the call - artifact: { - videoRecordingEnabled: true, - recordingS3PathPrefix: 's3://recordings/call-id-001' - }, - analysis: { - summary: null, - structuredData: {}, - successEvaluation: null - }, - assistant: { - transcriber: { - provider: 'deepgram', - model: 'nova-2', - language: 'bg', - smartFormat: false, - keywords: ['test'], - endpointing: 255 - }, - model: { - messages: [{ content: 'Hello!', role: 'assistant' }], - tools: [ - { - async: false, - messages: [ - { - type: 'request-start', - content: 'Tool started', - role: 'assistant', - conditions: [{ value: 'start', operator: 'eq', param: 'trigger' }] - } - ], - type: 'dtmf', - function: { - name: 'DTMF Tool', - description: 'Tool for DTMF detection', - parameters: { - type: 'object', - properties: {}, - required: ['param1'] - } - }, - server: { - timeoutSeconds: 20, - url: 'https://tool.server.url', - secret: 'secretKey' - } - } - ], - toolIds: ['tool-1'], - provider: 'anyscale', - model: 'model-1', - temperature: 1, - maxTokens: 525, - emotionRecognitionEnabled: true, - numFastTurns: 1 - }, - voice: { - fillerInjectionEnabled: false, - provider: 'azure', - voiceId: 'andrew', - speed: 1.25, - chunkPlan: { - enabled: true, - minCharacters: 30, - punctuationBoundaries: ['.', ',', '!', '?'], - formatPlan: { - enabled: true, - numberToDigitsCutoff: 2025 - } - } - }, - firstMessageMode: 'assistant-speaks-first', - recordingEnabled: true, - hipaaEnabled: false, - clientMessages: ['conversation-update', 'function-call'], - serverMessages: ['conversation-update', 'end-of-call-report'], - silenceTimeoutSeconds: 30, - maxDurationSeconds: 600, - backgroundSound: 'office', - backchannelingEnabled: false, - backgroundDenoisingEnabled: false - } -}; diff --git a/typescript/api/calls/delete.ts b/typescript/api/calls/delete.ts deleted file mode 100644 index bdb6a80..0000000 --- a/typescript/api/calls/delete.ts +++ /dev/null @@ -1,52 +0,0 @@ -// Import necessary types -import { DeleteCallResponse } from '@/types/vapiAi/api/calls/delete'; - -// Function to delete a call by ID -async function deleteCallById( - callId: string, - token: string -): Promise { - const url = `https://api.vapi.ai/call/${callId}`; - - const options = { - method: 'DELETE', - headers: { - Authorization: `Bearer ${token}`, - 'Content-Type': 'application/json' - } - }; - - try { - const response = await fetch(url, options); - - if (!response.ok) { - const error = await response.text(); - throw new Error(`Error deleting call: ${error}`); - } - - const deleteCallData: DeleteCallResponse = await response.json(); - return deleteCallData; - } catch (err) { - console.error('Error:', err); - throw err; - } -} - -// Example usage -const token = ''; -const callId = 'call-id-123'; - -deleteCallById(callId, token) - .then((deletedCall) => console.log('Deleted Call:', deletedCall)) - .catch((err) => console.error('Error deleting call:', err)); - -export const exampleDeleteResponse = { - id: 'call-id-123', - status: 'ended', - endedReason: 'manually-canceled', - type: 'inboundPhoneCall', - phoneCallProvider: 'twilio', - messages: [], - createdAt: '2023-09-07T12:00:00Z', - updatedAt: '2023-09-07T12:30:00Z' -}; diff --git a/typescript/api/calls/get.ts b/typescript/api/calls/get.ts deleted file mode 100644 index 51058f2..0000000 --- a/typescript/api/calls/get.ts +++ /dev/null @@ -1,161 +0,0 @@ -// Import or declare types -import { GetCallResponse } from '@/types/vapiAi/api/calls/get'; - -// Function to fetch call details by ID -async function getCallById( - callId: string, - token: string -): Promise { - const url = `https://api.vapi.ai/call/${callId}`; - - const options = { - method: 'GET', - headers: { - Authorization: `Bearer ${token}`, - 'Content-Type': 'application/json' - } - }; - - try { - const response = await fetch(url, options); - - if (!response.ok) { - const error = await response.text(); - throw new Error(`Error fetching call: ${error}`); - } - - const callData: GetCallResponse = await response.json(); - return callData; - } catch (err) { - console.error('Error:', err); - throw err; - } -} - -// Example usage -const token = ''; -getCallById('call-id-123', token) - .then((call) => console.log('Call details:', call)) - .catch((err) => console.error('Error fetching call:', err)); - -// Example payload -export const exampleCallResponse: GetCallResponse = { - id: 'call-id-123', - orgId: 'org-id-456', - type: 'inboundPhoneCall', - phoneCallProvider: 'twilio', - phoneCallTransport: 'sip', - status: 'ended', - endedReason: 'assistant-error', - monitor: { - listenUrl: 'https://example.com/listen', - controlUrl: 'https://example.com/control' - }, - messages: [ - { - role: 'user', - message: 'Hello, how can I help?', - time: Date.now(), - secondsFromStart: 5, - endTime: Date.now() + 1000, - duration: 1 - } - ], - destination: { - type: 'number', - numberE164CheckEnabled: true, - number: '+1234567890', - extension: '123', - message: 'Transfer to support', - description: 'Call transferred to support team' - }, - createdAt: '2023-09-07T12:00:00Z', - updatedAt: '2023-09-07T12:05:00Z', - startedAt: '2023-09-07T12:01:00Z', - endedAt: '2023-09-07T12:04:30Z', - cost: 5.0, - costBreakdown: { - transport: 1.5, - stt: 1.0, - llm: 0.5, - tts: 0.8, - vapi: 1.2, - total: 5.0, - llmPromptTokens: 100, - llmCompletionTokens: 80, - ttsCharacters: 500 - }, - transcript: 'Transcript of the call goes here...', - recordingUrl: 'https://example.com/recording.mp3', - stereoRecordingUrl: 'https://example.com/stereo-recording.mp3', - artifact: { - videoRecordingEnabled: true, - recordingS3PathPrefix: 's3://recordings/call-id-123' - }, - analysis: { - summary: 'The call ended abruptly due to an error.', - structuredData: {}, - successEvaluation: 'unsuccessful' - }, - assistantId: 'assistant-id-789', - assistant: { - transcriber: { - provider: 'deepgram', - model: 'nova-2', - language: 'en', - smartFormat: false, - keywords: ['support', 'account'], - endpointing: 255 - }, - model: { - messages: [ - { - role: 'user', - message: 'Hello, how can I help?', - time: Date.now(), - secondsFromStart: 5, - endTime: Date.now() + 1000, - duration: 1 - } - ], - tools: [], - toolIds: [], - provider: 'anyscale', - model: 'gpt-4', - temperature: 0.8, - knowledgeBase: { - provider: 'canonical', - topK: 5, - fileIds: ['file-id-001'] - }, - maxTokens: 500, - emotionRecognitionEnabled: true, - numFastTurns: 2 - }, - voice: { - fillerInjectionEnabled: false, - provider: 'azure', - voiceId: 'andrew', - speed: 1.25, - chunkPlan: { - enabled: true, - minCharacters: 30, - punctuationBoundaries: ['.', '?', '!'], - formatPlan: { - enabled: true, - numberToDigitsCutoff: 2025 - } - } - }, - firstMessageMode: 'assistant-speaks-first', - recordingEnabled: true, - hipaaEnabled: false, - clientMessages: ['conversation-update', 'function-call'], - serverMessages: ['conversation-update', 'end-of-call-report'], - silenceTimeoutSeconds: 30, - maxDurationSeconds: 600, - backgroundSound: 'office', - backchannelingEnabled: false, - backgroundDenoisingEnabled: true - } -}; diff --git a/typescript/api/calls/list.ts b/typescript/api/calls/list.ts deleted file mode 100644 index a1723ea..0000000 --- a/typescript/api/calls/list.ts +++ /dev/null @@ -1,107 +0,0 @@ -import { - ListCallsQueryParams, - ListCallsResponse -} from '@/types/vapiAi/api/calls/list'; - -// Function to fetch list of calls with query parameters -async function listCalls( - token: string, - params: ListCallsQueryParams = {} -): Promise { - const queryParams = new URLSearchParams(params as any).toString(); // Convert params to query string - const url = `https://api.vapi.ai/call?${queryParams}`; - - const options = { - method: 'GET', - headers: { - Authorization: `Bearer ${token}`, - 'Content-Type': 'application/json' - } - }; - - try { - const response = await fetch(url, options); - - if (!response.ok) { - const error = await response.text(); - throw new Error(`Error fetching call list: ${error}`); - } - - const callListData: ListCallsResponse = await response.json(); - return callListData; - } catch (err) { - console.error('Error:', err); - throw err; - } -} - -// Example usage -const token = ''; -const queryParams: ListCallsQueryParams = { - limit: 10, - assistantId: 'assistant-id-123', - createdAtGt: '2023-01-01T00:00:00Z' -}; - -listCalls(token, queryParams) - .then((callList) => console.log('Call list:', callList)) - .catch((err) => console.error('Error fetching call list:', err)); - -export const exampleListCallsResponse: ListCallsResponse = { - calls: [ - { - id: 'call-id-001', - orgId: 'org-id-001', - type: 'inboundPhoneCall', - monitor: { - listenUrl: 'https://example.com/listen', - controlUrl: 'https://example.com/control' - }, - phoneCallProvider: 'twilio', - phoneCallTransport: 'sip', - status: 'ended', - endedReason: 'assistant-error', - messages: [ - { - role: 'user', - message: 'Hello, how can I help?', - time: Date.now(), - secondsFromStart: 5, - endTime: Date.now() + 1000, - duration: 1 - } - ], - createdAt: '2023-09-07T12:00:00Z', - updatedAt: '2023-09-07T12:05:00Z', - startedAt: '2023-09-07T12:01:00Z', - endedAt: '2023-09-07T12:04:30Z', - cost: 5.0, - costBreakdown: { - transport: 1.5, - stt: 1.0, - llm: 0.5, - tts: 0.8, - vapi: 1.2, - total: 5.0, - llmPromptTokens: 100, - llmCompletionTokens: 80, - ttsCharacters: 500 - }, - transcript: 'Transcript of the call goes here...', - recordingUrl: 'https://example.com/recording.mp3', - stereoRecordingUrl: 'https://example.com/stereo-recording.mp3', - artifact: { - videoRecordingEnabled: true, - recordingS3PathPrefix: 's3://recordings/call-id-001' - }, - analysis: { - summary: 'The call ended due to an error.', - structuredData: {}, - successEvaluation: 'unsuccessful' - }, - assistantId: 'assistant-id-001' - } - // More calls... - ], - totalCount: 20 // Optional total count of calls -}; diff --git a/typescript/api/calls/update.ts b/typescript/api/calls/update.ts deleted file mode 100644 index e55dcf0..0000000 --- a/typescript/api/calls/update.ts +++ /dev/null @@ -1,74 +0,0 @@ -import { - UpdateCallRequestBody, - UpdateCallResponse -} from '@/types/vapiAi/api/calls/update'; - -// Function to update the call by ID -async function updateCall( - callId: string, - token: string, - requestBody: UpdateCallRequestBody -): Promise { - const url = `https://api.vapi.ai/call/${callId}`; - - const options = { - method: 'PATCH', - headers: { - Authorization: `Bearer ${token}`, - 'Content-Type': 'application/json' - }, - body: JSON.stringify(requestBody) - }; - - try { - const response = await fetch(url, options); - - if (!response.ok) { - const error = await response.text(); - throw new Error(`Error updating call: ${error}`); - } - - const updatedCallData: UpdateCallResponse = await response.json(); - return updatedCallData; - } catch (err) { - console.error('Error:', err); - throw err; - } -} - -// Example usage -const token = ''; -const callId = 'call-id-123'; // The ID of the call to update -const requestBody: UpdateCallRequestBody = { - name: 'Updated Call Name' // Updating the name of the call -}; - -updateCall(callId, token, requestBody) - .then((updatedCall) => console.log('Updated call:', updatedCall)) - .catch((err) => console.error('Error updating call:', err)); - -export const exampleUpdateCallResponse = { - id: 'call-id-123', - orgId: 'org-id-456', - type: 'outboundPhoneCall', - messages: [ - { - content: 'Hello, how can I help you?', - role: 'assistant' - }, - { - content: 'I need help with my account.', - role: 'user' - } - ], - status: 'ended', - endedReason: 'assistant-ended-call', - createdAt: '2023-09-07T12:00:00Z', - updatedAt: '2023-09-07T12:05:00Z', - startedAt: '2023-09-07T12:01:00Z', - endedAt: '2023-09-07T12:04:30Z', - cost: 5.0, - transcript: 'Transcript of the call goes here...', - recordingUrl: 'https://example.com/recording.mp3', - assistantId: 'assistant-id-001' -}; diff --git a/typescript/api/phoneNumbers/create.ts b/typescript/api/phoneNumbers/create.ts deleted file mode 100644 index aab919b..0000000 --- a/typescript/api/phoneNumbers/create.ts +++ /dev/null @@ -1,93 +0,0 @@ -import { - CreatePhoneNumberRequest, - CreatePhoneNumberResponse, - PhoneNumberProvider -} from '@/types/vapiAi/api/phoneNumbers/create'; -import fetch from 'node-fetch'; - -// API call to create a phone number -async function createPhoneNumber( - apiUrl: string, - apiKey: string, - phoneNumberRequestData: CreatePhoneNumberRequest -): Promise { - const options = { - method: 'POST', - headers: { - Authorization: `Bearer ${apiKey}`, - 'Content-Type': 'application/json' - }, - body: JSON.stringify(phoneNumberRequestData) - }; - - try { - const response = await fetch(apiUrl, options); - - if (!response.ok) { - const errorText = await response.text(); - throw new Error(`Error creating phone number: ${errorText}`); - } - - // Cast the JSON response to the expected type - const responseData = (await response.json()) as CreatePhoneNumberResponse; - console.log('Phone number created successfully:', responseData); - - return responseData; // Return the response data if needed - } catch (error) { - console.error('Error:', error); - throw error; // Re-throw the error if needed for further handling - } -} - -// Example usage of the createPhoneNumber function -const apiUrl = 'https://api.vapi.ai/phone-number'; -const apiKey = ''; // Replace with your actual API key - -const phoneNumberRequestData: CreatePhoneNumberRequest = { - fallbackDestination: { - type: 'number', - numberE164CheckEnabled: true, - number: '+14155551234', - extension: '123', - message: 'This is a fallback message.', - description: 'Fallback description.' - }, - provider: PhoneNumberProvider.ByoPhoneNumber, // Correct - numberE164CheckEnabled: true, - number: '+14155551234', - credentialId: 'credential-id-123', - name: 'Test Phone Number', - assistantId: 'assistant-id-123', - squadId: 'squad-id-123', - serverUrl: 'https://server.url', - serverUrlSecret: 'server-secret-123' -}; - -// Call the function -createPhoneNumber(apiUrl, apiKey, phoneNumberRequestData) - .then((response) => console.log('Phone Number Response:', response)) - .catch((error) => console.error('Phone Number Error:', error)); - -export const exampleCreatePhoneNumberResponse: CreatePhoneNumberResponse = { - fallbackDestination: { - type: 'number', - numberE164CheckEnabled: true, - number: '+14155551234', - extension: '123', - message: 'This is a fallback message.', - description: 'Fallback description.' - }, - provider: PhoneNumberProvider.ByoPhoneNumber, // Correct - numberE164CheckEnabled: true, - id: 'phone-number-id-123', - orgId: 'org-id-123', - createdAt: '2023-09-07T12:00:00Z', - updatedAt: '2023-09-07T12:30:00Z', - name: 'Test Phone Number', - assistantId: 'assistant-id-123', - squadId: 'squad-id-123', - serverUrl: 'https://server.url', - serverUrlSecret: 'server-secret-123', - number: '+14155551234', - credentialId: 'credential-id-123' -}; diff --git a/typescript/api/phoneNumbers/delete.ts b/typescript/api/phoneNumbers/delete.ts deleted file mode 100644 index ab08579..0000000 --- a/typescript/api/phoneNumbers/delete.ts +++ /dev/null @@ -1,67 +0,0 @@ -import { PhoneNumberProvider } from '@/types/vapiAi/api/phoneNumbers/create'; -import { DeletePhoneNumberResponse } from '@/types/vapiAi/api/phoneNumbers/delete'; - -// Function to delete a phone number by ID -async function deletePhoneNumberById( - phoneNumberId: string, - token: string -): Promise { - const url = `https://api.vapi.ai/phone-number/${phoneNumberId}`; - - const options = { - method: 'DELETE', - headers: { - Authorization: `Bearer ${token}`, - 'Content-Type': 'application/json' - } - }; - - try { - const response = await fetch(url, options); - - if (!response.ok) { - const errorText = await response.text(); - throw new Error(`Error deleting phone number: ${errorText}`); - } - - // Parse and return the response data - const responseData: DeletePhoneNumberResponse = - (await response.json()) as DeletePhoneNumberResponse; - return responseData; - } catch (err) { - console.error('Error:', err); - throw err; - } -} - -// Example usage -const token = ''; -deletePhoneNumberById('phone-number-id-123', token) - .then((deletedPhoneNumber) => - console.log('Deleted Phone Number:', deletedPhoneNumber) - ) - .catch((err) => console.error('Error deleting phone number:', err)); - -export const exampleDeletePhoneNumberResponse: DeletePhoneNumberResponse = { - fallbackDestination: { - type: 'number', - numberE164CheckEnabled: true, - number: '+14155551234', - extension: '123', - message: 'Backup destination in case of failure', - description: 'Test description for the fallback' - }, - provider: PhoneNumberProvider.ByoPhoneNumber, // Correct - numberE164CheckEnabled: true, - id: 'phone-number-id-123', - orgId: 'org-id-456', - createdAt: '2023-11-07T05:31:56Z', - updatedAt: '2023-11-07T05:31:56Z', - name: 'Main Office Line', - assistantId: 'assistant-id-789', - squadId: 'squad-id-321', - serverUrl: 'https://example.com/server-url', - serverUrlSecret: 'secret-key', - number: '+14155551234', - credentialId: 'credential-id-654' -}; diff --git a/typescript/api/phoneNumbers/get.ts b/typescript/api/phoneNumbers/get.ts deleted file mode 100644 index c8784d8..0000000 --- a/typescript/api/phoneNumbers/get.ts +++ /dev/null @@ -1,64 +0,0 @@ -import { PhoneNumberProvider } from '@/types/vapiAi/api/phoneNumbers/create'; -import { GetPhoneNumberResponse } from '@/types/vapiAi/api/phoneNumbers/get'; -import fetch from 'node-fetch'; - -// Function to fetch phone number details by ID -async function getPhoneNumberById( - phoneNumberId: string, - token: string -): Promise { - const url = `https://api.vapi.ai/phone-number/${phoneNumberId}`; - - const options = { - method: 'GET', - headers: { - Authorization: `Bearer ${token}`, - 'Content-Type': 'application/json' - } - }; - - try { - const response = await fetch(url, options); - - if (!response.ok) { - const errorText = await response.text(); - throw new Error(`Error fetching phone number: ${errorText}`); - } - - const responseData = (await response.json()) as GetPhoneNumberResponse; // Type casting here - return responseData; - } catch (err) { - console.error('Error:', err); - throw err; - } -} - -// Example usage -const token = ''; -getPhoneNumberById('phone-number-id-123', token) - .then((phoneNumber) => console.log('Phone Number:', phoneNumber)) - .catch((error) => console.error('Error:', error)); - -export const exampleGetPhoneNumberResponse: GetPhoneNumberResponse = { - fallbackDestination: { - type: 'number', - numberE164CheckEnabled: true, - number: '+14155551234', - extension: '123', - message: 'Fallback message in case of failure.', - description: 'Fallback for missed calls.' - }, - provider: PhoneNumberProvider.ByoPhoneNumber, // Correct - numberE164CheckEnabled: true, - id: 'phone-number-id-123', - orgId: 'org-id-456', - createdAt: '2023-11-07T05:31:56Z', - updatedAt: '2023-11-07T05:31:56Z', - name: 'Test Phone Number', - assistantId: 'assistant-id-789', - squadId: 'squad-id-1011', - serverUrl: 'https://example.server.url', - serverUrlSecret: 'server-secret-123', - number: '+14155551234', - credentialId: 'credential-id-456' -}; diff --git a/typescript/api/phoneNumbers/list.ts b/typescript/api/phoneNumbers/list.ts deleted file mode 100644 index ce13d39..0000000 --- a/typescript/api/phoneNumbers/list.ts +++ /dev/null @@ -1,107 +0,0 @@ -import { PhoneNumberProvider } from '@/types/vapiAi/api/phoneNumbers/create'; -import { ListPhoneNumbersResponse } from '@/types/vapiAi/api/phoneNumbers/list'; -import fetch from 'node-fetch'; // Or node-fetch v3 or axios if preferred - -// Function to list phone numbers with optional query parameters -async function listPhoneNumbers( - token: string, - limit: number = 100, - createdAtGt?: string, - createdAtLt?: string, - updatedAtGt?: string, - updatedAtLt?: string -): Promise { - const url = new URL('https://api.vapi.ai/phone-number'); - - // Add query parameters if provided - url.searchParams.append('limit', limit.toString()); - if (createdAtGt) url.searchParams.append('createdAtGt', createdAtGt); - if (createdAtLt) url.searchParams.append('createdAtLt', createdAtLt); - if (updatedAtGt) url.searchParams.append('updatedAtGt', updatedAtGt); - if (updatedAtLt) url.searchParams.append('updatedAtLt', updatedAtLt); - - const options = { - method: 'GET', - headers: { - Authorization: `Bearer ${token}`, - 'Content-Type': 'application/json' - } - }; - - try { - const response = await fetch(url.toString(), options); - - if (!response.ok) { - const errorText = await response.text(); - throw new Error(`Error listing phone numbers: ${errorText}`); - } - - // Cast the response to ListPhoneNumbersResponse - const responseData = (await response.json()) as ListPhoneNumbersResponse; - return responseData; - } catch (err) { - console.error('Error:', err); - throw err; - } -} - -// Example usage -const token = ''; -listPhoneNumbers( - token, - 50, - '2023-01-01T00:00:00Z', - undefined, - '2023-12-31T23:59:59Z' -) - .then((response) => console.log('Phone Numbers:', response)) - .catch((error) => console.error('Error:', error)); - -export const exampleListPhoneNumbersResponse: ListPhoneNumbersResponse = [ - { - fallbackDestination: { - type: 'number', - numberE164CheckEnabled: true, - number: '+14155551234', - extension: '1234', - message: 'Fallback message', - description: 'Fallback description' - }, - provider: PhoneNumberProvider.ByoPhoneNumber, // Correct - numberE164CheckEnabled: true, - id: 'phone-number-123', - orgId: 'org-123', - createdAt: '2023-11-07T05:31:56Z', - updatedAt: '2023-11-07T05:31:56Z', - name: 'Test Phone Number', - assistantId: 'assistant-123', - squadId: 'squad-123', - serverUrl: 'https://my-server-url.com', - serverUrlSecret: 'my-server-secret', - number: '+14155551234', - credentialId: 'credential-123' - }, - { - fallbackDestination: { - type: 'number', - numberE164CheckEnabled: true, - number: '+14155554321', - extension: '5678', - message: 'Fallback message', - description: 'Fallback description' - }, - provider: PhoneNumberProvider.ByoPhoneNumber, // Correct - numberE164CheckEnabled: true, - id: 'phone-number-456', - orgId: 'org-123', - createdAt: '2023-11-06T12:00:00Z', - updatedAt: '2023-11-06T12:30:00Z', - name: 'Secondary Phone Number', - assistantId: 'assistant-456', - squadId: 'squad-456', - serverUrl: 'https://my-other-server-url.com', - serverUrlSecret: 'my-other-server-secret', - number: '+14155554321', - credentialId: 'credential-456' - } -]; diff --git a/typescript/api/phoneNumbers/update.ts b/typescript/api/phoneNumbers/update.ts deleted file mode 100644 index 107fca3..0000000 --- a/typescript/api/phoneNumbers/update.ts +++ /dev/null @@ -1,92 +0,0 @@ -import { - CreatePhoneNumberRequest, - CreatePhoneNumberResponse, - PhoneNumberProvider -} from '@/types/vapiAi/api/phoneNumbers/create'; -import { UpdatePhoneNumberResponse } from '@/types/vapiAi/api/phoneNumbers/update'; - -// Function to create a phone number -async function createPhoneNumber( - token: string, - phoneNumberData: CreatePhoneNumberRequest -): Promise { - const url = `https://api.vapi.ai/phone-number`; - - const options = { - method: 'POST', - headers: { - Authorization: `Bearer ${token}`, - 'Content-Type': 'application/json' - }, - body: JSON.stringify(phoneNumberData) - }; - - try { - const response = await fetch(url, options); - - if (!response.ok) { - const errorText = await response.text(); - throw new Error(`Error creating phone number: ${errorText}`); - } - - // Explicitly cast the response to CreatePhoneNumberResponse - const responseData: CreatePhoneNumberResponse = - (await response.json()) as CreatePhoneNumberResponse; - console.log('Phone number created successfully:', responseData); - - return responseData; - } catch (err) { - console.error('Error:', err); - throw err; - } -} - -// Example usage -const token = ''; -const phoneNumberData: CreatePhoneNumberRequest = { - fallbackDestination: { - type: 'number', - numberE164CheckEnabled: true, - number: '+14155551234', - extension: '123', - message: 'Test message', - description: 'Test description' - }, - provider: PhoneNumberProvider.ByoPhoneNumber, // Correct - numberE164CheckEnabled: true, - number: '+14155551234', - credentialId: 'credential-123', - name: 'Test Phone Number', - assistantId: 'assistant-123', - squadId: 'squad-123', - serverUrl: 'https://example.com/server', - serverUrlSecret: 'server-secret' -}; - -createPhoneNumber(token, phoneNumberData) - .then((response) => console.log('Phone number response:', response)) - .catch((error) => console.error('Error:', error)); - -export const exampleUpdatePhoneNumberResponse: UpdatePhoneNumberResponse = { - fallbackDestination: { - type: 'number', - numberE164CheckEnabled: true, - number: '+14155551234', - extension: '1234', - message: 'Fallback message', - description: 'Fallback description' - }, - provider: PhoneNumberProvider.ByoPhoneNumber, // Correct - numberE164CheckEnabled: true, - id: 'phone-number-123', - orgId: 'org-123', - createdAt: '2023-11-07T05:31:56Z', - updatedAt: '2023-11-08T05:31:56Z', // The updated timestamp - name: 'Updated Phone Number', - assistantId: 'assistant-123', - squadId: 'squad-123', - serverUrl: 'https://updated-server-url.com', - serverUrlSecret: 'updated-secret-key', - number: '+14155551234', - credentialId: 'credential-123' -}; diff --git a/typescript/api/squad/create.ts b/typescript/api/squad/create.ts deleted file mode 100644 index da58940..0000000 --- a/typescript/api/squad/create.ts +++ /dev/null @@ -1,189 +0,0 @@ -import { ToolMessageType, MessageRole } from '@/types/vapiAi/api/calls/create'; -import { CreateSquadRequest } from '@/types/vapiAi/api/squad/create'; - -async function createSquad( - apiUrl: string, - apiKey: string, - squadData: CreateSquadRequest -) { - const options = { - method: 'POST', - headers: { - Authorization: `Bearer ${apiKey}`, - 'Content-Type': 'application/json' - }, - body: JSON.stringify(squadData) - }; - - try { - const response = await fetch(apiUrl, options); - - if (!response.ok) { - const error = await response.text(); - throw new Error(`Error creating squad: ${error}`); - } - - const createdSquad = await response.json(); - console.log('Squad created successfully:', createdSquad); - return createdSquad; - } catch (error) { - console.error('Error:', error); - throw error; - } -} - -// Example usage -const apiUrl = 'https://api.vapi.ai/squad'; -const apiKey = ''; // Replace with actual API key - -const squadData: CreateSquadRequest = { - name: 'My Squad', - members: [ - { - assistantId: 'assistant-123', - assistant: { - transcriber: { - provider: 'deepgram', - model: 'nova-2', - language: 'en', - smartFormat: false, - keywords: ['support', 'help'], - endpointing: 255 - }, - model: { - messages: [ - { content: 'Hello, how can I assist you?', role: 'assistant' } - ], - tools: [ - { - async: false, - messages: [ - { - type: ToolMessageType.ToolMessageStart, - content: 'Processing your request, please wait...', - role: MessageRole.Assistant - } - ], - type: 'dtmf', - function: { - name: 'DTMF Tool', - description: 'Tool for DTMF detection', - parameters: { - type: 'object', - properties: {}, - required: ['param1'] - } - }, - server: { - timeoutSeconds: 20, - url: 'https://my-tool-url.com', - secret: 'mySecretKey' - } - } - ], - toolIds: ['tool-1'], - provider: 'anyscale', - model: 'gpt-4', - temperature: 0.7, - maxTokens: 1000, - emotionRecognitionEnabled: true, - numFastTurns: 1 - }, - voice: { - provider: 'azure', - voiceId: 'en-US-GuyNeural', - speed: 1.2, - chunkPlan: { - enabled: true, - minCharacters: 30, - punctuationBoundaries: ['.', ',', '?', '!', ';'], - formatPlan: { enabled: true, numberToDigitsCutoff: 2025 } - } - }, - firstMessageMode: 'assistant-speaks-first', - recordingEnabled: true, - hipaaEnabled: false, - clientMessages: ['conversation-update', 'function-call', 'transcript'], - serverMessages: ['conversation-update', 'end-of-call-report'], - silenceTimeoutSeconds: 30, - maxDurationSeconds: 600, - backgroundSound: 'office', - backchannelingEnabled: false, - backgroundDenoisingEnabled: true, - modelOutputInMessagesEnabled: false, - transportConfigurations: [ - { - provider: 'twilio', - timeout: 60, - record: false, - recordingChannels: 'mono' - } - ], - voicemailDetection: { - provider: 'twilio', - voicemailDetectionTypes: ['machine_end_beep', 'machine_end_silence'], - enabled: true, - machineDetectionTimeout: 30, // Timeout in seconds - machineDetectionSpeechThreshold: 3000, // Threshold in milliseconds - machineDetectionSpeechEndThreshold: 2500, // Added this field - machineDetectionSilenceTimeout: 5000 // Timeout in milliseconds - }, - voicemailMessage: - 'You have reached our voicemail, please leave a message after the beep.', - endCallMessage: 'Thank you for calling. Goodbye!', - endCallPhrases: ['Goodbye', 'Take care'], - serverUrl: 'https://my-server-url.com', - serverUrlSecret: 'serverSecret', - analysisPlan: { - summaryPrompt: 'Summarize the call in a few sentences.', - successEvaluationPrompt: 'Did the call meet the customer’s needs?', - successEvaluationRubric: 'NumericScale', // Could also be 'PassFail' - summaryRequestTimeoutSeconds: 10, // Timeout for summary request - structuredDataRequestTimeoutSeconds: 10, // Timeout for structured data request - successEvaluationRequestTimeoutSeconds: 10, // Timeout for success evaluation request - structuredDataPrompt: 'Provide structured data from the call.', // Missing structured data prompt - structuredDataSchema: { - type: 'object', - properties: {}, // Define the properties for structured data here - required: ['field1'] // Example required fields - } - }, - artifactPlan: { - videoRecordingEnabled: true, - recordingS3PathPrefix: 's3://my-bucket/recordings/' - }, - messagePlan: { - idleMessages: ['Are you still there?'], - idleMessageMaxSpokenCount: 3, - idleTimeoutSeconds: 20 - }, - startSpeakingPlan: { - waitSeconds: 1, - smartEndpointingEnabled: true, - transcriptionEndpointingPlan: { - onPunctuationSeconds: 0.1, - onNoPunctuationSeconds: 1.5, - onNumberSeconds: 0.5 - } - }, - stopSpeakingPlan: { numWords: 50, voiceSeconds: 1, backoffSeconds: 1 }, - credentialIds: ['credential-1'] - } - } - ], - membersOverrides: { - transcriber: { - provider: 'deepgram', - model: 'nova-2', - language: 'bg', - smartFormat: true, - keywords: ['override'], - endpointing: 300 - } - } -}; - -// Create the squad -createSquad(apiUrl, apiKey, squadData) - .then((response) => console.log('Squad Response:', response)) - .catch((error) => console.error('Error:', error)); diff --git a/typescript/api/squad/delete.ts b/typescript/api/squad/delete.ts deleted file mode 100644 index 3c71808..0000000 --- a/typescript/api/squad/delete.ts +++ /dev/null @@ -1,75 +0,0 @@ -// api/squads.ts -import { DeleteSquadResponse } from '@/types/vapiAi/api/squad/delete'; - -// Function to delete a squad by ID -export async function deleteSquadById( - squadId: string, - token: string -): Promise { - const url = `https://api.vapi.ai/squad/${squadId}`; - - const options = { - method: 'DELETE', - headers: { - Authorization: `Bearer ${token}`, - 'Content-Type': 'application/json' - } - }; - - try { - const response = await fetch(url, options); - - if (!response.ok) { - const errorText = await response.text(); - throw new Error(`Error deleting squad: ${errorText}`); - } - - // Cast the response to DeleteSquadResponse type - const responseData: DeleteSquadResponse = await response.json(); - return responseData; - } catch (error) { - console.error('Failed to delete squad:', error); - throw error; - } -} - -// Example usage -const token = ''; -const squadId = 'squad-id-123'; // The ID of the squad to delete - -deleteSquadById(squadId, token) - .then((response) => console.log('Deleted Squad:', response)) - .catch((error) => console.error('Error deleting squad:', error)); - -export const exampleDeleteSquadResponse: DeleteSquadResponse = { - id: 'squad-id-123', - name: 'Example Squad', - members: [ - { - assistantId: 'assistant-id-001', - assistant: { - transcriber: { - provider: 'deepgram', - model: 'nova-2', - language: 'en' - }, - model: { - messages: [ - { content: 'Hello, how can I help you?', role: 'assistant' } - ], - provider: 'anyscale', - temperature: 0.7 - } - } - } - ], - membersOverrides: { - transcriber: { - provider: 'deepgram', - model: 'nova-2' - } - }, - orgId: 'org-id-001', - createdAt: '2023-09-07T12:00:00Z', - updatedAt: '2023-09-07T12:30:00Z' -}; diff --git a/typescript/api/squad/get.ts b/typescript/api/squad/get.ts deleted file mode 100644 index d6b84c2..0000000 --- a/typescript/api/squad/get.ts +++ /dev/null @@ -1,53 +0,0 @@ -import { GetSquadResponse } from '@/types/vapiAi/api/squad/get'; - -// Function to fetch a squad by ID -async function getSquadById( - squadId: string, - token: string -): Promise { - const url = `https://api.vapi.ai/squad/${squadId}`; - - const options = { - method: 'GET', - headers: { - Authorization: `Bearer ${token}`, - 'Content-Type': 'application/json' - } - }; - - try { - const response = await fetch(url, options); - - if (!response.ok) { - const errorText = await response.text(); - throw new Error(`Error fetching squad: ${errorText}`); - } - - const squadData: GetSquadResponse = await response.json(); // Cast response to GetSquadResponse type - return squadData; - } catch (error) { - console.error('Error fetching squad:', error); - throw error; - } -} - -// Example usage: -const token = ''; -const squadId = 'squad-id-123'; - -getSquadById(squadId, token) - .then((squad) => console.log('Squad details:', squad)) - .catch((error) => console.error('Error:', error)); - -export const exampleGetSquateResponse = { - id: 'squad-id-123', - name: 'Support Team', - members: [ - { - assistantId: 'assistant-id-001', - name: 'Support Assistant' - } - ], - createdAt: '2023-09-07T12:00:00Z', - updatedAt: '2023-09-07T12:30:00Z' -}; diff --git a/typescript/api/squad/list.ts b/typescript/api/squad/list.ts deleted file mode 100644 index a61cb2c..0000000 --- a/typescript/api/squad/list.ts +++ /dev/null @@ -1,70 +0,0 @@ -// api/squads.ts - -import { - ListSquadsQueryParams, - ListSquadsResponse -} from '@/types/vapiAi/api/squad/list'; // Ensure correct path - -// Function to list squads with optional query parameters -export async function listSquads( - token: string, // API token for authorization - queryParams: ListSquadsQueryParams = {} // Optional query parameters -): Promise { - const baseUrl = 'https://api.vapi.ai/squad'; - - // Construct query string from queryParams object - const queryString = new URLSearchParams( - queryParams as Record - ).toString(); - const url = `${baseUrl}?${queryString}`; - - const options = { - method: 'GET', - headers: { - Authorization: `Bearer ${token}`, - 'Content-Type': 'application/json' - } - }; - - try { - const response = await fetch(url, options); - - if (!response.ok) { - throw new Error(`Error fetching squads: ${response.statusText}`); - } - - // Cast the response to ListSquadsResponse - const data: ListSquadsResponse = await response.json(); - return data; - } catch (error) { - console.error('Failed to fetch squads:', error); - throw error; - } -} - -// Example usage: -const token = ''; -listSquads(token, { limit: 50, createdAtGt: '2023-01-01T00:00:00Z' }) - .then((squads) => console.log('Squads:', squads)) - .catch((error) => console.error('Error:', error)); - -// Example response -export const exampleListSquadsResponse: ListSquadsResponse = { - squads: [ - { - id: 'squad-001', - name: 'Support Squad', - members: [ - { - assistantId: 'assistant-001', - assistant: { transcriber: { provider: 'deepgram', model: 'nova' } } - } - ], - createdAt: '2023-09-07T12:00:00Z', - updatedAt: '2023-09-07T12:10:00Z', - membersOverrides: { - assistant: { voice: { provider: 'azure', voiceId: 'andrew' } } - } - } - ] -}; diff --git a/typescript/api/squad/update.ts b/typescript/api/squad/update.ts deleted file mode 100644 index a06d159..0000000 --- a/typescript/api/squad/update.ts +++ /dev/null @@ -1,113 +0,0 @@ -// api/squads.ts -import { - UpdateSquadRequest, - UpdateSquadResponse -} from '@/types/vapiAi/api/squad/update'; - -// Function to update a squad by ID -export async function updateSquad( - squadId: string, // ID of the squad to update - token: string, // API token for authorization - updateData: UpdateSquadRequest // Data for the update -): Promise { - const url = `https://api.vapi.ai/squad/${squadId}`; - - const options = { - method: 'PATCH', - headers: { - Authorization: `Bearer ${token}`, - 'Content-Type': 'application/json' - }, - body: JSON.stringify(updateData) // Send the updated squad data - }; - - try { - const response = await fetch(url, options); - - if (!response.ok) { - const errorText = await response.text(); - throw new Error(`Error updating squad: ${errorText}`); - } - - const updatedSquad: UpdateSquadResponse = await response.json(); - return updatedSquad; - } catch (error) { - console.error('Failed to update squad:', error); - throw error; - } -} - -// Example usage -const token = ''; -const squadId = 'squad-id-123'; // The ID of the squad to update - -const updateData: UpdateSquadRequest = { - name: 'New Squad Name', - members: [ - { - assistantId: 'assistant-id-001', - assistant: { - transcriber: { - provider: 'deepgram', - model: 'nova-2', - language: 'en' - }, - model: { - messages: [{ content: 'Welcome to the call.', role: 'assistant' }], - provider: 'anyscale', - temperature: 0.7 - }, - voice: { - provider: 'azure', - voiceId: 'andrew', - speed: 1.25 - } - }, - assistantOverrides: { - voice: { - speed: 1.1 - } - } - } - ], - membersOverrides: { - assistant: { - transcriber: { provider: 'deepgram', model: 'nova-2' } - } - } -}; - -updateSquad(squadId, token, updateData) - .then((updatedSquad) => console.log('Updated Squad:', updatedSquad)) - .catch((error) => console.error('Error updating squad:', error)); - -// Example response after successful update -export const exampleUpdateSquadResponse: UpdateSquadResponse = { - id: 'squad-id-123', - name: 'New Squad Name', - members: [ - { - assistantId: 'assistant-id-001', - assistant: { - transcriber: { provider: 'deepgram', model: 'nova-2', language: 'en' }, - model: { - messages: [{ content: 'Welcome to the call.', role: 'assistant' }], - provider: 'anyscale', - temperature: 0.7 - }, - voice: { provider: 'azure', voiceId: 'andrew', speed: 1.25 } - }, - assistantOverrides: { - voice: { speed: 1.1 } - } - } - ], - membersOverrides: { - assistant: { - transcriber: { provider: 'deepgram', model: 'nova-2' } - } - }, - orgId: 'org-id-001', - createdAt: '2023-09-07T12:00:00Z', - updatedAt: '2023-09-07T12:30:00Z' -}; diff --git a/typescript/api/tools/create.ts b/typescript/api/tools/create.ts deleted file mode 100644 index d819897..0000000 --- a/typescript/api/tools/create.ts +++ /dev/null @@ -1,104 +0,0 @@ -// api/tools.ts - -import { ToolMessageType, MessageRole } from '@/types/vapiAi/api/calls/create'; -import { - CreateToolRequest, - ConditionOperator, - ToolType, - CreateToolResponse -} from '@/types/vapiAi/api/tools/create'; - -// Function to create a tool -export async function createTool(token: string, toolData: CreateToolRequest) { - const url = 'https://api.vapi.ai/tool'; - - const options = { - method: 'POST', - headers: { - Authorization: `Bearer ${token}`, - 'Content-Type': 'application/json' - }, - body: JSON.stringify(toolData) - }; - - try { - const response = await fetch(url, options); - - if (!response.ok) { - const errorText = await response.text(); - throw new Error(`Error creating tool: ${errorText}`); - } - - const responseData = await response.json(); - console.log('Tool created successfully:', responseData); - return responseData; - } catch (error) { - console.error('Error creating tool:', error); - throw error; - } -} - -// Example usage -const token = ''; -const toolData: CreateToolRequest = { - async: false, - messages: [ - { - type: ToolMessageType.ToolMessageStart, - content: 'Processing your request, please wait...', - role: MessageRole.Assistant - } - ], - type: ToolType.DTMF, - function: { - name: 'DTMF Tool', - description: 'Tool for detecting DTMF tones', - parameters: { - type: 'object', - properties: {}, - required: ['param1'] - } - }, - server: { - timeoutSeconds: 20, - url: 'https://example.com/dtmf-tool', - secret: 'superSecret' - } -}; - -// Call the function -createTool(token, toolData) - .then((tool) => console.log('Tool Created:', tool)) - .catch((error) => console.error('Tool Creation Error:', error)); - -const exampleToolResponse: CreateToolResponse = { - async: false, - messages: [ - { - type: ToolMessageType.ToolMessageStart, - content: 'Processing your request, please wait...', - role: MessageRole.Assistant - } - ], - type: ToolType.DTMF, - id: 'tool-id-123', - orgId: 'org-id-123', - createdAt: '2023-11-07T05:31:56Z', - updatedAt: '2023-11-07T05:31:56Z', - function: { - name: 'DTMF Tool', - description: 'Tool for detecting DTMF tones', - parameters: { - type: 'object', - properties: {}, - required: ['param1'] - } - }, - server: { - timeoutSeconds: 20, - url: 'https://example.com/dtmf-tool', - secret: 'superSecret' - } -}; - -console.log(exampleToolResponse); diff --git a/typescript/api/tools/delete.ts b/typescript/api/tools/delete.ts deleted file mode 100644 index 7a2c628..0000000 --- a/typescript/api/tools/delete.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { DeleteToolResponse } from '@/types/vapiAi/api/tools/delete'; - -const options = { - method: 'DELETE', - headers: { - Authorization: 'Bearer ' - } -}; - -// Perform the API call to delete a tool by ID -fetch('https://api.vapi.ai/tool/{id}', options) - .then((response) => { - if (!response.ok) { - throw new Error(`Error deleting tool: ${response.statusText}`); - } - return response.json(); - }) - .then((deleteResponse: DeleteToolResponse) => { - console.log('Tool deleted successfully:', deleteResponse); - }) - .catch((error) => console.error('Error:', error)); - -export const exampleToolDeleteResponse = { - id: 'tool-123', - status: 'deleted', - orgId: 'org-123', - deletedAt: '2023-11-07T05:45:00Z' -}; diff --git a/typescript/api/tools/get.ts b/typescript/api/tools/get.ts deleted file mode 100644 index 6c35f49..0000000 --- a/typescript/api/tools/get.ts +++ /dev/null @@ -1,77 +0,0 @@ -// api/tools.ts - -import { ToolMessageType, MessageRole } from '@/types/vapiAi/api/calls/create'; -import { ToolType } from '@/types/vapiAi/api/tools/create'; -import { GetToolResponse } from '@/types/vapiAi/api/tools/get'; - -// Function to get a tool by its ID -export async function getToolById( - token: string, - toolId: string -): Promise { - const url = `https://api.vapi.ai/tool/${toolId}`; - - const options = { - method: 'GET', - headers: { - Authorization: `Bearer ${token}`, - 'Content-Type': 'application/json' - } - }; - - try { - const response = await fetch(url, options); - - if (!response.ok) { - const errorText = await response.text(); - throw new Error(`Error fetching tool: ${errorText}`); - } - - const toolData: GetToolResponse = await response.json(); - console.log('Tool fetched successfully:', toolData); - return toolData; - } catch (error) { - console.error('Error fetching tool:', error); - throw error; - } -} - -// Example usage -const token = ''; -const toolId = 'tool-id-123'; - -getToolById(token, toolId) - .then((tool) => console.log('Tool Data:', tool)) - .catch((error) => console.error('Error fetching tool:', error)); - -const exampleToolResponse: GetToolResponse = { - id: '23423adasd', - async: false, - messages: [ - { - type: ToolMessageType.ToolMessageStart, - content: 'Processing your request, please wait...', - role: MessageRole.Assistant - } - ], - type: ToolType.DTMF, // Use enum value here instead of a string id: 'tool-id-123', - orgId: 'org-id-123', - createdAt: '2023-11-07T05:31:56Z', - updatedAt: '2023-11-07T05:31:56Z', - function: { - name: 'DTMF Tool', - description: 'Tool for detecting DTMF tones', - parameters: { - type: 'object', - properties: {}, - required: ['param1'] - } - }, - server: { - timeoutSeconds: 20, - url: 'https://example.com/dtmf-tool', - secret: 'superSecret' - } -}; - -console.log(exampleToolResponse); diff --git a/typescript/api/tools/list.ts b/typescript/api/tools/list.ts deleted file mode 100644 index 35f78e2..0000000 --- a/typescript/api/tools/list.ts +++ /dev/null @@ -1,59 +0,0 @@ -import { ListToolsResponse } from '@/types/vapiAi/api/tools/list'; - -const options = { - method: 'GET', - headers: { - Authorization: 'Bearer ', - 'Content-Type': 'application/json' - } -}; - -// API call to list tools -fetch('https://api.vapi.ai/tool', options) - .then((response) => response.json()) - .then((data: ListToolsResponse) => { - console.log('Total tools:', data.totalCount); - console.log('Tools:', data.tools); - }) - .catch((error) => console.error('Error fetching tools:', error)); - -export const exampleToolListResponse = { - tools: [ - { - async: false, - messages: [ - { - type: 'request-start', - content: 'Starting the DTMF tool', - conditions: [ - { - value: 'start', - operator: 'eq', - param: 'trigger' - } - ] - } - ], - type: 'dtmf', - id: 'tool-123', - orgId: 'org-123', - createdAt: '2023-11-07T05:31:56Z', - updatedAt: '2023-11-07T05:31:56Z', - function: { - name: 'DTMF Function', - description: 'Detect DTMF tones', - parameters: { - type: 'object', - properties: {}, - required: ['tones'] - } - }, - server: { - timeoutSeconds: 20, - url: 'https://server.url', - secret: 'superSecretKey' - } - } - ], - totalCount: 1 -}; diff --git a/typescript/api/tools/update.ts b/typescript/api/tools/update.ts deleted file mode 100644 index 7a398d1..0000000 --- a/typescript/api/tools/update.ts +++ /dev/null @@ -1,77 +0,0 @@ -import { UpdateToolResponse } from '@/types/vapiAi/api/tools/update'; - -const options = { - method: 'PATCH', - headers: { - Authorization: 'Bearer ', - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ - async: false, - messages: [ - { - type: 'request-start', - content: 'Starting the tool', - conditions: [{ value: 'start', operator: 'eq', param: 'trigger' }] - } - ], - function: { - name: 'Custom Tool Function', - description: 'This is a custom tool function.', - parameters: { - type: 'object', - properties: {}, - required: ['parameter1'] - } - }, - server: { - timeoutSeconds: 20, - url: 'https://custom-server.url', - secret: 'superSecretKey' - } - }) -}; - -// Perform the API call -fetch('https://api.vapi.ai/tool/{id}', options) - .then((response) => response.json()) - .then((updatedTool: UpdateToolResponse) => { - console.log('Updated Tool:', updatedTool); - }) - .catch((error) => console.error('Error updating tool:', error)); - -export const exampleToolUpdateResponse = { - async: false, - messages: [ - { - type: 'request-start', - content: 'Starting the tool', - conditions: [ - { - value: 'start', - operator: 'eq', - param: 'trigger' - } - ] - } - ], - type: 'dtmf', - id: 'tool-123', - orgId: 'org-123', - createdAt: '2023-11-07T05:31:56Z', - updatedAt: '2023-11-07T05:32:00Z', - function: { - name: 'Custom Tool Function', - description: 'This is a custom tool function.', - parameters: { - type: 'object', - properties: {}, - required: ['parameter1'] - } - }, - server: { - timeoutSeconds: 20, - url: 'https://custom-server.url', - secret: 'superSecretKey' - } -}; diff --git a/typescript/index.ts b/typescript/index.ts deleted file mode 100644 index 82ee6eb..0000000 --- a/typescript/index.ts +++ /dev/null @@ -1,82 +0,0 @@ -import axios from 'axios'; - -// Base URL for VAPI API (replace with actual URL from VAPI docs) -const VAPI_BASE_URL = 'https://api.vapi.ai'; - -// API key or token for VAPI API (replace with your actual API key/token) -const VAPI_API_KEY = 'YOUR_VAPI_API_KEY'; - -/** - * Sync a cloned voice with VAPI. - * @param customerId - The unique ID of the customer - * @param voiceId - The cloned voice ID from ElevenLabs - * @returns A promise that resolves when the sync is complete - */ -export const syncVoiceWithVAPI = async ( - customerId: string, - voiceId: string -): Promise => { - const url = `${VAPI_BASE_URL}/vapi/voices/sync`; - - const payload = { - customerId, - voiceId - }; - - try { - const response = await axios.post(url, payload, { - headers: { - Authorization: `Bearer ${VAPI_API_KEY}`, - 'Content-Type': 'application/json' - } - }); - - if (response.status === 200 || response.status === 201) { - console.log( - `Voice ID ${voiceId} synced successfully for customer ${customerId}` - ); - } else { - console.error( - `Failed to sync voice for customer ${customerId}: ${response.statusText}` - ); - throw new Error(`Failed to sync voice: ${response.statusText}`); - } - } catch (error) { - console.error('Error syncing voice with VAPI:', error); - throw new Error('Sync with VAPI failed.'); - } -}; - -/** - * Fetch all cloned voices for a specific customer from VAPI. - * @param customerId - The unique ID of the customer - * @returns A promise that resolves with an array of voices for the customer - */ -export const fetchCustomerVoices = async ( - customerId: string -): Promise => { - const url = `${VAPI_BASE_URL}/vapi/voices/customer/${customerId}`; - - try { - const response = await axios.get(url, { - headers: { - Authorization: `Bearer ${VAPI_API_KEY}`, - 'Content-Type': 'application/json' - } - }); - - if (response.status === 200) { - const voices = response.data.voices; - console.log(`Fetched ${voices.length} voices for customer ${customerId}`); - return voices; - } else { - console.error( - `Failed to fetch voices for customer ${customerId}: ${response.statusText}` - ); - throw new Error(`Failed to fetch voices: ${response.statusText}`); - } - } catch (error) { - console.error('Error fetching customer voices from VAPI:', error); - throw new Error('Fetch customer voices failed.'); - } -}; diff --git a/typescript/syncCustomerVoice.ts b/typescript/syncCustomerVoice.ts deleted file mode 100644 index 480ab79..0000000 --- a/typescript/syncCustomerVoice.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { fetchCustomerVoices, syncVoiceWithVAPI } from '.'; - -/** - * Sync the cloned voice with VAPI for the given customer - * @param customerId - The unique ID of the customer - * @param voiceId - The cloned voice ID from ElevenLabs - */ -async function syncCustomerVoiceWithVAPI( - customerId: string, - voiceId: string -): Promise { - try { - // Sync the cloned voice with VAPI - await syncVoiceWithVAPI(customerId, voiceId); - console.log( - `Successfully synced voice ${voiceId} for customer ${customerId}` - ); - } catch (error) { - console.error( - `Error syncing voice ${voiceId} for customer ${customerId}:`, - error - ); - throw new Error('Failed to sync voice with VAPI'); - } -} - -/** - * Fetch only the voices for the authenticated customer from VAPI - * @param customerId - The unique ID of the customer - * @returns List of voice data for that customer - */ -async function getCustomerVoices(customerId: string): Promise { - try { - // Fetch voices for this customer from VAPI - const voices = await fetchCustomerVoices(customerId); - console.log(`Fetched ${voices.length} voices for customer ${customerId}`); - return voices; - } catch (error) { - console.error(`Error fetching voices for customer ${customerId}:`, error); - throw new Error('Failed to fetch customer voices'); - } -} diff --git a/typescript/utils/createSalesScript.ts b/typescript/utils/createSalesScript.ts deleted file mode 100644 index da557a7..0000000 --- a/typescript/utils/createSalesScript.ts +++ /dev/null @@ -1,25 +0,0 @@ -function createAssistantMessages(salesScript: string): Message[] { - const scriptLines = salesScript - .split('\n') - .filter((line) => line.trim() !== ''); - - const messages: Message[] = [ - { - role: 'system', - content: `You're a sales agent following this script: - ${scriptLines.join('\n')} - Follow this script while adapting to the conversation naturally.` - } - ]; - - // Add script lines as assistant messages - scriptLines.forEach((line, index) => { - messages.push({ - role: 'assistant', - content: line, - type: index === 0 ? 'request-start' : undefined - }); - }); - - return messages; -}