0.8.4 • Published 4 years ago

react-swizi-chat v0.8.4

Weekly downloads
1
License
MIT
Repository
-
Last release
4 years ago

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

  1. Installation

  2. Usage

  3. Properties

  4. Customize style

  5. Notifier

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

namedefault valuedescription
apikeyrequiredYour swizi chat apikey
userTokenSwizi user token to identify user. You can use userId or externalUserId in place of
clazzemptyA css class to customize ChatBox
onCloseClickedemptya function called when user click on close button
avatarComponentdefault svgcomponent displayed to symbolized one2one rooms and user
groupComponentdefault svgcomponent displayed to symbolized channels with severals users
sendComponentdefault svgcomponent displayed to for send message button
writingSpinnerdefault spinnercomponent displayed when other user is writing a message
openSingleroomfalseIf user has only one room, this room is automatically opened (value is true when a recipient is defined)
labelsdefault labelsobject containing list of labels to use. See ./src/components/SwiziChatBox/defaultLabels.js for example
recipientIdemptyOpen only one room to chat with a unique user which id is recipientId
recipientExternalIdemptyOpen only one room to chat with a unique user which external id is recipientExternalId
deviceTypeemptyA string to describe the deviceType. This info will be sent to log monitor to help debug
deviceIdemptyA string to identify currentId. This tag info be sent to log monitor to help debug
tagListemptyA list of tag (string) to use to filter rooms
limitToRoomemptyThe component will load only one room with the id contained in this property. openSingleRoom will be switch to true.
swiziApihttps://api.swizi.ioEndpoint to Swizi API. User to identify user if no token or invalid token is provided
useLikefalseUser can like a message and see how many likes were sent to this message (experimental feature)
usePhotofalseUser can send a photo as a message (experimental feature)
templateMessage""Message editor is initialised with this message ready to be sent
limitToUnreadfalseRooms are filtered to display only rooms with at least one unread message

Customize Style

The component can be customized with your own style.

  1. Copy /src/components/SwiziChatBox/style.less
  2. Replace swizi-chat-box-default-style class with your name
  3. Change style and import new css
  4. 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'
				})
				/>
		)
	}
}
0.8.4

4 years ago

0.8.1

4 years ago

0.8.3

4 years ago

0.8.2

4 years ago

0.8.0

4 years ago

0.7.8

5 years ago

0.7.7

5 years ago

0.7.6

5 years ago

0.7.4

5 years ago

0.7.3

5 years ago

0.7.2

5 years ago

0.7.1

5 years ago

0.7.0

5 years ago

0.6.1

5 years ago

0.5.1

5 years ago

0.5.0

5 years ago

0.4.0

5 years ago

0.3.0

5 years ago

0.2.4

5 years ago

0.2.3

5 years ago

0.2.2

5 years ago

0.2.1

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.0

5 years ago

0.2.0

5 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.48

6 years ago

0.0.47

6 years ago

0.0.46

6 years ago

0.0.45

6 years ago

0.0.44

6 years ago

0.0.43

6 years ago

0.0.42

6 years ago

0.0.41

6 years ago

0.0.40

6 years ago

0.0.39

6 years ago

0.0.37

6 years ago

0.0.36

6 years ago

0.0.35

6 years ago

0.0.34

6 years ago

0.0.33

6 years ago

0.0.32

6 years ago

0.0.31

6 years ago

0.0.30

6 years ago

0.0.29

6 years ago

0.0.28

6 years ago

0.0.27

6 years ago

0.0.26

6 years ago

0.0.25

6 years ago

0.0.24

6 years ago

0.0.23

6 years ago

0.0.22

6 years ago

0.0.21

6 years ago

0.0.20

6 years ago

0.0.19

6 years ago

0.0.18

6 years ago

0.0.17

6 years ago

0.0.16

6 years ago

0.0.15

6 years ago

0.0.14

6 years ago

0.0.13

6 years ago

0.0.12

6 years ago

0.0.11

6 years ago

0.0.10

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago