react-swizi-chat v0.8.4
Swizi Chat React Component
react-swizi-chat is a React component to easily add chat functionnality to your app.
this component uses swizi-chat-sdk.
Summary
Installation
npm i react-swizi-chat or yarn add react-swizi-chat
Usage
Example 1 : display a ChatBox with all channels for this user
import {SwiziChatBox} from 'SwiziChatBox'
class App extends React.Component {
render () {
return (
<SwiziChatBox apikey={"your api key"} userToken={a swizi token for user} />
)
}
}
Example 2 : display a ChatBox with a single channel between two users
import React from 'react'
import {SwiziChatBox} from 'SwiziChatBox'
class App extends React.Component {
render () {
return (
<SwiziChatBox apikey={"your api key"} userToken={a swizi token for user} recipientExternalId={'external id of recipient'}/>
)
}
}
Example 3 : Open a contact in an existing chatBox
import React from 'react'
import SwiziChatBox from 'SwiziChatBox'
class App extends React.Component {
render () {
return (
<SwiziChatBox apikey={"your api key"}
userToken={a swizi token for user}
recipientExternalId={'external id of recipient'}
ref=>{this.myChatBox=ref}/>
)
}
}
...
this.myChatBox.getContactList()
...
this.myChatBox.openContact('recipient id')
...
Example 4 : Open a room in an existing chatBox
import React from 'react'
import SwiziChatBox from 'SwiziChatBox'
class App extends React.Component {
render () {
return (
<SwiziChatBox
apikey={"your api key"}
userToken={a swizi token for user}
recipientExternalId={'external id of recipient'}
ref=>{this.myChatBox=ref}/>
)
}
}
...
this.myChatBox.openRoom('room id')
...
Properties
name | default value | description |
---|---|---|
apikey | required | Your swizi chat apikey |
userToken | Swizi user token to identify user. You can use userId or externalUserId in place of | |
clazz | empty | A css class to customize ChatBox |
onCloseClicked | empty | a function called when user click on close button |
avatarComponent | default svg | component displayed to symbolized one2one rooms and user |
groupComponent | default svg | component displayed to symbolized channels with severals users |
sendComponent | default svg | component displayed to for send message button |
writingSpinner | default spinner | component displayed when other user is writing a message |
openSingleroom | false | If user has only one room, this room is automatically opened (value is true when a recipient is defined) |
labels | default labels | object containing list of labels to use. See ./src/components/SwiziChatBox/defaultLabels.js for example |
recipientId | empty | Open only one room to chat with a unique user which id is recipientId |
recipientExternalId | empty | Open only one room to chat with a unique user which external id is recipientExternalId |
deviceType | empty | A string to describe the deviceType. This info will be sent to log monitor to help debug |
deviceId | empty | A string to identify currentId. This tag info be sent to log monitor to help debug |
tagList | empty | A list of tag (string) to use to filter rooms |
limitToRoom | empty | The component will load only one room with the id contained in this property. openSingleRoom will be switch to true. |
swiziApi | https://api.swizi.io | Endpoint to Swizi API. User to identify user if no token or invalid token is provided |
useLike | false | User can like a message and see how many likes were sent to this message (experimental feature) |
usePhoto | false | User can send a photo as a message (experimental feature) |
templateMessage | "" | Message editor is initialised with this message ready to be sent |
limitToUnread | false | Rooms are filtered to display only rooms with at least one unread message |
Customize Style
The component can be customized with your own style.
- Copy /src/components/SwiziChatBox/style.less
- Replace swizi-chat-box-default-style class with your name
- Change style and import new css
- Pass the new class name in clazz property
Notifier
SwiziChatNotifier is an invisible React component to be notified when a message is sent to a Swizi user.
Usage :
import React from 'react'
import { SwiziChatNotifier } from 'SwiziChatBox';
class App extends React.Component {
let that = this;
render () {
return (
<SwiziChatNotifier
apikey={"your api key"}
userToken={a swizi token for user}
ref=>{this.myChatNotofier=ref}
onUnreadChanged={
()=>{
// Some messages have been marked as read. must update counter
console.log(that.myChatNotifier.getUnreadCount()+ ' unread messages'
}
}
onMessageReceived={info => {
console.log('Message received on room '+info.roomId+' from '+info.from.displayName)
console.log(that.myChatNotifier.getUnreadCount()+ ' unread messages'
})
/>
)
}
}
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago