1.5.7 • Published 2 days ago

sceyt-chat v1.5.7

Weekly downloads
-
License
SEE LICENSE IN LI...
Repository
github
Last release
2 days ago

SceytChat JavaScript SDK

The SceytChat JavaScript SDK provides developers with a powerful and flexible chat interface that can be easily integrated into JavaScript apps. With SceytChat, you can easily add one-to-one and group chat functionality to your app. It comes packed with a wide range of features, including message threading, media and file sharing, reactions, user mentions, message search, user and channel blocking, message forwarding and replies, and many more.

Table of contents

Installation

To use the SceytChat JavaScript SDK in your project, you can install it via npm or yarn.

npm

To install the SceytChat JavaScript SDK using npm, run the following command:

npm i sceyt-chat

yarn

To install the SceytChat JavaScript SDK using Yarn, run the following command:

yarn add sceyt-chat

Usage

To use the SceytChat SDK in your application, you'll need to initialize it with the following parameters:

  • apiUrl: The URL for the Sceyt Chat API endpoint that the SDK should connect to. You can find this value in the Sceyt managment dashboard. This parameter is required.
  • appId: The unique ID for your Sceyt Chat application. You can find this value in the Sceyt managment dashboard. This parameter is required.
  • clientId The unique ID for your SceytChat client. This parameter should be unique across the instances if you want to use multiple clients of the same user, for example in multiple browser tabs.
  • requestTimeout An optional parameter that specifies the maximum amount of time in milliseconds to wait for a response from the Sceyt Chat API before timing out. If this parameter is not specified, the SDK will use a default timeout of 10000 milliseconds (10 seconds).
import SceytChat from 'sceyt-chat';

const sceytClient = new SceytChat('{apiUrl}', '{appId}', '{clientId}')

Before connecting to the SceytChat service, it's a good idea to add connection listeners to the SceytChat client to handle various events that may occur during the connection process. Here are connection listeners you can add:

// Create a new connection listener
const connectionListener = new sceytClient.ConnectionListener();

// Set the listener function for the 'connectionStatusChanged' event
connectionListener.onConnectionStatusChanged = async (status) => {
  console.log('Connection status changed:', status);
};

// Set the listener function for the 'tokenWillExpire' event
connectionListener.onTokenWillExpire = async (timeInterval) => {
  console.log('Token will expire in', timeInterval/1000, 'seconds');
};

// Set the listener function for the 'tokenExpired' event
connectionListener.onTokenExpired = async () => {
  console.log('Access token has expired');
};

// Add the connection listener to the SceytChat client
sceytClient.addConnectionListener('my-connection-listener', connectionListener);

Before creating a channel and sending messages, make sure the SceytChat client is connected:

// Connect to the Sceyt Chat API with a valid access token
sceytClient.connect('{accessToken}');

Now you can create a new channel with different members and send a message:

const members = [
    {
        role: 'participant',
        id: 'alice'
    },
    {
        role: 'participant',
        id: 'john'
    }
]

const params = {
    type: 'group',
    subject: 'Marketing Group',
    members
}

const marketingGroup = await sceytClient.Channel.create(params);

// Create a message builder to construct a message object for sending
const messageBuilder = marketingGroup.createMessageBuilder();
const messageToSend = messageBuilder
    .setBody('Hey team! How are you doing today?')
    .setType('common')
    .create();

// Send the message
const message = await channel.sendMessage(messageToSend);

License

See the LICENSE file for details.

1.5.8-beta.0

2 days ago

1.5.7-beta.2

3 months ago

1.5.7

3 months ago

1.5.7-beta.1

3 months ago

1.5.5

5 months ago

1.5.6

5 months ago

1.0.4-beta.0

11 months ago

1.0.4-beta.1

11 months ago

1.5.4

8 months ago

1.5.3

8 months ago

1.5.2

11 months ago

1.5.1

11 months ago

1.5.0

11 months ago

1.0.5

11 months ago

1.0.4

12 months ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago