Suggestions

close search

StringeeClient

Represents a Stringee client, manages the client's connection. This component provides methods to connect to/disconnect from Stringee server, receives the connection's events, the incoming call event.

Props

eventHandlers: Object

Event handlers passed into the native StringeeClient instance. Example:


            clientEventHandlers = {
                onConnect: this.onConnect,
                onDisConnect: this.onDisConnect,
                onFailWithError: this.onFailWithError,
                onRequestAccessToken: this.onRequestAccessToken,
                onIncomingCall: this.onIncomingCall,
                onIncomingCall2: this.onIncomingCall2,
                onCustomMessage: this.onCustomMessage,
                onObjectChange: this.onObjectChange,
                onReceiveChatRequest: this.onReceiveChatRequest,
                onReceiveTransferChatRequest: this.onReceiveTransferChatRequest,
                onTimeoutAnswerChat: this.onTimeoutAnswerChat,
                onTimeoutInQueue: this.onTimeoutInQueue,
                onConversationEnded: this.onConversationEnded,
                onUserBeginTyping: this.onUserBeginTyping,
                onUserEndTyping: this.onUserEndTyping,
            };
          

Events

onConnect : Function(userId: string, projectId: string, isReconnecting: boolean)

Invoked when the client connects to Stringee server:
- userId: It's the unique identification of the client on Stringee system.
- projectId: Id of your project.
- isReconnecting = YES: The client is reconnecting, isReconnecting = NO: The client connects first time.

onDisConnect : Function(userId: string, projectId: string, isReconnecting: boolean)

Invoked when the client connects to Stringee server:
- userId: It's the unique identification of the client on Stringee system.
- projectId: Id of your project.
- isReconnecting = YES: The client is reconnecting, isReconnecting = NO: The client connects first time.

onFailWithError : Function(userId: string, code: int, message: string)

Invoked when the client fails to connect to Stringee server:
- userId: It's the unique identification of the client on Stringee system.
- code = 1, message = "Access token is empty"
- code = 2, message = "Access token can not be decoded"
- code = 3, message = "Access token invalid format"
- code = 4, message = "Access token does not use HS256"
- code = 5, message = "API key sid or account sid not found"
- code = 6, message = "Access token expired or invalid"
- code = 7, message = "Access token invalid payload"
- code = 8, message = "Project not found"

onRequestAccessToken : Function()

Invoked when the access token is expired. You must get a new token and reconnect.

onIncomingCall : Function(userId: string, callId: string, from: string, to: string, fromAlias: string, toAlias: string, callType: int, isVideoCall: boolean, customDataFromYourServer: string)

Invoked when the client receives an incoming call:
- userId: It's the unique identification of the client on Stringee system.
- callId: The call's id generated by Stringee server.
- from: The caller's phone number or id.
- to: The callee's phone number or id.
- fromAlias: The alias of the caller.
- toAlias: The alias of the callee.
- callType: The type of the call:
    + callType = 0, App-to-app-outgoing-call
    + callType = 1, App-to-app-incoming-call
    + callType = 2, App-to-phone
    + callType = 3, Phone-to-app
- isVideoCall: Whether the call is a video call:
    + isVideoCall = true, a video call
    + isVideoCall = false, a voice call
- customDataFromYourServer: The custom data from your server when a client makes a call or receives an incoming call.

onIncomingCall2 : Function(userId: string, callId: string, from: string, to: string, fromAlias: string, toAlias: string, callType: int, isVideoCall: boolean, customDataFromYourServer: string)

Invoked when the client receives an incoming call2:
- userId: It's the unique identification of the client on Stringee system.
- callId: The call's id generated by Stringee server.
- from: The caller's phone number or id.
- to: The callee's phone number or id.
- fromAlias: The alias of the caller.
- toAlias: The alias of the callee.
- callType: The type of the call:
    + callType = 0, App-to-app-outgoing-call
    + callType = 1, App-to-app-incoming-call
    + callType = 2, App-to-phone
    + callType = 3, Phone-to-app
- isVideoCall: Whether the call is a video call:
    + isVideoCall = true, a video call
    + isVideoCall = false, a voice call
- customDataFromYourServer: The custom data from your server when a client makes a call or receives an incoming call.

onCustomMessage : Function(data: string)

Invoked when the client get custom message:
- data: It's data of custom message.

onObjectChange : Function(objectType: int, changeType: int, objectChanges: Object)

