Agora chat sdk Introduction
Agora chat sdk provides complete instant messaging function development capabilities, shields/encapsulate and block its internal complex details, and provides a relatively simple and concise API interface to facilitate third-party applications to quickly integrate instant messaging functions for PC/mobile Web applications
Chat SDK can be integrated in the following way:
- Install
npm install agora-chat --save
- Import websdk
import websdk from 'agora-chat'
- Initialize the SDK
const WebIM = {};
const conn = (WebIM.conn = new websdk.connection({
appKey: 'your app key',
}));
- Login chat server
const options = {
user: 'username',
pwd: 'password',
};
conn.open(options);
- Send a message
let option = {
chatType: 'singleChat',
type: 'txt',
to: 'userID',
msg: 'message content',
};
let msg = websdk.message.create(option);
conn.send(msg)
.then(() => {
console.log('send private text Success');
})
.catch((e) => {
console.log('Send private text error');
});