AdvancedIntegrations
Advanced

Integrations and Extensions

Learn how to connect SparkChat with third-party services, enable webhooks, and extend functionality through voice input and external tools.

{
  "event": "message.created",
  "chatId": "chat_12345",
  "message": "Hello from SparkChat!",
  "timestamp": "2024-10-15T10:30:00Z"
}
const query = 'SELECT Id, Name FROM Account LIMIT 10';
const response = await fetch('https://api.example.com/salesforce/query', {
  method: 'POST',
  headers: { 'Authorization': `Bearer ${salesforceToken}` },
  body: JSON.stringify({ query })
});

Overview

SparkChat supports seamless integrations with external services, allowing you to extend its AI capabilities beyond the core platform. Connect to third-party APIs for custom data sources, set up webhooks for real-time event notifications, enable voice input and text-to-speech (TTS) for hands-free interactions, and integrate with enterprise systems for scalable deployments.

Use these features to build workflows that pull data from CRMs, databases, or collaboration tools, and push SparkChat outputs to your preferred destinations.

Connecting to External APIs

Connect SparkChat to any REST API by using the built-in API tool in workflows or agents. Provide the endpoint URL, headers, and parameters to fetch or send data dynamically.

Store sensitive credentials like {API_KEY} in SparkChat's secure environment variables.

Here is an example using the CodeGroup component for multi-language HTTP requests:

const response = await fetch('https://api.example.com/users', {
  method: 'GET',
  headers: {
    'Authorization': `Bearer ${process.env.API_KEY}`,
    'Content-Type': 'application/json'
  }
});
const data = await response.json();
console.log(data);
path
userIdstring
Required

The unique identifier for the user to fetch.

header
Authorizationstring
Required

Bearer token for authentication.

Setting Up Webhooks

Webhooks enable SparkChat to send real-time payloads to your server on events like message completions or agent responses.

Create Webhook Endpoint

Set up a public HTTPS endpoint on your server to receive POST requests.

Configure in SparkChat

Navigate to Workflows > Integrations, add your webhook URL: https://your-webhook-url.com/sparkchat.

Select Events

Choose events like message.created or agent.response.

Test and Verify

Trigger a test event and verify the payload.

Example webhook payload:

Voice and TTS Features

Enable voice input for natural conversations and TTS for AI responses. Supports multiple platforms.

Use the MediaRecorder API for input and Web Speech API for TTS.

// Record and send audio
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
const mediaRecorder = new MediaRecorder(stream);
mediaRecorder.ondataavailable = (event) => {
  // Send blob to SparkChat API
  const formData = new FormData();
  formData.append('audio', event.data);
  fetch('https://api.example.com/voice/transcribe', {
    method: 'POST',
    body: formData
  });
};

Enterprise Integrations

For custom deployments, integrate SparkChat with systems like Salesforce, Slack, or on-premise databases.

Always validate incoming webhooks with HMAC signatures to prevent unauthorized access.