Invoked when the client receives an object change of chat:
- objectType: It's the type of updated object:
    + objectType = 0, Conversation
    + objectType = 1, Message
- changeType: It's the type of change:
    + changeType = 0, Insert - Notify an object is created or inserted.
    + changeType = 1, Update - Notify an object is updated.
    + changeType = 2, Delete - Notify an object is deleted.
- objectChanges: A set of updated objects.

onReceiveChatRequest : Function(request: ChatRequest)

Invoked when the client receives chat request.

onReceiveTransferChatRequest : Function(request: ChatRequest)

Invoked when the client receives transfer chat request.

onTimeoutAnswerChat : Function(request: ChatRequest)

Invoked when chat request time out rout to agent.

onTimeoutInQueue : Function(convId: string, customerId: string, customerName: string)

Invoked when chat request time out route to agent:
- convId: It's the id of conversation.
- customerId: It's the id of customer.
- customerName: It's the name of customer.

onConversationEnded : Function(convId: string, endedby: string)

Invoked when the conversation is ended:
- convId: It's the id of conversation.
- endedby: It's the id of user who end this conversation.

onUserBeginTyping : Function(convId: string, userId: string, displayName: string)

Invoked when the user send begin typing:
- convId: It's the id of conversation.
- userId: It's the id of user who send begin typing.
- displayName: It's the name of user who send begin typing.

onUserEndTyping : Function(convId: string, userId: string, displayName: string)

Invoked when the user send begin typing:
- convId: It's the id of conversation.
- userId: It's the id of user who send end typing.
- displayName: It's the name of user who send end typing.

Functions

connect(token: string)

Connects to Stringee server with an access token:
- token: Your access token.

disconnect()

Disconnects from Stringee server.

registerPush(deviceToken: string, isProduction: boolean, isVoip: boolean, callback:(status, code, message))

Register device token to receive push notification. When you have an incoming call, you receive a notification from Stringee server:
- deviceToken: The token received from Apple's server when you register push notification to Apple (iOS).
- isProduction = true : For production environment, isProduction = false: For development environment (iOS).
- isVoip = true: To receive voip push notification, isVoip = false: To receive remote push notification (iOS).
- callback: The result of the registration:
    + status = true, code = 0, message = "Register successfully."
    + status = false, code = 1, message = "The Bundle Identifier has not been configured.".
    + status = false, code = -1, message = "StringeeClient is not initialized or connected".
    + status = false, code = -2, message = "Data is empty.".
    + status = false, code = -3, message = "Generic error.".

unregisterPush(deviceToken: string, callback: (status, code, message))

Remove your device token from Stringee server. Your device will not receive push notification when you have an incoming call
- deviceToken: The device token which registered.
- callback: The result of unregistering
    + status = true, code = 0, message = "Unregister successfully."
    + status = false, code = 1, message = "The Bundle Identifier has not been configured.".
    + status = false, code = -1, message = "StringeeClient is not initialized or connected".
    + status = false, code = -2, message = "Generic error".

sendCustomMessage(toUserId: string,message: string, callback: (status, code, message))

Send a custom message to a user
- toUserId: User's id whom send message to
- message: Custom message in JSON format
- callback: The result
    + status = true, code = 0, message = "Success"
    + status = false, code = -1, message = "StringeeClient is not initialized or connected".
    + status = false, code = -2, message = "Generic error".

createConversation(userIds,options, callback: (status, code, message, conversation))

Construct a new conversation with the provided participants and options.
- userIds: Users' id of participants
- options: Conversation options to use when constructing this conversation
- callback: The result
    + status = true, code = 0, message = "Success"
    + status = false, code = -1, message = "StringeeClient is not initialized or connected".
    + status = false, code = -2, message = "Generic error".
    + conversation: A conversation ready for messages.

getConversationById(conversationId: String, callback: (status, code, message, conversation))

Return the existing conversation with given ID.
- conversationId: Conversation ID
- callback: The result
    + status = true, code = 0, message = "Success"
    + status = false, code = -1, message = "StringeeClient is not initialized or connected".
    + status = false, code = -2, message = "Generic error".
    + conversation: The existing conversation.

getLocalConversations(userId: String, count: String, callback: (status, code, message, conversations))

Return stored conversations.
- userId: Your user ID
- count: Number of conversations you want to get
- callback: The result
    + status = true, code = 0, message = "Success"
    + status = false, code = -1, message = "StringeeClient is not initialized or connected".
    + status = false, code = -2, message = "User id can not be null".
    + conversations: A list of conversations.

getLastConversations(count: String, callback: (status, code, message, conversations))

Return latest conversations from server.
- count: Number of conversations you want to get
- callback: The result
    + status = true, code = 0, message = "Success"
    + status = false, code = -1, message = "StringeeClient is not initialized or connected".
    + conversations: A list of conversations.

getConversationsAfter(datetime: long, count: String, callback: (status, code, message, conversations))

Return a list of conversations which have updated time greater than datetime from server.
- datetime: A timestamp
- count: Number of conversations you want to get
- callback: The result
    + status = true, code = 0, message = "Success"
    + status = false, code = -1, message = "StringeeClient is not initialized or connected".
    + conversations: A list of conversations.

getConversationsBefore(datetime: long, count: String, callback: (status, code, message, conversations))

Return a list of conversations which have updated time smaller than datetime from server.
- datetime: A timestamp
- count: Number of conversations you want to get
- callback: The result
    + status = true, code = 0, message = "Success"
    + status = false, code = -1, message = "StringeeClient is not initialized or connected".
    + conversations: A list of conversations.

deleteConversation(conversationId: String, callback: (status, code, message))

Delete a conversation
- conversationId: The conversation ID
- callback: The result
    + status = true, code = 0, message = "Success"
    + status = false, code = -1, message = "StringeeClient is not initialized or connected".

addParticipants(conversationId: String, userIds: array, callback: (status, code, message, users))

Add participants to a conversation
- conversationId: The conversation ID
- userIds: Users' ID of participants
- callback: The result
    + status = true, code = 0, message = "Success"
    + status = false, code = -1, message = "StringeeClient is not initialized or connected".
    + users: A list of added participants

removeParticipants(conversationId: String, userIds: array, callback: (status, code, message, users))

Remove participants from a conversation
- conversationId: The conversation ID
- userIds: Users' ID of participants
- callback: The result
    + status = true, code = 0, message = "Success"
    + status = false, code = -1, message = "StringeeClient is not initialized or connected".
    + users: A list of removed participants

updateConversation(conversationId: String, params: map, callback: (status, code, message))

Update a conversation
- conversationId: The conversation ID
- params: {name: ?, avatar: ?}
- callback: The result
    + status = true, code = 0, message = "Success"
    + status = false, code = -1, message = "StringeeClient is not initialized or connected".
    + status = false, code = -2, message = "Conversation ID can not be null".

markConversationAsRead(conversationId: String, callback: (status, code, message))

Mark a conversation as read
- conversationId: The conversation ID
- callback: The result
    + status = true, code = 0, message = "Success"
    + status = false, code = -1, message = "StringeeClient is not initialized or connected".

getConversationWithUser(userId: String, callback: (status, code, message, conversation))

Return the existing conversation with given id of user.
- userId: User's id
- callback: The result
    + status = true, code = 0, message = "Success"
    + status = false, code = -1, message = "StringeeClient is not initialized or connected".
    + status = false, code = -2, message = "Generic error".
    + conversation: The existing conversation.

getUnreadConversationCount(callback: (status, code, message, count))

Return the number of unread conversation.
- userId: User's id
- callback: The result
    + status = true, code = 0, message = "Success"
    + status = false, code = -1, message = "StringeeClient is not initialized or connected".
    + status = false, code = -2, message = "Generic error".
    + count: The number of unread conversation.

sendBeginTyping(convId: string, callback: (status, code, message))

Send begin typing.
- convId: Conversation's id
- callback: The result
    + status = true, code = 0, message = "Success"
    + status = false, code = -1, message = "StringeeClient is not initialized or connected".
    + status = false, code = -2, message = "Generic error".

sendEndTyping(convId: string, callback: (status, code, message))

Send end typing.
- convId: Conversation's id
- callback: The result
    + status = true, code = 0, message = "Success"
    + status = false, code = -1, message = "StringeeClient is not initialized or connected".
    + status = false, code = -2, message = "Generic error".

sendMessage(message: map, callback: (status, code, message))

Send a message
- message: Message to send
- callback: The result
    + status = true, code = 0, message = "Success"
    + status = false, code = -1, message = "StringeeClient is not initialized or connected".

deleteMessage(conversationId: String, messageId: String, callback: (status, code, message))

Delete a message in a conversation
- conversationId: The conversation ID
- messageId: The message ID
- callback: The result
    + status = true, code = 0, message = "Success"
    + status = false, code = -1, message = "StringeeClient is not initialized or connected".

