Voice Integration
Add voice calling capabilities to Linktor using providers like Twilio or Vonage. Build IVR systems, enable click-to-call, and integrate voice with your AI bots.
Overview
The Voice integration enables you to:
- Make and receive phone calls programmatically
- Build interactive voice response (IVR) systems
- Convert speech to text for AI processing
- Generate dynamic text-to-speech responses
- Record calls for quality assurance
- Transfer calls to human agents
- Handle conference calls
Prerequisites
Before configuring Voice in Linktor, you'll need:
- Voice Provider Account: Twilio or Vonage account with voice capability
- Phone Number: A phone number with voice capability
- Webhook URL: Publicly accessible HTTPS endpoint
Supported Providers
| Provider | Features | Best For |
|---|---|---|
| Twilio | Full-featured, global, STT/TTS | Enterprise, global reach |
| Vonage | WebRTC support, competitive pricing | Web-based calling |
| Plivo | Affordable, developer-friendly | Cost-sensitive applications |
Configuration in Linktor
Twilio Voice Setup
Step 1: Get Twilio Voice Credentials
- Sign up at twilio.com
- From the Console, note your:
- Account SID
- Auth Token
- Buy a phone number with Voice capability
- Note the phone number
Step 2: Add Channel in Dashboard
- Go to Settings → Channels in Linktor
- Click Add Channel and select Voice
- Choose Twilio as the provider
- Fill in the configuration:
| Field | Description |
|---|---|
| Name | Display name (e.g., "Support Hotline") |
| Account SID | Your Twilio Account SID |
| Auth Token | Your Twilio Auth Token |
| Phone Number | Your Twilio voice number (E.164 format) |
| Default Voice | TTS voice (e.g., "Polly.Joanna") |
| Default Language | Speech recognition language |
- Click Save to create the channel
Step 3: Configure Twilio Webhook
- Go to Phone Numbers → Manage → Active Numbers
- Select your phone number
- Under Voice & Fax:
- A Call Comes In: configure this only after exposing a voice inbound callback in your deployment
- Call Status Changes: configure this only after exposing a voice status callback in your deployment
Vonage Voice Setup
Step 1: Create Vonage Voice Application
- Sign up at vonage.com
- Go to Applications and create a new application
- Enable Voice capability
- Set Answer URL and Event URL to your Linktor webhooks
- Generate and download the private key
- Link a phone number to the application
Step 2: Add Channel in Dashboard
| Field | Description |
|---|---|
| Name | Display name for this channel |
| Application ID | Your Vonage Application ID |
| Private Key | Your Vonage private key content |
| Phone Number | Your Vonage voice number |
API Usage
Making Outbound Calls
Basic Outbound Call
import { Linktor } from '@linktor/sdk'
const client = new Linktor({ apiKey: 'YOUR_API_KEY' })
const call = await client.voice.calls.create({
channelId: 'ch_voice_123',
to: '+5511999999999',
flow: 'outbound_welcome' // IVR flow to execute
})
console.log(`Call initiated: ${call.id}, status: ${call.status}`)
Call with Custom TwiML/NCCO
// Twilio TwiML
const call = await client.voice.calls.create({
channelId: 'ch_voice_123',
to: '+5511999999999',
twiml: `
<Response>
<Say voice="Polly.Joanna">Hello! This is a reminder about your appointment tomorrow at 3 PM.</Say>
<Gather input="speech dtmf" timeout="5" numDigits="1">
<Say>Press 1 to confirm, or 2 to reschedule.</Say>
</Gather>
</Response>
`
})
Call with Text-to-Speech
const call = await client.voice.calls.create({
channelId: 'ch_voice_123',
to: '+5511999999999',
actions: [
{
action: 'say',
text: 'Hello! Your order has been shipped and will arrive tomorrow.',
voice: 'Polly.Joanna',
language: 'en-US'
},
{
action: 'say',
text: 'Press any key to repeat this message, or hang up.',
voice: 'Polly.Joanna'
},
{
action: 'gather',
input: ['dtmf'],
timeout: 10,
onGather: 'repeat_message'
}
]
})
Handling Inbound Calls
IVR Flow Example
Define an IVR flow that handles incoming calls:
// In your Linktor flow configuration
{
"name": "main_ivr",
"trigger": {
"type": "voice.inbound",
"channelId": "ch_voice_123"
},
"steps": [
{
"id": "welcome",
"action": "say",
"text": "Welcome to Acme Support. ",
"voice": "Polly.Joanna"
},
{
"id": "menu",
"action": "gather",
"input": ["dtmf", "speech"],
"timeout": 5,
"speechTimeout": "auto",
"hints": ["sales", "support", "billing"],
"prompt": {
"action": "say",
"text": "For sales, press 1 or say sales. For support, press 2 or say support. For billing, press 3 or say billing."
},
"onGather": "route_call"
},
{
"id": "route_call",
"action": "conditional",
"conditions": [
{
"if": "{{digits}} == '1' || {{speech}} contains 'sales'",
"then": "transfer_sales"
},
{
"if": "{{digits}} == '2' || {{speech}} contains 'support'",
"then": "transfer_support"
},
{
"if": "{{digits}} == '3' || {{speech}} contains 'billing'",
"then": "transfer_billing"
}
],
"default": "invalid_option"
},
{
"id": "transfer_sales",
"action": "dial",
"number": "+5511888888888",
"callerId": "{{channel.phoneNumber}}",
"timeout": 30,
"onNoAnswer": "voicemail"
}
]
}
Speech Recognition (STT)
Gather Speech Input
await client.voice.calls.update(callId, {
actions: [
{
action: 'say',
text: 'Please describe your issue after the beep.'
},
{
action: 'gather',
input: ['speech'],
speechTimeout: 'auto',
language: 'en-US',
hints: ['refund', 'shipping', 'product', 'account'],
onGather: async (result) => {
const transcription = result.speechResult
// Process with AI
const response = await processWithAI(transcription)
return {
action: 'say',
text: response
}
}
}
]
})
Text-to-Speech (TTS)
Available Voices
// List available voices
const voices = await client.voice.voices.list({
channelId: 'ch_voice_123',
language: 'en-US'
})
// Twilio Polly voices
// - Polly.Joanna (female, US)
// - Polly.Matthew (male, US)
// - Polly.Amy (female, UK)
// - Polly.Brian (male, UK)
// - Polly.Camila (female, Portuguese)
Using Different Voices
await client.voice.calls.update(callId, {
actions: [
{
action: 'say',
text: 'Hello, this is your English assistant.',
voice: 'Polly.Joanna',
language: 'en-US'
},
{
action: 'say',
text: 'Ol\u00e1, sou sua assistente em portugu\u00eas.',
voice: 'Polly.Camila',
language: 'pt-BR'
}
]
})
Call Recording
Enable Recording
const call = await client.voice.calls.create({
channelId: 'ch_voice_123',
to: '+5511999999999',
record: true,
recordingStatusCallback: 'https://api.your-domain.com/your-voice-recording-callback',
flow: 'outbound_call'
})
Retrieve Recordings
const recordings = await client.voice.recordings.list({
callId: call.id
})
recordings.forEach(recording => {
console.log(`Recording: ${recording.url}, duration: ${recording.duration}s`)
})
Call Transfer
Warm Transfer
await client.voice.calls.update(callId, {
actions: [
{
action: 'say',
text: 'Please hold while I transfer you to an agent.'
},
{
action: 'dial',
number: '+5511888888888',
callerId: '{{caller.number}}',
timeout: 30,
whisper: {
action: 'say',
text: 'Incoming call from {{caller.number}} regarding order issue.'
}
}
]
})
Cold Transfer
await client.voice.calls.transfer(callId, {
to: '+5511888888888',
announce: 'Transferring to support team.'
})
AI Voice Bot Integration
import { Linktor } from '@linktor/sdk'
const client = new Linktor({ apiKey: 'YOUR_API_KEY' })
// Handle incoming call with AI
client.voice.on('call.answered', async (call) => {
await client.voice.calls.update(call.id, {
actions: [
{
action: 'say',
text: 'Hello! I am your AI assistant. How can I help you today?'
},
{
action: 'gather',
input: ['speech'],
speechTimeout: 'auto',
onGather: async (result) => {
// Send to AI bot
const aiResponse = await client.bots.chat({
botId: 'bot_ai_123',
message: result.speechResult,
context: {
channel: 'voice',
callId: call.id,
caller: call.from
}
})
return {
action: 'say',
text: aiResponse.message
}
}
}
]
})
})
Webhook Events
Call Events
// Incoming call event
{
"event": "voice.call.incoming",
"data": {
"callId": "call_abc123",
"channelId": "ch_voice_123",
"direction": "inbound",
"from": "+5511999999999",
"to": "+5511888888888",
"status": "ringing",
"timestamp": "2024-01-15T10:30:00Z"
}
}
// Call answered
{
"event": "voice.call.answered",
"data": {
"callId": "call_abc123",
"status": "in-progress",
"answeredBy": "human", // or "machine"
"timestamp": "2024-01-15T10:30:05Z"
}
}
// Call completed
{
"event": "voice.call.completed",
"data": {
"callId": "call_abc123",
"status": "completed",
"duration": 125,
"recordingUrl": "https://...",
"timestamp": "2024-01-15T10:32:10Z"
}
}
DTMF Events
{
"event": "voice.dtmf",
"data": {
"callId": "call_abc123",
"digits": "1",
"timestamp": "2024-01-15T10:30:15Z"
}
}
Webhook Setup
Webhook URL Format
Voice inbound callbacks are not exposed by the default API routes yet. Use a deployment-specific callback URL only if you add that route.
Webhook Security
Twilio:
- Validates
X-Twilio-Signatureheader - Use Request Validator
Vonage:
- Validates JWT signature
- Verify
Authorizationheader
Common Issues and Troubleshooting
"Call failed to connect"
Possible causes:
- Invalid phone number
- Number not voice-capable
- Carrier issues
- Insufficient balance
Solution:
- Verify number format (E.164)
- Check number capabilities in provider dashboard
- Test with different numbers
- Check account balance
Poor Audio Quality
Possible causes:
- Network latency
- Codec issues
- TTS voice quality
Solution:
- Use high-quality TTS voices (Polly Neural)
- Check network connectivity
- Use appropriate audio codecs
Speech Recognition Failures
Possible causes:
- Background noise
- Accent not recognized
- Wrong language configured
Solution:
- Add speech hints for expected words
- Use appropriate language model
- Consider gathering DTMF as fallback
Webhook Timeout
Possible causes:
- Slow webhook response (>15 seconds for Twilio)
- Complex processing
Solution:
- Respond immediately with TwiML
- Use async processing for complex logic
- Implement proper caching
Recording Not Available
Possible causes:
- Recording not enabled
- Call too short
- Storage issues
Solution:
- Verify recording is enabled
- Check minimum duration requirements
- Verify storage configuration
Best Practices
-
Always Identify Yourself: State who is calling at the start of outbound calls.
-
Provide Options: Always give callers a way to reach a human.
-
Handle Errors Gracefully: Have fallback flows for unrecognized input.
-
Keep IVR Menus Short: Maximum 3-4 options per menu level.
-
Use Appropriate Voices: Match voice gender, accent, and language to your audience.
-
Record with Consent: Announce recording at the start of calls where required.
-
Monitor Call Quality: Track metrics like answer rates, duration, and drop-offs.
-
Test Regularly: Call your numbers regularly to verify they're working.
Compliance
TCPA (US)
- Get prior express consent before calling
- Honor Do Not Call requests
- Follow calling hour restrictions (8am-9pm local)
- Provide opt-out mechanism
Recording Consent
- One-party consent states: Only one party needs to consent
- Two-party consent states: All parties must consent
- Always announce recording to be safe
Rate Limits
| Provider | Concurrent Calls | Calls per Second |
|---|---|---|
| Twilio | Based on CPS | 1 CPS default (can increase) |
| Vonage | Based on account | 1 CPS default |
Pricing Considerations
Voice calls are billed by:
- Per-minute rates: Varies by destination
- Phone number rental: Monthly fee
- Recording storage: Per minute stored
- Transcription: Per minute transcribed
Next Steps
- Flows - Build complex IVR systems
- AI Bots - Create AI-powered voice assistants
- API Reference - Review available API resources
- Voice Channel - Review recording best practices