Kallglot does not currently provide official SDKs. The helper functions in these examples, such as createKallglotSession(...), represent ordinary HTTPS calls to the API.
Copy
Ask AI
import express from 'express';import twilio from 'twilio';const app = express();const VoiceResponse = twilio.twiml.VoiceResponse;app.post('/webhooks/twilio/voice', express.urlencoded({ extended: false }), async (req, res) => { const { CallSid, From, To, Direction } = req.body; try { // Create a Kallglot session const session = await createKallglotSession({ mode: 'bidirectional_translation', source_language: 'de', // Customer's language target_language: 'en', // Agent's language provider: { type: 'twilio', call_sid: CallSid }, metadata: { from: From, to: To, direction: Direction } }); // Generate TwiML to connect the call to Kallglot const response = new VoiceResponse(); // Optional: Play a greeting response.say({ language: 'de-DE' }, 'Willkommen. Ihr Anruf wird übersetzt.'); // Connect to Kallglot media stream const connect = response.connect(); connect.stream({ url: session.stream.url, track: 'both_tracks' // Send both inbound and outbound audio }).parameter({ name: 'token', value: session.stream.token }).parameter({ name: 'session_id', value: session.id }); res.type('text/xml').send(response.toString()); } catch (error) { console.error('Failed to create session:', error); // Fallback: connect to agent without translation const response = new VoiceResponse(); response.say('Translation is temporarily unavailable. Connecting you now.'); response.dial('+14155550123'); // Your agent's number res.type('text/xml').send(response.toString()); }});app.listen(3000);
Always use track: 'both_tracks' to send both inbound and outbound audio to Kallglot. This ensures proper speaker separation.
Handle race conditions
The Twilio webhook must respond quickly (within 15 seconds). Create the session and respond immediately:
Copy
Ask AI
// Good: Create session in webhookconst session = await createKallglotSession({...});res.type('text/xml').send(response.toString());// Bad: Doing too much in webhookconst session = await createKallglotSession({...});await db.save(session); // Too slow!await analytics.track({...}); // Even slower!res.type('text/xml').send(response.toString());
Clean up on call end
End Kallglot sessions when calls complete to stop billing: