LeadSmart API integrates with several third-party services to extend its functionality. This document outlines the available integrations and how they are implemented.WhatsApp Integration#
The API integrates with WhatsApp to enable messaging with clients.Implementation#
Library: @whiskeysockets/baileys
src/messaging/whatsapp.service.ts
src/messaging/handlers.ts
Features#
Multiple WhatsApp instances per company
Message sending and receiving
Connection status monitoring
Message history management
Configuration#
WhatsApp instances are configured at the company level, with each instance representing a WhatsApp account. The connection is established using WhatsApp Web's QR code authentication flow.Health Checks#
The system performs regular health checks on WhatsApp connections using a scheduled job:Google Calendar Integration#
The API integrates with Google Calendar to synchronize appointments.Implementation#
src/integrations/google/calendar.service.ts
src/integrations/google/auth.service.ts
src/integrations/routes/google.routes.ts
Features#
Google Calendar authentication via OAuth
Event creation and synchronization
Webhook notifications for real-time updates
Authentication Flow#
1.
User initiates OAuth flow from frontend
2.
Backend receives authorization code
3.
Backend exchanges code for access and refresh tokens
4.
Tokens are stored in the database (IntegrationToken model)
5.
Refresh tokens are used to maintain access
Webhook Management#
The API registers webhooks with Google Calendar to receive real-time updates. Webhooks must be renewed periodically to remain active:OpenAI Integration#
The API integrates with OpenAI to provide AI-powered conversations and analysis.Implementation#
src/services/openai.service.ts
src/services/openaiBot.service.ts
src/controllers/openaiBot.controller.ts
Features#
Multiple AI bots per company
Customizable bot personalities via system prompts
Model selection (gpt-4, gpt-3.5-turbo, etc.)
Temperature and parameter tuning
Context management for conversations
Vector storage for semantic search
Configuration#
OpenAI bots are configured at the company level with the following parameters:API credentials (API key, organization ID)
System prompt for bot personality
Chatwoot Integration#
The API integrates with Chatwoot for customer support management.Implementation#
src/services/chatwootAccount.service.ts
src/controllers/chatwootAccount.controller.ts
Features#
Chatwoot account management
Conversation synchronization
Configuration#
Chatwoot integration is configured at the company level with the following parameters:Integration Token Management#
All third-party service tokens are managed through the IntegrationToken
model, which securely stores:Tokens are automatically refreshed when expired, and services handle authentication failures gracefully.Implementing New Integrations#
To add a new integration to LeadSmart API:1.
Create service files in src/integrations/[service-name]/
2.
Implement authentication flow and token storage
3.
Create controller and route files
4.
Add necessary models or extend existing models
5.
Implement error handling for integration-specific errors
6.
Document the integration in this guide
Security Considerations#
All API keys and tokens are stored encrypted in the database
Refresh flows handle token expiration gracefully
Rate limiting is implemented to prevent excessive API calls
Error handling preserves system stability during integration failures
Modificado em 2025-04-24 22:32:01