Leadsmart
  1. Docs
Leadsmart
  • API Reference
  • Docs
    • LeadSmart API Documentation
    • Services
    • Middleware
    • Integrations
    • Database
    • Architecture
  • Authentication
    • Register
      POST
    • Update User
      PATCH
    • Login
      POST
    • Logout
      POST
    • Reset Password
      POST
    • Change Email
      POST
    • Request Password Reset
      POST
    • Request Email Change
      POST
    • Upload Profile Picture
      POST
    • Verify Email
      GET
  • Companies
    • Create Company
      POST
    • Join Company
      POST
    • Get All User Company
      GET
    • Get user Company
      GET
    • Update Company
      PATCH
    • Deactivate Company
      PATCH
    • Activate Company
      PATCH
    • Reset Invite Code
      PATCH
  • Members
    • Create a Member
      POST
    • Get All Member
      GET
    • Get Single Member
      GET
    • Update Member
      PATCH
    • Deactivate Member
      PATCH
    • Activate Member
      PATCH
  • Agendas
    • Create Company Agenda
    • Get All Agendas
    • Get Single Agenda
    • Get Agenda with Appoint
    • Get Available Slots
    • Update Agenda
    • Delete Agenda
    • Activate Agenda
    • Create Agenda Integration
    • Delete Agenda Integration
  • Appointments
    • Create Appointment
    • Get All Appointments
    • Get Appointment
    • Add Members
    • Delete Members
    • Update Appointment
    • Update Date
  • Plans
    • Get Single Plan
    • Get All Plans
    • Create Plan
    • Delete Plan
    • Update Plan
  • Plans Duration
    • Get Single Plan Duration
    • Create Plan Duration
    • Delete Plan Duration
    • Update Plan Duration
  • Company Roles
    • Get Single Company Role
    • Get All Company Roles
    • Create Company Role
    • Delete Company Role
    • Update Company Role
  • Clients
    • Get All Clients
    • Create Client
    • Get Client By Id
    • Update Client
    • Delete Client
  • Client Threads
    • Get Thread By Id
    • Get All By Client
    • Get All By Instance
    • Update Thread
    • Delete Client Thread
  • Admin
    • Get All Plans Duration
    • Get All Plans
    • Create Plan
    • Get All Members
    • Get All Companies
  • Chatwoot Accounts
    • Get Chatwoot Account
    • Update Chatwoot Account
    • Delete Chatwoot Account
    • Create Chatwoot Account
  • Integrations
    • Tokens
      • Fetch All Tokens
      • Fetch Token
      • Update Token
      • Remove Token
    • Google
      • Create Auth URL
      • Regenerate Auth URL
      • Renew Google Webhook
    • External Calendar
      • Create External Event
      • Update External Event
      • Delete External Event
      • Validate Calendar Id
      • Fetch External Calendars
  • AI Keys
    • Get All AI Keys
    • Get AI Keys By ID
    • Create AI Key
    • Update AI Key
    • Delete AI Key
  • Agent Prompts
    • Get All Agent Prompts
    • Get Agent Prompt By ID
    • Create Agent Prompt
    • Update Agent Prompt
    • Delete Agent Prompt
  • Agent Configuration
    • Get All Agent Configurations
    • Get Agent Configuration By ID
    • Create Agent Configuration
    • Update Agent Configuration
    • Delete Configuration Prompt
  • Agent Prompt Versions
    • Get Active Agent Prompt
    • Get All Agent Prompt Versions
    • Get Agent Prompt Version By ID
    • Create Agent Prompt Version
    • Update Agent Prompt Version
    • Update Agent Prompt Version Copy
    • Delete Agent Prompt Version
  • Messaging
    • Instances
      • Create Instance
      • Get All Instance
      • Get Instance
      • Update Instance
      • Connect Instance
      • Disconnect Instance
      • Activate Instance
      • Deactivate Instance
    • Message
      • Send Message
  • Notifications
    • Get All Notifications
    • Get Notification By ID
    • Create Notification
    • Delete Notification
  • Whatsapp Notification Configuration
    • Get All Whatsapp Notification Configs By Company
    • Create Notification Config
    • Get Notification Config By ID
    • Delete Config Notification
    • Update Config Notification
  • Notification Configurations
    • Get All Notification Configs By Company
    • Create Notification Config
    • Get Notification Config By ID
    • Delete Config Notification
    • Update Config Notification
  1. Docs

Integrations

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
Key files:
src/messaging/whatsapp.service.ts
src/messaging/types.ts
src/messaging/handlers.ts

Features#

Multiple WhatsApp instances per company
QR code authentication
Message sending and receiving
Media message support
Connection status monitoring
Automatic reconnection
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#

Library: googleapis
Key files:
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
Bi-directional updates
Webhook notifications for real-time updates
Multi-calendar support

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#

Library: openai
Key files:
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)
Model selection
Temperature setting
System prompt for bot personality
Maximum token limits

Chatwoot Integration#

The API integrates with Chatwoot for customer support management.

Implementation#

Key files:
src/services/chatwootAccount.service.ts
src/controllers/chatwootAccount.controller.ts

Features#

Chatwoot account management
Conversation synchronization
Agent assignment
Status tracking

Configuration#

Chatwoot integration is configured at the company level with the following parameters:
Chatwoot API credentials
Account ID
Inbox configurations
Agent assignments

Integration Token Management#

All third-party service tokens are managed through the IntegrationToken model, which securely stores:
Access tokens
Refresh tokens
Expiration dates
Service identifiers
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
Página anterior
Middleware
Próxima página
Database
Built with