JAVASCRIPT SDK

In-App Chat javascript SDK

Features

  • Individual messages
  • Push notifications
  • Text, Image, Video, Audio messages
  • Typing Indicators
  • Delivered and Read receipts
  • Chat history
  • Chat user list
  • Contact details

Install the js SDK

$ npm install ertc
<script src="lib/ertc.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/paho-mqtt/1.1.0/paho-mqtt.js" type="text/javascript"></script>

Initialise the SDK

new eRTCSDK().initialise (“com.ripbull.ertc”);

API documentation

Validate the namespace of your app

Use tenant module’s validate tenant method to validate tenant information.

new TenantModule().validateTenant(namespace, accessCode).then(result => {
   console.log(result);
}).catch(error => {
   console.log(error);
});

Login with username and password

Use the tenant module’s login method to login the user.

new TenantModule().login (username, password).then(result => {
   console.log(result);
}).catch(error => {
   console.log(error);
});

Forgot password

Use the tenant module’s forget password method to get the new password for the user.

new TenantModule().forgetPassword (emailAddress).then(result => {
   console.log(result);
}).catch(error => {
   console.log(error);
});

Change password

Use the tenant module’s change password method to change the existing password for the user.

new TenantModule().changePassword (oldPassword, newPassword).then(result => {
   console.log(result);
}).catch(error => {
   console.log(error);
});

Load user list

Use the user module’s getchatuser method to get the chat users list.

new UserModule().GetChatUsers(false).then(result => {
   console.log(result);
}).catch(error => {
   console.log(error);
});

Update User

Use the user module’s update user method to update the logged-in user.

new UserModule().UpdateUser (false).then(result => {
   console.log(result);
}).catch(error => {
   onsole.log(error);
});

Set availability status

Use the user module’s update user method to update the logged-in user.

new UserModule().setUserAvailability(value).then(result => {
   console.log(result);
}).catch(error => {
   console.log(error);
});

Logout User

Use the user module’s logout user method to log users out.

new UserModule().LogOutUser().then(result => {
   console.log(result);
}).catch(error => {
   console.log(error);
});

To initiate chat, you have to create a thread with the recipient

new ChatModule().createThread(userChatId).then(result => {
   console.log(result);
}).catch(error => {
   console.log(error);
});

Sending a text message

Use chat module’s sendMessage method to send text messages.

let message: Message = {
   type: MessageType.Text,
   message: textMessage
};
new ChatModule().sendMessage(threadId, message).then(result => {
   console.log(result);
}).catch(error => {
   console.log(error);
});

Sending a media message

Use chat module’s sendMessage method to send media messages.

let message: Message = {
   type: MessageType.Image,
   media: File,
};
new ChatModule().sendMessage(threadId, message).then(result => {
   console.log(result);
}).catch(error => {
   console.log(error);
});

Sending a document

Use chat module’s sendMessage method to send document messages.

let message: Message = {
   type: MessageType.File,
   media: File
}
new ChatModule().sendMessage(threadId, message).then(result => {
   console.log(result);
}).catch(error => {
   console.log(error);
});

Sending a contact

Use chat module’s sendMessage method to send document messages.

let message: Message = {
   type: MessageType.Contact,
   contact: {
      contactName: user.name,
      eMailRecords: [email],
      phoneNumberRecord: []
   }
}
new ChatModule().sendMessage(threadId, message).then(result => {
   console.log(result);
}).catch(error => {
   console.log(error);
});

Sending a GIF

Use chat module’s sendMessage method to send gif messages.

let message: Message = {
   type: MessageType.Gify,
   gifPath: result
}
new ChatModule().sendMessage(threadId, message).then(result => {
   console.log(result);
}).catch(error => {
   console.log(error);
});

Block / unblock a user

To block a user: action = “block”
To unblock a user: action = “unblock”
new ChatModule().blockUnblockUser(action, userChatId).then(result => {
   console.log(result);
}).catch(error => {
   console.log(error);
});