In order to use Stringee Live Chat API, you need to have a widget key which will be used to identify your portal. You can get that key by doing the following steps:

$ npm install stringee-react-native --saveThe Stringee Android SDK requires some permissions from your app's AndroidManifest.xml file:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Open up android/app/proguard-rules.pro and add following lines:
-dontwarn org.apache.**
-keep class com.stringee.** { *; }
-keep class org.apache.** { *; }
Note Please make sure to have CocoaPods on your computer.
pod initAdd the following to your pod file:
platform :ios, '8.0'
target '<YourProjectName>' do
node_modules_path = '../node_modules'
pod 'yoga', path: "#{node_modules_path}/react-native/ReactCommon/yoga/yoga.podspec"
pod 'React', path: "#{node_modules_path}/react-native", :subspecs => ['DevSupport', 'RCTNetwork']
pod 'RNStringee', path: "#{node_modules_path}/stringee-react-native-chat/ios"
end
post_install do |installer|
installer.pods_project.targets.each do |target|
if target.name == "React"
target.remove_from_project
end
end
end
pod install<YourProjectName>.xcworkspace file in XCode. This file can be found in the ios folder of your React Native project.Build Settings tab -> Other linker flags add $(inherited) flag.Build Settings tab -> Enable bitcode select NO.Info.plist and select Open As -> Source Code.<key>NSCameraUsageDescription</key>
<string>$(PRODUCT_NAME) uses Camera</string>
<key>NSMicrophoneUsageDescription</key>
<string>$(PRODUCT_NAME) uses Microphone</string>
import {StringeeClient} from "stringee-react-native";
...
render () {
return (
<View>
...
<StringeeClient
ref={this.client}
eventHandlers = {this.clientEventHandlers}
/>
...
</View>
)
}Register client events
...
constructor(props) {
super(props);
...
// Create client ref
this.client = createRef();
// Register client events
this.clientEventHandlers = {
onConnect: this.onConnect,
onDisConnect: this.onDisConnect,
onFailWithError: this.onFailWithError,
onRequestAccessToken: this.onRequestAccessToken,
onCustomMessage: this.onCustomMessage,
onObjectChange: this.onObjectChange,
onTimeoutInQueue: this.onTimeoutInQueue,
onConversationEnded: this.onConversationEnded,
onUserBeginTyping: this.onUserBeginTyping,
onUserEndTyping: this.onUserEndTyping,
};
}
...
//Event
// The client connects to Stringee server
onConnect = ({userId}) => {
console.log('onConnect - ' + userId);
};
// The client disconnects from Stringee server
onDisConnect = () => {
console.log('onDisConnect');
};
// The client fails to connects to Stringee server
onFailWithError = ({code, message}) => {
console.log('onFailWithError: code-' + code + ' message: ' + message);
};
// Access token is expired. A new access token is required to connect to Stringee server
onRequestAccessToken = () => {
console.log('onRequestAccessToken');
};
// Receive custom message
onCustomMessage = ({data}) => {
console.log('onCustomMessage: ' + data);
};
// Receive event of Conversation or Message
onObjectChange = ({objectType, objectChanges, changeType}) => {
console.log('onObjectChange: objectType - ' + objectType + '\n changeType - ' + changeType + '\n objectChanges - ' + JSON.stringify(objectChanges),);
};
// Receive when chat request to queue is timeout
onTimeoutInQueue = ({convId, customerId, customerName}) => {
console.log('onTimeoutInQueue: convId - ' + convId + '\n customerId - ' + customerId +
'\n customerName - ' + customerName,);
};
// Receive when conversation ended
onConversationEnded = ({convId, endedby}) => {
console.log('onConversationEnded: convId - ' + convId + '\n endedby - ' + endedby,);
};
// Receive when user send beginTyping
onUserBeginTyping = ({convId, userId, displayName}) => {
console.log('onUserBeginTyping: convId - ' + convId + '\n userId - ' + userId + '\n displayName - ' + displayName,);
};
// Receive when user send endTyping
onUserEndTyping = ({convId, userId, displayName}) => {
console.log('onUserEndTyping: convId - ' + convId + '\n userId - ' + userId + '\n displayName - ' + displayName,);
};
Chat Profile is an object which will let you know:
this.client.current.getChatProfile('YOUR_WIDGET_KEY', (status, code, message, chatProfile)=> {
console.log('getChatProfile, msg: ' + message + ' Profile: ' + JSON.stringify(chatProfile),);
},
);
In order to chat with your agents, your customers have to connect to Stringee server first. But they are not users in your system, they can be anybody, so you need to generate a token for them. In order to do that, call the following function:
this.client.current.getLiveChatToken('YOUR_WIDGET_KEY', 'YOUR_CUSTOMER_NAME', 'YOUR_CUSTOMER_EMAIL', (status, code, message, token) => {
console.log('getLiveChatToken: ' + JSON.stringify(token));
// After get token then can connect
this.client.current.connect(token);
},
);
In which:
Before starting a live chat conversation, you can update the customer information to Stringee Server, so your agent can know more about your customer (where is the customer from? what type of cell phone the customer using?...). In order to do that, call the following function:
this.client.current.updateUserInfo("USER_NAME", "USER_EMAIL", "USER_AVATAR", (status, code, message) => {
console.log('updateUserInfo: ' + message);
);
Then start a live chat conversation by calling:
this.client.current.createLiveChatConversation(queueId, (status, code, message, conversation) => {
console.log('createLiveChatConversation - ' + JSON.stringify(_conversation),);
},
);
In which:
Follow this instruction Messages
In order to end the live chat conversation, you call the following method:
this.client.current.endChat(convId, (status, code, message) => {
console.log('endChat: status - ' + status + ' code - ' + code + ' message - ' + message,);
},
);
Next, we will connect to Stringee Server. You must do this before you can start a live chat conversation.
import {StringeeClient} from "stringee-react-native";
...
render () {
return (
<View>
...
<StringeeClient
ref={this.client}
eventHandlers = {this.clientEventHandlers}
/>
...
</View>
)
}Register client events
...
constructor(props) {
super(props);
...
// Create client ref
this.client = createRef();
// Register client events
this.clientEventHandlers = {
onConnect: this.onConnect,
onDisConnect: this.onDisConnect,
onFailWithError: this.onFailWithError,
onRequestAccessToken: this.onRequestAccessToken,
onCustomMessage: this.onCustomMessage,
onObjectChange: this.onObjectChange,
onReceiveChatRequest: this.onReceiveChatRequest,
onReceiveTransferChatRequest: this.onReceiveTransferChatRequest,
onTimeoutAnswerChat: this.onTimeoutAnswerChat,
onConversationEnded: this.onConversationEnded,
onUserBeginTyping: this.onUserBeginTyping,
onUserEndTyping: this.onUserEndTyping,
};
}
...
//Event
// The client connects to Stringee server
onConnect = ({userId}) => {
console.log('onConnect - ' + userId);
};
// The client disconnects from Stringee server
onDisConnect = () => {
console.log('onDisConnect');
};
// The client fails to connects to Stringee server
onFailWithError = ({code, message}) => {
console.log('onFailWithError: code-' + code + ' message: ' + message);
};
// Access token is expired. A new access token is required to connect to Stringee server
onRequestAccessToken = () => {
console.log('onRequestAccessToken');
};
// Receive custom message
onCustomMessage = ({data}) => {
console.log('onCustomMessage: ' + data);
};
// Receive event of Conversation or Message
onObjectChange = ({objectType, objectChanges, changeType}) => {
console.log('onObjectChange: objectType - ' + objectType + '\n changeType - ' + changeType + '\n objectChanges - ' + JSON.stringify(objectChanges),);
};
// Receive when chat request to queue is timeout
onReceiveChatRequest = ({request}) => {
console.log('onReceiveChatRequest: chatRequest - ' + JSON.stringify(request),);
};
// Receive when chat request to queue is timeout
onReceiveTransferChatRequest = ({request}) => {
console.log('onReceiveTransferChatRequest: chatRequest - ' + JSON.stringify(request),);
};
// Receive when chat request to queue is timeout
onTimeoutAnswerChat = ({request}) => {
console.log('onTimeoutAnswerChat: chatRequest - ' + JSON.stringify(request),);
};
// Receive when conversation ended
onConversationEnded = ({convId, endedby}) => {
console.log('onConversationEnded: convId - ' + convId + '\n endedby - ' + endedby,);
};
// Receive when user send beginTyping
onUserBeginTyping = ({convId, userId, displayName}) => {
console.log('onUserBeginTyping: convId - ' + convId + '\n userId - ' + userId + '\n displayName - ' + displayName,);
};
// Receive when user send endTyping
onUserEndTyping = ({convId, userId, displayName}) => {
console.log('onUserEndTyping: convId - ' + convId + '\n userId - ' + userId + '\n displayName - ' + displayName,);
};
Connect to Stringee
this.client.current.connect('YOUR_TOKEN');
After receive a chat request, agent can accept or reject this chat request.
For accept chat request, call the following function:
this.client.current.acceptChatRequest(chatRequest, (status, code, message) => {
console.log('acceptChatRequest: status - ' + status + ' code - ' + code + ' message - ' + message,);
if (status) {
// if accept success, you can get conversation to start chatting
this.client.current.getConversationById(chatRequest.convId, (status, code, message, conversation) => {
console.log('getConversationById: status - ' + status + ' code - ' + code + ' message - ' + message + ' conversation - ' + JSON.stringify(conversation),);
},
);
}
},
);
After accept chat request success, you can get conversation by conversationId from chat request
For accept chat request, call the following function:
this.client.current.rejectChatRequest(chatRequest, (status, code, message) => {
console.log('rejectChatRequest: status - ' + status + ' code - ' + code + ' message - ' + message,);
},
);
Follow this instruction Messages
In order to end the live chat conversation, you call the following method:
this.client.current.endChat(convId, (status, code, message) => {
console.log('endChat: status - ' + status + ' code - ' + code + ' message - ' + message,);
},
);
For agent want to create a ticket for a missed live chat conversation, you call:
this.client.current.createLiveChatTicket('YOUR_WIDGET_KEY', 'CUSTOMER_NAME', 'CUSTOMER_EMAIL', 'TICKET_DESCRIPTION', (status, code, message) => {
console.log('createLiveChatTicket: status - ' + status + ' code - ' + code + ' message - ' + message,);
},
);
If you wanna send chat's content to an email at any time, you can use the following function:
this.client.current.sendChatTranscript('EMAIL', convId, 'DOMAIN', (status, code, message) => {
console.log('sendChatTranscript: status - ' + status + ' code - ' + code + ' message - ' + message,);
},
);
You can view a completed version of this sample app on GitHub: https://github.com/stringeecom/react-native-samples/tree/master/LiveChatSample