Skip to main content

Overview

The Eusate Messenger SDK provides the fastest way to integrate helpdesk functionality into your web or mobile applications. With just a few lines of code, you can add complete customer support capabilities powered by SATE.

Installation

Install the SDK using npm:
npm install @eusate/messenger-sdk
Or using yarn:
yarn add @eusate/messenger-sdk

Quick Start

1. Import and Initialize

import EusateMessenger from '@eusate/messenger-sdk';

const messenger = new EusateMessenger({
  apiKey: 'your-api-key',
  sessionId: 'unique-customer-session-id',
  baseUrl: '{api_base_url}' // Optional, defaults to production
});

2. Initialize the Messenger

// Initialize the messenger
await messenger.init();

// Optional: Set up event listeners
messenger.on('message', (message) => {
  console.log('New message:', message);
});

messenger.on('connected', () => {
  console.log('Connected to Eusate');
});

3. Send Messages

// Send a text message
await messenger.sendMessage('Hello, I need help with my order');

// Send a message in a specific conversation
await messenger.sendMessage('Follow-up question', {
  conversationId: 'existing-conversation-id'
});

Configuration Options

apiKey
string
required
Your API key from the apikey settings
sessionId
string
required
Unique identifier for the customer session
baseUrl
string
API base URL. Defaults to production endpoint
autoConnect
boolean
Automatically connect on initialization. Default: true
debug
boolean
Enable debug logging. Default: false

Methods

Core Methods

init()

Initialize the messenger and establish connection.
await messenger.init();

sendMessage(message, options?)

Send a message to start or continue a conversation.
message
string
required
The message content to send
options.conversationId
string
ID of existing conversation to continue
options.attachment
boolean
Whether message includes attachment. Default: false
// Start new conversation
const response = await messenger.sendMessage('I need help');

// Continue existing conversation
await messenger.sendMessage('Thanks!', {
  conversationId: response.conversationId
});

getConversations(options?)

Retrieve customer conversations.
options.closed
boolean
Filter by conversation status
// Get all conversations
const conversations = await messenger.getConversations();

// Get only open conversations
const openConversations = await messenger.getConversations({ closed: false });

getMessages(conversationId)

Get all messages in a conversation.
const messages = await messenger.getMessages('conversation-id');

markAsRead(conversationId)

Mark a conversation as read by the customer.
await messenger.markAsRead('conversation-id');

closeConversation(conversationId)

Close a conversation when the issue is resolved.
await messenger.closeConversation('conversation-id');

submitReview(conversationId, rating, feedback?)

Submit a review after conversation closure.
conversationId
string
required
ID of the conversation to review
rating
number
required
Rating from 1 to 5
feedback
string
Optional feedback text
await messenger.submitReview('conversation-id', 5, 'Great support!');

Connection Methods

connect()

Manually establish connection to the server.
await messenger.connect();

disconnect()

Disconnect from the server.
messenger.disconnect();

isConnected()

Check connection status.
const connected = messenger.isConnected();

Events

The SDK emits various events you can listen to:

Connection Events

// Connection established
messenger.on('connected', () => {
  console.log('Connected to Eusate');
});

// Connection lost
messenger.on('disconnected', () => {
  console.log('Disconnected from Eusate');
});

// Connection error
messenger.on('error', (error) => {
  console.error('Connection error:', error);
});

Message Events

// New message received
messenger.on('message', (message) => {
  console.log('New message:', message);
  // message contains: id, content, sender, timestamp, conversationId
});

// Message sent successfully
messenger.on('messageSent', (message) => {
  console.log('Message sent:', message);
});

// Conversation status changed
messenger.on('conversationUpdate', (conversation) => {
  console.log('Conversation updated:', conversation);
});

Support Events

// SATE suggests closing conversation
messenger.on('closeRequested', (conversationId) => {
  // Show confirmation dialog to user
  showCloseConfirmation(conversationId);
});

// Conversation closed
messenger.on('conversationClosed', (conversationId) => {
  // Show review form
  showReviewForm(conversationId);
});

Complete Example

Here’s a complete implementation example:
import EusateMessenger from '@eusate/messenger-sdk';