getLocalMessages(conversationId: String, count: int, callback: (status, code, message,messages))

Return stored messages of a conversation
- conversationId: The conversation ID
- count: Number of messages you want to get ID
- callback: The result
    + status = true, code = 0, message = "Success"
    + status = false, code = -1, message = "StringeeClient is not initialized or connected".
    + messages: A list of messages

getLastMessages(conversationId: String, count: int, callback: (status, code, message, messages))

Return latest messages of a conversation from server
- conversationId: The conversation ID
- count: Number of messages you want to get ID
- callback: The result
    + status = true, code = 0, message = "Success"
    + status = false, code = -1, message = "StringeeClient is not initialized or connected".
    + messages: A list of messages

getMessagesAfter(conversationId: String, seq: long, count: int, callback: (status, code, message, messages))

Return a list of messages of a conversation from server which have sequence greater than seq
- conversationId: The conversation ID
- seq: A sequence
- count: Number of messages you want to get ID
- callback: The result
    + status = true, code = 0, message = "Success"
    + status = false, code = -1, message = "StringeeClient is not initialized or connected".
    + messages: A list of messages

getMessagesBefore(conversationId: String, seq: long, count: int, callback: (status, code, message, messages))

Return a list of messages of a conversation from server which have sequence smaller than seq
- conversationId: The conversation ID
- seq: A sequence
- count: Number of messages you want to get ID
- callback: The result
    + status = true, code = 0, message = "Success"
    + status = false, code = -1, message = "StringeeClient is not initialized or connected".
    + messages: A list of messages

clearDb(callback: (status, code, message))

Clear local database
- callback: The result
    + status = true, code = 0, message = "Success"
    + status = false, code = -1, message = "StringeeClient is not initialized or connected".

getChatProfile(widgetKey: String, callback: (status, code, message, chatProfile))

Return a chat profile contain list of queue
- widgetKey: The key of your portal
- callback: The result
    + status = true, code = 0, message = "Success"
    + status = false, code = -1, message = "StringeeClient is not initialized or connected".
    + chatProfile: A chat profile.

getLiveChatToken(widgetKey: String, name: string, email: string, callback: (status, code, message, token))

Return a token for connect to Stringee server
- widgetKey: The key of your portal
- name: The name of customer
- email: The email of customer
- callback: The result
    + status = true, code = 0, message = "Success"
    + status = false, code = -1, message = "StringeeClient is not initialized or connected".
    + token: token.

updateUserInfo(name: string, email: string, avatar: string, callback: (status, code, message))

Update user info
- name: The name of customer
- email: The email of customer
- avatar: The avatar url of customer
- callback: The result
    + status = true, code = 0, message = "Success"
    + status = false, code = -1, message = "StringeeClient is not initialized or connected".

createLiveChatConversation(queueId: string, callback: (status, code, message, conversation))

Create a live chat conversation
- queueId: The id of queue
- callback: The result
    + status = true, code = 0, message = "Success"
    + status = false, code = -1, message = "StringeeClient is not initialized or connected".
    + conversation: A conversation.

acceptChatRequest(request: ChatRequest, callback: (status, code, message))

Accept chat request
- request: The chat request
- callback: The result
    + status = true, code = 0, message = "Success"
    + status = false, code = -1, message = "StringeeClient is not initialized or connected".

rejectChatRequest(request: ChatRequest, callback: (status, code, message))

Reject chat request
- request: The chat request
- callback: The result
    + status = true, code = 0, message = "Success"
    + status = false, code = -1, message = "StringeeClient is not initialized or connected".

createLiveChatTicket(widgetKey: string, name: string, email: string, note: string, callback: (status, code, message))

Create a ticket of live chat
- widgetKey: The key of your portal
- name: The name of customer
- email: The email of customer
- note: The description for ticket
- callback: The result
    + status = true, code = 0, message = "Success"
    + status = false, code = -1, message = "StringeeClient is not initialized or connected".

sendChatTranscript(email: string, convId: string, domain: string, callback: (status, code, message))

Send a chat transcript
- email: The email which you want to send
- convId: The id of conversation
- domain: The domain which you want to send
- callback: The result
    + status = true, code = 0, message = "Success"
    + status = false, code = -1, message = "StringeeClient is not initialized or connected".

endChat(convId: string, callback: (status, code, message))

Reject chat request
- convId: The id of conversation
- callback: The result
    + status = true, code = 0, message = "Success"
    + status = false, code = -1, message = "StringeeClient is not initialized or connected".