Overview
To get started, you will need to install MinChat Javascript SDK in your Javascript front-end project.
npm
yarn
pnpm
npm install @minchat/js
yarn add @minchat/js
pnpm install @minchat/js
The MinChat SDK needs to be initialized with the
MINCHAT_API_KEY
as a parameter as well as a User object representing the current user logged in. The API Key can be found on the Minchat dashboard.add to imports section
import MinChat from '@minchat/js'
const currentUser = {
username: "micheal",
name: "Micheal Saunders",
avatar: "urltoavatar.com/avatar.jpg" //optional
}
const minchat = MinChat.getInstance(MINCHAT_API_KEY).connectUser(currentUser)
This is called whenever a new message is received in a conversation, new or old.
minchat.onChat((chat) => {
//do something with the chat
})
Response
Field | Type | Description |
---|---|---|
chat | The chat object that has received a new message. |
You should create users in your MinChat application to initiate conversations with. Users are at the core of all conversations. MinChat applications are made up of users who chat in either group chats or one-to-one conversations.
Usually, you would create users based on the data from your database. A User is represented by a JSON object.
const otherUser = await minchat.createUser({
username: "example-username",
name: "Example Name",
avatar: "urltoavatar.com/avatar.jpg" //optional
})
note:
createUser(...)
automatically creates a new user in the system, if a user with the same username already exists then it will reuse that user.You can get a list of the conversations of the current user. conversations retrieved are paginated to 25 messages at a time.
async/await
callback
const { chats , page , totalChats , totalPages } = await minchat.getChats(1 /** page to query **/ )
minchat.getChats(1 /** page to query **/ , ({ chats , page , totalChats , totalPages })=>{
//do something with the list of chats
})
Parameters
Field | Type | State | Description |
---|---|---|---|
page | number | optional | query a specific page of chats, each page contains 25 chats. if null or undefined then the most recent 25 chats are returned |
Response
Field | Type | Description |
---|---|---|
chats | array of Chat objects | |
page | number | shows the current page of chats. each page contains 25 chats |
totalChats | number | shows the total number of chats that exist |
totalPages | number | shows the total number of pages of chats that exist. each page contains 25 chats |
const chat = await minchat.chat(otherUser.id)
Field | Type | State | Description |
---|---|---|---|
id | string | required | The id of the user to start a conversation with. (note: this user must already be created) |
const chat = await minchat.groupChat({
name: "Epic Group Chat",
memberIds: [ otherUser.id , thirdUser.id ],
avatar: "exampleavatar.com"
})
Field | Type | State | Description |
---|---|---|---|
name | string | optional | The name of the group chat. |
memberIds | string | required | id list of participants of the group chat. |
avatar | string | file | optional | the avatar of the group chat |
Last modified 22h ago