README
React Native Multichannel Widget
The most complete chat UI Multichannel for React Native
Requirements
- React Native Version >= 0.59
Installation
- Using npm
npm i @qiscus-community/react-native-multichannel-widget - Using yarn
yarn add @qiscus-community/react-native-multichannel-widget
Configuration Widget
1. Add MultichannelWidgetProvider in App.js
We use Hooks to synchronize data. To make it work we have to explicitly insert a mount point in your app like this:
// in your entry file like `App.js`
import {MultichannelWidgetProvider} from '@qiscus-community/react-native-multichannel-widget';
// in your render function
return (
<MultichannelWidgetProvider> // <- use MultichannelWidgetProvider
<App />
</MultichannelWidgetProvider>
);
2. Initialization Widget
Initiate widget for first time
import {Qiscus} from '@qiscus-community/react-native-multichannel-widget';
const SplashCreen = () => {
useEffect(()=>{
//optional params
let options = {
baseURLMultichannel: // custom base url Multichannel
baseURLSdk: // custom base url SDK
mqttURLSdk: // custom mqtt url SDK
brokerLbURLSdk: // custom broker LB url SDK
uploadURLSdk: // custom uploader url SDK
}
Qiscus.setup(AppId,options);
},[])
....
};
AppId Qiscus used to initiate chat applications in qiscus, further related to AppId : https://documentation.qiscus.com/latest/multichannel-customer-service/settings-and-configuration#app-information
3. Initialization Chat
Initiate room chat
import Widget from '@qiscus-community/react-native-multichannel-widget';
const widget = Widget();
widget.initiateChat(options)
.then(result => {
})
.catch(e => {
})
Input options (object prefered)
| fields | type | required | description |
|---|---|---|---|
| userId | string | true | unique identifier of a user |
| name | string | true | display name of a user |
| deviceId | string | false | device token from fcm, used for push notification needs |
| extras | json_string/ json_object | false | eg: {"data_source": "us"} |
| additionalInfo | json_string/ json_object | false | it will fill the user properties bar on the right side of customer room |
| messageExtras | json__string/ json_object | false | will fill the information on message extras |
| channelId | integer | false | optional, init chat on target channel_id |
Example
const USER_ID = "user01@mail.com"
const NAME = "user01"
const FCM_TOKEN = "12345678"
const USER_EXTRAS = {
user_id: "user01",
is_priority: true
}
const ADDISIONAL_INFO = {
"full name" : "Linda",
"email" : "linda@mail.com"
}
let options = {
userId : USER_ID,
name : NAME,
deviceId: FCM_TOKEN,
extras: USER_EXTRAS,
additionalInfo: ADDISIONAL_INFO
}
widget.initiateChat(options)
.then(result => {
})
.catch(e => {
})
4. Use Header Component
Using component header

<Header
height={56}
style={{
backgroundColor : 'orange'
}}
textColor = 'white'
/>
Props
title(String) - Custom titlesubtitle(String) - Custom subtitleavatar(Object) - Extra props to be passed Component to custom avatarheight(Integer) - Height of the Header, default is56headerRight(Object) - Extra props to be passed Component to the Right HeaderheaderLeft(Object) - Extra props to be passed Component to the Left Headerstyle(Object) - Extra props to be passed custom style headertextColor(String) - Custom text color header
5. Use Chat Room Component
Using chat room component

<MultichannelWidget
onSuccessGetRoom={room => {
}}
onDownload={onDownload}
onPressSendAttachment={onPressSendAttachment}
/>
Props
onSuccessGetRoom(Function(room)) - Callback when success get roomonPressSendAttachment(Function) - Callback when button Send Attachment is tappedonPressVideo(Function) - Callback when button media player is tappedonDownload(Function) - Callback when a download message attachment is tappedrenderSendAttachment(Object) - Extra props to be custom Component button Send AttachmentrenderSendMessage(Object) - Extra props to be custom Component button Send Messageplaceholder(String) - Extra props to be custom placeholder, defaultType a message...renderTickSent(Object) - Extra props to be custom Component Tick SentrenderTickDelivered(Object) - Extra props to be custom Component Tick DeliveredrenderTickRead(Object) - Extra props to be custom Component Tick ReadrenderTickPending(Object) - Extra props to be custom Component Tick PendingfilterMessage(Function(message)) - Extra props to filter list messageavatar(Object) - Extra props to be passed Component to custom avataronTyping(Function) - Callback when a user typing
Get Unread Message Count
To get unread message count, you can use getUnreadCount method like below.
widget.getUnreadCount(callback)
End Session User
To request end session or end chat, you can use endSession method like below.
widget.endSession()
Remove Notification
At the logout action from the app, you need to implement removeNotification method like below to remove FCM_TOKEN from Qiscus Server, that means Qiscus Server not sending push notifications again to the device.
widget.removeNotification('FCM_TOKEN')
FCM_TOKEN is the same value when first initiation in step: 3. Initialization Chat link
Change Language
To change the language you can use changeLanguage method with input en for English and id for Indonesia.
widget.changeLanguage("en")
Get Qiscus SDK Service
To get Qiscus functionalities, you can import Qiscus like below.
import {Qiscus} from '@qiscus-community/react-native-multichannel-widget';
// another example to get room object from qiscus
import {Qiscus} from '@qiscus-community/react-native-multichannel-widget';
let room = Qiscus.qiscus.selected
for more methods related qiscus sdk service, you can read on this link : https://github.com/Qiscus-Integration/react-native-multichannel-widget/blob/master/lib/services/qiscus/index.js
Example App
ExampleApp folder contains an example app to demonstrate how to use this package.
How to run the example app
- Clone or download this repo
- Open ExampleApp directory
- create new file with name
.envfile like .env_sample add APP_ID with your Multichannel AppId - Open your terminal or cmd and execute
npm installcommand - To run the Example App you need to execute
react-native run-androidcommand and wait for the process to complete
Push Notification
To implement push notification in react native widget you need to add FCM Key in notifications setting, below is how to do it, you need to read in “Android's Customer Widget Push Notification” section https://documentation.qiscus.com/multichannel-customer-service/settings-and-configuration#notifications
References
- Multichannel Mobile in app widget from scratch : https://documentation.qiscus.com/multichannel-customer-service/channel-integration#mobile-in-app-widget
- Mobile App push notification : https://documentation.qiscus.com/multichannel-customer-service/channel-integration#mobile-app-push-notification