class CustomerSupport {
  constructor(apiKey, customerId) {
    this.messenger = new EusateMessenger({
      apiKey: apiKey,
      sessionId: customerId,
      debug: process.env.NODE_ENV === 'development'
    });

    this.setupEventListeners();
  }

  async initialize() {
    try {
      await this.messenger.init();
      console.log('Support system ready');
    } catch (error) {
      console.error('Failed to initialize support:', error);
    }
  }

  setupEventListeners() {
    // Handle incoming messages
    this.messenger.on('message', (message) => {
      this.displayMessage(message);
    });

    // Handle connection status
    this.messenger.on('connected', () => {
      this.updateConnectionStatus('Connected');
    });

    this.messenger.on('disconnected', () => {
      this.updateConnectionStatus('Disconnected');
    });

    // Handle close requests
    this.messenger.on('closeRequested', (conversationId) => {
      this.showCloseConfirmation(conversationId);
    });

    // Handle conversation closure
    this.messenger.on('conversationClosed', (conversationId) => {
      this.showReviewForm(conversationId);
    });
  }

  async sendMessage(text, conversationId = null) {
    try {
      const response = await this.messenger.sendMessage(text, {
        conversationId
      });
      
      this.displayMessage({
        content: text,
        sender: 'customer',
        timestamp: new Date()
      });

      return response;
    } catch (error) {
      console.error('Failed to send message:', error);
      this.showError('Failed to send message');
    }
  }

  async loadConversations() {
    try {
      const conversations = await this.messenger.getConversations();
      this.displayConversations(conversations);
    } catch (error) {
      console.error('Failed to load conversations:', error);
    }
  }

  async closeConversation(conversationId) {
    try {
      await this.messenger.closeConversation(conversationId);
      this.showReviewForm(conversationId);
    } catch (error) {
      console.error('Failed to close conversation:', error);
    }
  }

  async submitReview(conversationId, rating, feedback) {
    try {
      await this.messenger.submitReview(conversationId, rating, feedback);
      this.showSuccess('Thank you for your feedback!');
    } catch (error) {
      console.error('Failed to submit review:', error);
    }
  }

  // UI helper methods
  displayMessage(message) {
    // Implement your message display logic
  }

  displayConversations(conversations) {
    // Implement your conversation list logic
  }

  updateConnectionStatus(status) {
    // Update UI connection indicator
  }

  showCloseConfirmation(conversationId) {
    // Show confirmation dialog
  }

  showReviewForm(conversationId) {
    // Show review form UI
  }

  showError(message) {
    // Show error message to user
  }

  showSuccess(message) {
    // Show success message to user
  }
}

// Usage
const support = new CustomerSupport('your-api-key', 'customer-123');
await support.initialize();

Error Handling

The SDK provides comprehensive error handling:
try {
  await messenger.sendMessage('Hello');
} catch (error) {
  switch (error.code) {
    case 'NETWORK_ERROR':
      console.log('Network connection issue');
      break;
    case 'AUTH_ERROR':
      console.log('Authentication failed');
      break;
    case 'RATE_LIMIT':
      console.log('Rate limit exceeded');
      break;
    default:
      console.log('Unknown error:', error.message);
  }
}

TypeScript Support

The SDK includes full TypeScript definitions:
import EusateMessenger, { 
  Message, 
  Conversation, 
  MessengerConfig 
} from '@eusate/messenger-sdk';

const config: MessengerConfig = {
  apiKey: 'your-api-key',
  sessionId: 'customer-123',
  debug: true
};

const messenger = new EusateMessenger(config);

messenger.on('message', (message: Message) => {
  console.log(`${message.sender}: ${message.content}`);
});

Best Practices

Security

  • Never expose API keys in client-side code
  • Use environment variables for configuration
  • Validate user input before sending messages

Performance

  • Reuse messenger instances instead of creating new ones
  • Implement connection retry logic for network issues
  • Use conversation IDs to continue existing conversations

User Experience

  • Show connection status to users
  • Handle offline scenarios gracefully
  • Provide feedback for user actions

Migration from API

If you’re currently using the direct API, here’s how to migrate:

Before (API)

// Manual API calls
const response = await fetch('/api/conversations');
const socket = io('/helpdesk');
socket.emit('support', data);

After (SDK)

// SDK handles everything
const messenger = new EusateMessenger(config);
await messenger.sendMessage('Hello');