Skip to content

Latest commit

 

History

History
1513 lines (995 loc) · 75.3 KB

File metadata and controls

1513 lines (995 loc) · 75.3 KB

WebimClientLibrary Reference Book

Table of contents

Webim class

Set of static methods which are used for session object creating and working with remote notifications that are sent by Webim service.

Class method newSessionBuilder()

Returns SessionBuilder class instance that is necessary to create WebimSession class instance.

Class method parse(remoteNotification:)

Converts iOS remote notification object into WebimRemoteNotification object. remoteNotification parameter takes [AnyHashable: Any] dictionary (which can be taken inside application(_ application:,didReceiveRemoteNotification userInfo:) AppDelegate class method from userInfo parameter). Method can return nil if remoteNotification parameter value doesn't fit to Webim service remote notification format or if it doesn't contain any useful payload. Preliminarily you can call method isWebim(remoteNotification:) on this value to know if this notification is send by Webim service.

Class method isWebim(remoteNotification:)

Allows to know if particular remote notification object represents Webim service remote notification. remoteNotification parameter takes [AnyHashable: Any] dictionary (which can be taken inside application(_ application:,didReceiveRemoteNotification userInfo:) AppDelegate class method from userInfo parameter). Returns true or false.

RemoteNotificationSystem enum

Enumerates push notifications systems that can be used with WebimClientLibrary. Enum values are used to be passed to method set(remoteNotificationSystem:) SessionBuilder class instance method.

APNS case

Apple Push Notification System.

NONE case

App does not receive remote notification from Webim service.

Go to table of contents

SessionBuilder class

Instance of this class is used to get WebimSession object. SessionBuilder class instance can be retreived with newSessionBuilder() Webim class method.

Instance method set(accountName:)

Sets Webim service account name. accountName parameter – String-typed account name. Usually is represented by server URL (e.g. "https://demo.webim.ru"), but also can be just one word (e.g. "demo") Returns self with account name set. Method is mandatory to create WebimSession object.

Instance method set(location:)

Sets location name for the session. location parameter – String-typed location name. Usually default available location names are "mobile" and "default". To create any other one you can contact service support. Returns self with location name set. Method is mandatory to create WebimSession object.

Instance method set(appVersion:)

Sets app version number if it is necessary to differentiate its values inside Webim service. appVersion parameter – optional String-typed app version. Returns self with app version set. When passed nil it does nothing. Method is not mandatory to create WebimSession object.

Instance method set(visitorFieldsJSONString:)

Sets visitor authorization data. Without this method calling a visitor is anonymous, with randomly generated ID. This ID is saved inside app UserDefaults and can be lost (e.g. when app is uninstalled), thereby message history is lost too. Authorized visitor data are saved by server and available with any device. jsonString parameter – JSON-formatted String-typed visitor fields. Returns self with visitor authorization data set. Method is not mandatory to create WebimSession object. Can't be used simultanously with set(providedAuthorizationTokenStateListener:,providedAuthorizationToken:) method.

Instance method set(visitorFieldsJSONData:)

Absolutely similar to method set(visitorFieldsJSONString jsonString:). jsonData parameter – JSON-formatted Data-typed visitor fields.

Instance method set(providedAuthorizationTokenStateListener:providedAuthorizationToken:)

When client provides custom visitor authorization mechanism, it can be realised by providing custom authorization token which is used instead of visitor fields. Method sets ProvidedAuthorizationTokenStateListener object and provided authorization token. Setting custom token is optional, if is not set, library generates its own. Returns self with visitor authorization data set. Method is not mandatory to create WebimSession object. Can't be used simultaneously with set(visitorFieldsJSONString:) or set(visitorFieldsJSONString:).

Instance method set(pageTitle:)

Sets chat title which is visible by an operator. Default value is "iOS Client" pageTitleString-typed chat title. Returns self with chat title set. Method is not mandatory to create WebimSession object.

Instance method set(fatalErrorHandler:)

Sets FatalErrorHandler object for session. fatalErrorHandler parameter – any object of a class or struct that conforms to FatalErrorHandler protocol (or nil). Returns self with FatalErrorHandler set. When nil passed it does nothing. Method is not mandatory to create WebimSession object.

Instance method set(remoteNotificationSystem:)

Sets remote notification system to use for receiving push notifications from Webim service. remoteNotificationSystem parameter – RemoteNotificationSystem enum value. If parameter value is not NONE, set(deviceToken:) method is mandatory to be called too. With NONE value passed it does nothing. Method is not mandatory to create WebimSession object.

Instance method set(deviceToken:)

Sets device token for push notification receiving. deviceToken parameter – String-typed device token in hexadecimal format and without any spaces and service symbols. Code example to convert device token to the right format:

let deviceToken = deviceToken.map { String(format: "%02.2hhx", $0) }.joined()

Returns self with device token set. For the proper remote notifications configuration this method call is not sufficient. You have to call set(remoteNotificationSystem:) method too. Method is not mandatory to create WebimSession object.

Instance method set(isLocalHistoryStoragingEnabled:)

By default session saves message history inside SQLite DB file. To deactivate this functionality you can use this method with false parameter isLocalHistoryStoragingEnabled value (with true value passed it does nothing). Returns self with the functionality activation setting. Method is not mandatory to create WebimSession object.

Instance method set(isVisitorDataClearingEnabled:)

Sets necesarity to clear all visitor data before session is created. With false isVisitorDataClearingEnabled parameter value passed it does nothing. Returns self with the functionality activation setting. Method is not mandatory to create WebimSession object.

Instance method set(webimLogger:verbosityLevel:)

Method to pass WebimLogger object. Parameter verbosityLevelWebimLoggerVerbosityLevel case (can be skipped). Returns self with the functionality activation setting. Method is not mandatory to create WebimSession object.

Instance method build()

Final method that returns WebimSession object. Can throw errors of SessionBuilderError type. The only two mandatory method to call preliminarily are set(accountName:) and set(location:).

WebimLoggerVerbosityLevel enum

Verbosity level of WebimLogger.

VERBOSE case

All available information will be delivered to WebimLogger instance with maximum verbosity level:

  • session network setup parameters;
  • network requests' URLs, HTTP method and parameters;
  • network responses' HTTP codes, received data and errors;
  • SQL queries and errors;
  • full debug information and additional notes.

DEBUG case

All information which is useful when debugging will be delivered to WebimLogger instance with necessary verbosity level:

  • session network setup parameters;
  • network requests' URLs, HTTP method and parameters;
  • network responses' HTTP codes, received data and errors;
  • SQL queries and errors;
  • moderate debug information.

INFO case

Reference information and all warnings and errors will be delivered to WebimLogger instance:

  • network requests' URLS, HTTP method and parameters;
  • HTTP codes and errors descriptions of failed requests.
  • SQL errors.

WARNING case

Errors and warnings only will be delivered to WebimLogger instance:

  • network requests' URLs, HTTP method, parameters, HTTP code and error description.
  • SQL errors.

ERROR case

Only errors will be delivered to WebimLogger instance:

  • network requests' URLs, HTTP method, parameters, HTTP code and error description.

SessionBuilderError enum

Error types that can be throwed by SessionBuilder method build().

NIL_ACCOUNT_NAME case

Error that is thrown when trying to create session object with nil account name.

NIL_LOCATION case

Error that is thrown when trying to create session object with nil location name.

INVALID_AUTHENTICATION_PARAMETERS case

Error that is thrown when trying to use standard and custom visitor fields authentication simultaneously.

INVALID_REMOTE_NOTIFICATION_CONFIGURATION case

Error that is thrown when trying to create session object with invalid remote notifications configuration.

Go to table of contents

ProvidedAuthorizationTokenStateListener protocol

When client provides custom visitor authorization mechanism, it can be realised by providing custom authorization token which is used instead of visitor fields. When provided authorization token is generated (or passed to session by client app), update(providedAuthorizationToken:) method is called. This method call indicates that client app must send provided authorisation token to its server which is responsible to send it to Webim service. This mechanism can't be used as is. It requires that client server to support this mecahnism.

update(providedAuthorizationToken:) method

Method is called in two cases:

  1. Provided authorization token is genrated (or set by client app) and must be sent to client server which is responsible to send it to Webim service.
  2. Passed provided authorization token is not valid. Provided authorization token can be invalid if Webim service did not receive it from client server yet. When this method is called, client server must send provided authorization token to Webim service. providedAuthorizationToken parameter contains provided authentication token which is set and which must be sent to Webim service by client server.

Go to table of contents

WebimSession protocol

Provides methods to manipulate with WebimSession object.

resume() method

Resumes session networking Session is created as paused. To start using it firstly you should call this method. Can throw errors of AccessError type.

pause() method

Pauses session networking. If is already paused the method does nothing. Can throw errors of AccessError type.

destroy() method

Deactivates session. After that any session methods are not available. Can throw errors of AccessError type.

getStream() method

Returns MessageStream object attached to this session. Each invocation of this method returns the same object.

change(location:) method

Changes location without creating a new session. location parameter – new location name of String type. Can throw errors of AccessError type.

set(deviceToken:) method

Sets device token.

Go to table of contents

MessageStream protocol

Provides methods to interact with Webim service.

getVisitSessionState() method

Returns current session state (VisitSessionState type.

getChatState() method

Returns current chat state of ChatState type.

getUnreadByOperatorTimestamp() method

Returns timestamp (of type Date) after which all chat messages are unread by operator (at the moment of last server update recieved).

getUnreadByVisitorMessageCount() method

Returns unread by visitor message count.

getUnreadByVisitorTimestamp() method

Returns timestamp (of type Date) after which all chat messages are unread by visitor (at the moment of last server update recieved) or nil if there's no unread by visitor messages.

getDepartmentList() method

Returns array of departments (Department) or nil if there're any or department list is not recieved yet.

getLocationSettings() method

Returns current LocationSettings object.

getCurrentOperator() method

Returns Operator object of the current chat or nil if one does not exist.

getLastRatingOfOperatorWith(id:) method

Returns previous rating of the operator or 0 if it was not rated before. id parameter – String-typed ID of operator.

rateOperatorWith(id:byRating:completionHandler:) method

Rates an operator. To get an ID of the current operator call getCurrentOperator(). id parameter – String-typed ID of the operator to be rated. Optional: if nil is passed, current chat operator will be rated. rating parameter – a number in range (1...5) that represents an operator rating. If the number is out of range, rating will not be sent to a server. completionHandler parameter – RateOperatorCompletionHandler object. Can throw errors of AccessError type.

startChat() method

Changes ChatState to QUEUE. Method call is not mandatory, send message or send file methods start chat automatically. If account settings provide automatic complimentary message it won't be sent before any "startChat" method or first sent message. Can throw errors of AccessError type.

startChat(firstQuestion:) method

Changes ChatState to QUEUE. Starts chat and sends first message simultaneously. Method call is not mandatory, send message or send file methods start chat automatically. If account settings provide automatic complimentary message it won't be sent before any "startChat" method or first sent message. Can throw errors of AccessError type.

startChat(departmentKey:) method

Starts chat with particular department. Department is identified by departmentKey parameter (see getKey() of Department protocol) Changes ChatState to QUEUE. In most cases method call is not mandatory, send message or send file methods start chat automatically. But it is mandatory when VisitSessionState is in DEPARTMENT_SELECTION state. If account settings provide automatic complimentary message it won't be sent before any "startChat" method or first sent message. Can throw errors of AccessError type.

startChat(departmentKey:firstQuestion:) method

Starts chat with particular department and sends first message simultaneously. Department is identified by departmentKey parameter (see getKey() of Department protocol) Changes ChatState to QUEUE. In most cases method call is not mandatory, send message or send file methods start chat automatically. But it is mandatory when VisitSessionState is in DEPARTMENT_SELECTION state. If account settings provide automatic complimentary message it won't be sent before any "startChat" method or first sent message. Can throw errors of AccessError type.

closeChat() method

Changes ChatState to CLOSED_BY_VISITOR. Can throw errors of AccessError type.

setVisitorTyping(draftMessage:) method

This method must be called whenever there is a change of the input field of a message transferring current content of a message as a parameter. When nil value passed it means that visitor stopped to type a message or deleted it. When there's multiple calls of this method occured, draft message is sending to service one time per second. Can throw errors of AccessError type.

send(message:data:completionHandler:) method

Sends a text message. When calling this method, if there is an active MessageTracker object. added(message newMessage:,after previousMessage:) method) with a message SENDING case in the status is also called. message parameter – String-typed message text. data parameter is optional, custom message parameters dictionary. Note that this functionality does not work as is – server version must support it. completionHandler parameter – optional DataMessageCompletionHandler object. Returns randomly generated String-typed ID of the message. Can throw errors of AccessError type.

send(message:isHintQuestion:) method

Sends a text message. When calling this method, if there is an active MessageTracker object. added(message newMessage:,after previousMessage:) method) with a message SENDING case in the status is also called. message parameter – String-typed message text. isHintQuestion parameter shows to server if a visitor chose a hint (true value) or wrote his own text (false). Optional to use. Returns randomly generated String-typed ID of the message. Can throw errors of AccessError type.

send(file:filename:mimeType:completionHandler:) method

Sends a file message. When calling this method, if there is an active MessageTracker object. added(message newMessage:,after previousMessage:) method) with a message SENDING case in the status is also called. file parameter – file represented in Data type. filename parameter – file name of String type. mimeType parameter – MIME type of the file to send of String type. completionHandler parameter – optional SendFileCompletionHandler object. Returns randomly generated String-typed ID of the message. Can throw errors of AccessError type.

newMessageTracker(messageListener:) method

Returns MessageTracker object wich (via getNextMessages(byLimit limitOfMessages:,completion:)) allows to request the messages from above in the history. Each next call getNextMessages(byLimit limitOfMessages:,completion:) returns earlier messages in relation to the already requested ones. Changes of user-visible messages (e.g. ever requested from MessageTracker) are transmitted to MessageListener. That is why MessageListener object is needed when creating MessageTracker. For each MessageStream at every single moment can exist the only one active MessageTracker. When creating a new one at the previous there will be automatically called destroy(). Can throw errors of AccessError type.

set(visitSessionStateListener:) method

Sets VisitSessionStateListener object to track changes of VisitSessionState.

set(chatStateListener:) method

Sets ChatStateListener object.

set(currentOperatorChangeListener:) method

Sets CurrentOperatorChangeListener object.

set(departmentListChangeListener:) method

Sets DepartmentListChangeListener object to track changes of department list.

set(operatorTypingListener:) method

Sets OperatorTypingListener object.

set(locationSettingsChangeListener:) method

Sets LocationSettingsChangeListener object.

set(onlineStatusChangeListener:) method

Sets OnlineStatusChangeListener object.

set(unreadByOperatorTimestampChangeListener:) method

Sets UnreadByOperatorTimestampChangeListener object.

set(unreadByVisitorMessageCountChangeListener:) method

Sets UnreadByVisitorMessageCountChangeListener object.

set(unreadByVisitorTimestampChangeListener:) method

Sets UnreadByVisitorTimestampChangeListener object.

Go to table of contents

DataMessageCompletionHandler protocol

Protocol which methods are called after send(message:data:completionHandler:) method is finished. Must be adopted.

onSuccess(messageID:) method

Executed when operation is done successfully. messageID parameter – ID of the appropriate message of String type.

onFailure(messageID:error:) method

Executed when operation is failed. messageID parameter – ID of the appropriate message of String type. error parameter – appropriate DataMessageError value.

Go to table of contents

SendFileCompletionHandler protocol

Protocol which methods are called after send(file:filename:mimeType:completionHandler:) method is finished. Must be adopted.

onSuccess(messageID:) method

Executed when operation is done successfully. messageID parameter – ID of the appropriate message of String type.

onFailure(messageID:error:) method

Executed when operation is failed. messageID parameter – ID of the appropriate message of String type. error parameter – appropriate SendFileError value.

Go to table of contents

RateOperatorCompletionHandler protocol

Protocol which methods are called after rateOperatorWith(id:byRating:completionHandler:) method is finished. Must be adopted.

onSuccess() method

Executed when operation is done successfully.

onFailure(error:) method

Executed when operation is failed. error parameter – appropriate RateOperatorError value.

Go to table of contents

VisitSessionStateListener protocol

Provides methods to track changes of VisitSessionState status.

changed(state:to:) method

Called when VisitSessionState status is changed. Parameters contain its previous and new values.

Go to table of contents

DepartmentListChangeListener protocol

Provides methods to track changes in departments list.

received(departmentList:) method

Called when department list is received. Current department list passed inside departmentList parameter and presents array of Department objects.

Go to table of contents

LocationSettings protocol

Interface that provides methods for handling LocationSettings which are received from server.

areHintsEnabled() method

This method shows to an app if it should show hint questions to visitor. Returns true if an app should show hint questions to visitor, false otherwise.

Go to table of contents

ChatStateListener protocol

Protocol that is to be adopted to track ChatState changes.

changed(state:to:) method

Called during ChatStatetransition. Parameters are of ChatState type.

Go to table of contents

CurrentOperatorChangeListener protocol

Protocol that is to be adopted to track if current Operator object is changed.

changed(operator:to:) method

Called when Operator object of the current chat changed. New one value can be nil (if an operator leaved the chat).

Go to table of contents

OperatorTypingListener protocol

Protocol that is to be adopted to track if the operator started or ended to type a message.

onOperatorTypingStateChanged(isTyping:) method

Called when operator typing state changed. Parameter isTyping is true if operator is typing, false otherwise.

Go to table of contents

LocationSettingsChangeListener protocol

Interface that provides methods for handling changes in LocationSettings.

changed(locationSettings:to:) method

Method called by an app when new LocationSettings object is received with parameters that represent previous and new LocationSettings objects.

Go to table of contents

OnlineStatusChangeListener protocol

Interface that provides methods for handling changes of session status.

changed(onlineStatus:to:) method

Called when new session status is received with parameters that represent previous and new OnlineStatus values.

Go to table of contents

UnreadByOperatorTimestampChangeListener protocol

Interface that provides methods for handling changes of parameter that is to be returned by getUnreadByOperatorTimestamp() method. Can be set by set(unreadByOperatorTimestampChangeListener:) method.

changedUnreadByOperatorTimestampTo(newValue:) method

Method to be called when parameter that is to be returned by getUnreadByOperatorTimestamp() method method is changed.

Go to table of contents

UnreadByVisitorMessageCountChangeListener protocol

Interface that provides methods for handling changes of parameter that is to be returned by getUnreadByVisitorMessageCount() method. Can be set by set(unreadByVisitorMessageCountChangeListener:) method.

changedUnreadByVisitorMessageCountTo(newValue:) method

Method to be called when parameter that is to be returned by getUnreadByVisitorMessageCount() method method is changed.

Go to table of contents

UnreadByVisitorTimestampChangeListener protocol

Interface that provides methods for handling changes of parameter that is to be returned by getUnreadByVisitorTimestamp() method. Can be set by set(unreadByVisitorTimestampChangeListener:) method.

changedUnreadByVisitorTimestampTo(newValue:) method

Method to be called when parameter that is to be returned by getUnreadByVisitorTimestamp() method method is changed.

Go to table of contents

ChatState enum

A chat is seen in different ways by an operator depending on ChatState. The initial state is NONE. Then if a visitor sends a message (send(message:isHintQuestion:)), the chat changes it's state to QUEUE. The chat can be turned into this state by calling startChat() method. After that, if an operator takes the chat to process, the state changes to CHATTING. The chat is being in this state until the visitor or the operator closes it. When closing a chat by the visitor closeChat() method it turns into the state CLOSED_BY_VISITOR, by the operator - CLOSED_BY_OPERATOR. When both the visitor and the operator close the chat, it's state changes to the initial – NONE. A chat can also automatically turn into the initial state during long-term absence of activity in it. Furthermore, the first message can be sent not only by a visitor but also by an operator. In this case the state will change from the initial to INVITATION, and then, after the first message of the visitor, it changes to CHATTING.

CHATTING case

Means that an operator has taken a chat for processing. From this state a chat can be turned into:

CHATTING_WITH_ROBOT case

Means that chat is picked up by a bot. From this state a chat can be turned into:

CLOSED_BY_OPERATOR case

Means that an operator has closed the chat. From this state a chat can be turned into:

CLOSED_BY_VISITOR case

Means that a visitor has closed the chat. From this state a chat can be turned into:

INVITATION case

Means that a chat has been started by an operator and at this moment is waiting for a visitor's response. From this state a chat can be turned into:

NONE case

Means the absence of a chat as such, e.g. a chat has not been started by a visitor nor by an operator. From this state a chat can be turned into:

QUEUE case

Means that a chat has been started by a visitor and at this moment is being in the queue for processing by an operator. From this state a chat can be turned into:

  • CHATTING, if an operator takes the chat for processing;
  • NONE, if a visitor closes the chat (by calling (closeChat() method) before it is taken for processing;
  • CLOSED_BY_OPERATOR, if an operator closes the chat without taking it for processing.

UNKNOWN case

The state is undefined. This state is set as the initial when creating a new session, until the first response of the server containing the actual state is got. This state is also used as a fallback if WebimClientLibrary can not identify the server state (e.g. if the server has been updated to a version that contains new states).

Go to table of contents

OnlineStatus enum

Online state possible cases.

BUSY_OFFLINE case

Offline state with chats' count limit exceeded. Means that visitor is not able to send messages at all.

BUSY_ONLINE case

Online state with chats' count limit exceeded. Visitor is able send offline messages, but the server can reject it.

OFFLINE case

Visitor is able send offline messages.

ONLINE case

Visitor is able to send both online and offline messages.

UNKNOWN case

Session has not received first session status yet or session status is not supported by this version of the library.

Go to table of contents

VisitSessionState enum

Session possible states.

CHAT case

Chat in progress.

DEPARTMENT_SELECTION case

Chat must be started with department selected (there was a try to start chat without department selected).

IDLE case

Session is active but no chat is occuring (chat was not started yet).

IDLE_AFTER_CHAT case

Session is active but no chat is occuring (chat was closed recently).

OFFLINE_MESSAGE case

Offline state.

UNKNOWN case

First status is not recieved yet or status is not supported by this version of the library.

Go to table of contents

DataMessageError enum

Error types that could be passed in onFailure(messageID:error:) method.

UNKNOWN case

Received error is not supported by current WebimClientLibrary version.

Quoted message errors.

QUOTED_MESSAGE_CANNOT_BE_REPLIED case

To be raised when quoted message ID belongs to a message without canBeReplied flag set to true (this flag is to be set on the server-side).

QUOTED_MESSAGE_FROM_ANOTHER_VISITOR case

To be raised when quoted message ID belongs to another visitor chat.

QUOTED_MESSAGE_MULTIPLE_IDS case

To be raised when quoted message ID belongs to multiple messages (server data base error).

QUOTED_MESSAGE_REQUIRED_ARGUMENTS_MISSING case

To be raised when one or more required arguments of quoting mechanism are missing.

QUOTED_MESSAGE_WRONG_ID case

To be raised when wrong quoted message ID is sent.

Go to table of contents

SendFileError enum

Error types that could be passed in onFailure(messageID:error:) method.

FILE_SIZE_EXCEEDED case

The server may deny a request if the file size exceeds a limit. The maximum size of a file is configured on the server.

FILE_TYPE_NOT_ALLOWED case

The server may deny a request if the file type is not allowed. The list of allowed file types is configured on the server.

Go to table of contents

RateOperatorError enum

Error types that could be passed in onFailure(error:) method.

NO_CHAT case

Arised when trying to send operator rating request if no chat is exists.

WRONG_OPERATOR_ID case

Arised when trying to send operator rating request if passed operator ID doesn't belong to existing chat operator (or, in the same place, chat doesn't have an operator at all).

Go to table of contents

MessageTracker protocol

MessageTracker object has two purposes:

getLastMessages(byLimit:completion:) method

Requests last messages from history. Returns not more than limitOfMessages of messages. If an empty list is passed inside completion, there no messages in history yet. If there is any previous MessageTracker request that is not completed, or limit of messages is less than 1, or current MessageTracker has been destroyed, this method will do nothing. Following history request can be fulfilled by getLastMessages(byLimit:completion:) method. Completion is called with received array of Message objects as the parameter. It is guaranteed that completion will be called with empty or not result if call didn't throw an error. If current MessageTracker is destroyed completion will be called on empty result. Can throw errors of AccessError type.

getNextMessages(byLimit:completion:) method

Requests the messages above in history. Returns not more than limitOfMessages of messages. If an empty list is passed inside completion, the end of the message history is reached. If there is any previous MessageTracker request that is not completed, or limit of messages is less than 1, or current MessageTracker has been destroyed, this method will do nothing. Notice that this method can not be called again until the callback for the previous call will be invoked. Completion is called with received array of Message objects as the parameter. It is guaranteed that completion will be called with empty or not result if call didn't throw an error. If current MessageTracker is destroyed completion will be called on empty result. Can throw errors of AccessError type.

getAllMessages(completion:) method

Requests all messages from history. If an empty list is passed inside completion, there no messages in history yet. If there is any previous MessageTracker request that is not completed, or current MessageTracker has been destroyed, this method will do nothing. This method is totally independent on getLastMessages(byLimit:completion:) and getNextMessages(byLimit:completion:) methods calls. Completion is called with received array of Message objects as the parameter. It is guaranteed that completion will be called with empty or not result if call didn't throw an error. If current MessageTracker is destroyed completion will be called on empty result. Can throw errors of AccessError type.

resetTo(message:) method

MessageTracker retains some range of messages. By using this method one can move the upper limit of this range to another message. If there is any previous MessageTracker request that is not completed, this method will do nothing. Notice that this method can not be used unless the previous call getNextMessages(byLimit:completion:) was finished (completion handler was invoked). Parameter messageMessage object reset to. Can throw errors of AccessError type.

destroy() method

Destroys the MessageTracker. It is impossible to use any MessageTracker methods after it was destroyed. Isn't mandatory to be called.

Go to table of contents

MessageListener protocol

Should be adopted. Provides methods to track changes inside message stream.

added(message:after:) method

Called when added a new message. If previousMessage == nil then it should be added to the end of message history (the lowest message is added), in other cases the message should be inserted before the message (i.e. above in history) which was given as a parameter previousMessage. Notice that this is a logical insertion of a message. I.e. calling this method does not necessarily mean receiving a new (unread) message. Moreover, at the first call getNextMessages(byLimit:completion:) most often the last messages of a local history (i.e. which is stored on a user's device) are returned, and this method will be called for each message received from a server after a successful connection. Parameters are of type Message. previousMessage represents a message after which it is needed to make a message insert. If nil then an insert is performed at the end of the list.

removed(message:) method

Called when removing a message. message parameter is of type Message.

removedAllMessages() method

Called when removed all the messages.

changed(message:to:) method

Called when changing a message. Message is an immutable type and field values can not be changed. That is why message changing occurs as replacing one object with another. Thereby you can find out, for example, which certain message fields have changed by comparing an old and a new object values. Parameters are of type Message.

Go to table of contents

Message protocol

Abstracts a single message in the message history. A message is an immutable object. It means that changing some of the message fields creates a new object. Messages can be compared by using isEqual(to:) method for searching messages with the same set of fields or by ID (message1.getID() == message2.getID()) for searching logically identical messages. ID is formed on the client side when sending a message (send(message:isHintQuestion:) or send(file:filename:mimeType:completionHandler:)).

getAttachment() method

Messages of the types FILE_FROM_OPERATOR and FILE_FROM_VISITOR can contain attachments. Returns MessageAttachment object. Notice that this method may return nil even in the case of previously listed types of messages. E.g. if a file is being sent.

getData() method

Messages of type ACTION_REQUEST contain custom dictionary. Returns dictionary which contains custom fields or nil if there's no such custom fields.

getID() method

Every message can be uniquefied by its ID. Messages also can be lined up by its IDs. ID doesn’t change while changing the content of a message. Returns unique ID of the message of type String.

getOperatorID() method

Returns ID of a message sender, if the sender is an operator, of type String.

getSenderAvatarFullURL() method

Returns URL of a sender's avatar or nil if one does not exist.

getSenderName() method

Returns name of a message sender of type String.

getSendStatus() method

Returns SENT if a message had been sent to the server, was received by the server and was delivered to all the clients; SENDING if not.

getText() method

Returns text of the message of type String.

getTime() method

Returns Date the message was processed by the server.

getType() method

Returns type of a message of MessageType type.

isEqual(to:) method

Method which can be used to compare if two Message objects have identical contents. Returns true if two Message objects are identical and false otherwise.

Example code:

if messageOne.isEqual(to: messageTwo) { /* … */ }

Where messageOne and messageTwo are any Message objects.

Go to table of contents

MessageAttachment protocol

Contains information about an attachment file.

getContentType() method

Returns MIME-type of an attachment file of optional String type.

getFileName() method

Returns name of an attachment file of optional String type.

getImageInfo() method

If a file is an image, returns ImageInfo object; in other cases returns nil.

getSize() method

Returns attachment file size in bytes of Int64 type.

getURLString() method

Returns URL of the file or nil. Notice that this URL is short-living and is tied to a session.

Go to table of contents

ImageInfo protocol

Provides information about an image.

getThumbURL() method

Returns a URL of an image thumbnail. The maximum width and height is usually 300 px but it can be adjusted at server settings. To get an actual preview size before file uploading is completed, use the following code:

let THUMB_SIZE = 300
var width = imageInfo.getWidth()
var height = imageInfo.getHeight()
if (height > width) {
    width = (THUMB_SIZE * width) / height
    height = THUMB_SIZE
} else {
    height = (THUMB_SIZE * height) / width
    width = THUMB_SIZE
}

Notice that this URL is short-living and is tied to a session.

getHeight() method

Returns height of an image in pixels of Int type or nil.

getWidth() method

Returns width of an image in pixels of Int type or nil.

Go to table of contents

MessageType enum

Message type representation.

ACTION_REQUEST case

A message from operator which requests some actions from a visitor. E.g. choose an operator group by clicking on a button in this message.

CONTACTS_REQUEST case

Message type that is received after operator clicked contacts request button. There's no this functionality automatic support yet. All payload is transfered inside standard text field.

FILE_FROM_OPERATOR case

A message sent by an operator which contains an attachment.

FILE_FROM_VISITOR case

A message sent by a visitor which contains an attachment.

INFO case

A system information message. Messages of this type are automatically sent at specific events. E.g. when starting a chat, closing a chat or when an operator joins a chat.

OPERATOR case

A text message sent by an operator.

OPERATOR_BUSY case

A system information message which indicates that an operator is busy and can't reply to a visitor at the moment.

VISITOR case

A text message sent by a visitor.

Go to table of contents

MessageSendStatus enum

Until a message is sent to the server, is received by the server and is spreaded among clients, message can be seen as "being send"; at the same time Message.getSendStatus() will return SENDING. In other cases - SENT.

SENDING case

A message is being sent.

SENT case

A message had been sent to the server, received by the server and was spreaded among clients.

Go to table of contents

Department protocol

Single department entity. Provides methods to get department information. Department objects can be received through DepartmentListChangeListener protocol methods and getDepartmentList() method of MessageStream protocol.

getKey() method

Department key is used to start chat with some department. Presented by String object. Used for startChat(departmentKey:) method of MessageStream protocol call.

getName() method

Returns department public name. Presented by String object.

getDepartmentOnlineStatus() method

Returns department online status. Presented by DepartmentOnlineStatus object.

getOrder() method

Returns order number. Presented by Int value. Higher numbers match higher priority.

getLocalizedNames() method

Returns dictionary of department localized names (if exists). Presented by [String: String] dictonary. Key is custom locale descriptor, value is matching name.

Returns department logo URL (if exists). Presented by URL object.

Go to table of contents

DepartmentOnlineStatus enum

Possible department online statuses. Can be retreived by getDepartmentOnlineStatus() method of Department protocol.

BUSY_OFFLINE case

Offline state with chats' count limit exceeded.

BUSY_ONLINE case

Online state with chats' count limit exceeded.

OFFLINE case

Visitor is able to send offline messages.

ONLINE case

Visitor is able to send both online and offline messages.

UNKNOWN case

Any status that is not supported by this version of the library.

Go to table of contents

Operator protocol

Presents chat operator object.

getID() method

Returns unique ID of the operator of String type.

getName() method

Returns display name of the operator of String type.

getAvatarURL() method

Returns URL of the operator’s avatar or nil if does not exist.

Go to table of contents

WebimRemoteNotification protocol

Abstracts a remote notifications from Webim service.

getType() method

Returns type of this remote notification of NotificationType type.

getEvent() method

Returns event of this remote notification of NotificationEvent type or nil.

getParameters() method

Returns parameters of this remote notification of array of type String type. Each NotificationType has specific list of parameters.

Go to table of contents

NotificationType enum

Represents payload type of remote notification.

CONTACT_INFORMATION_REQUEST case

This notification type indicated that contact information request is sent to a visitor.

Parameters: empty.

OPERATOR_ACCEPTED case

This notification type indicated that an operator has connected to a dialogue.

Parameters:

  • Operator's name.

OPERATOR_FILE case

This notification type indicated that an operator has sent a file.

Parameters:

  • Operator's name;
  • File name.

OPERATOR_MESSAGE case

This notification type indicated that an operator has sent a text message.

Parameters:

  • Operator's name;
  • Message text.

WIDGET case

This notification type indicated that an operator has sent a widget message. This type can be received only if server supports this functionality.

Parameters: empty.

Go to table of contents

NotificationEvent enum

Represents meaned type of action when remote notification is received.

ADD case

Means that a notification should be added by current remote notification.

DELETE case

Means that a notification should be deleted by current remote notification.

Go to table of contents

FatalErrorHandler protocol

Must be adopted to handle service errors that can occur.

on(error:) method

This method is to be called when Webim service error is received. Notice that method called NOT FROM THE MAIN THREAD!

error parameter is of WebimError type.

Go to table of contents

FatalErrorType enum

Webim service error types. Mind that most of this errors causes session to destroy.

ACCOUNT_BLOCKED case

Indicates that the account in Webim service has been disabled (e.g. for non-payment). The error is unrelated to the user’s actions. Recommended response is to show the user an error message with a recommendation to try using the chat later.

Notice that the session will be destroyed if this error occured.

NO_CHAT case

Indicates that there was a try to perform action that requires existing chat, but there's no chat. E.g. see rateOperatorWith(id:,byRating rating:) method of MessageStream protocol.

PROVIDED_VISITOR_FIELDS_EXPIRED case

Indicates an expired authorization of a visitor. The recommended response is to re-authorize it and to re-create session object.

Notice that the session will be destroyed if this error occured.

UNKNOWN case

Indicates the occurrence of an unknown error. Recommended response is to send an automatic bug report and show to a user an error message with the recommendation to try using the chat later.

Notice that the session will be destroyed if this error occured.

VISITOR_BANNED case

Indicates that a visitor was banned by an operator and can't send messages to a chat anymore. Occurs when a user tries to open the chat or write a message after that. Recommended response is to show the user an error message with the recommendation to try using the chat later or explain to the user that it was blocked for some reason.

Notice that the session will be destroyed if this error occured.

WRONG_PROVIDED_VISITOR_HASH case

Indicates a problem of your application authorization mechanism and is unrelated to the user’s actions. Occurs when trying to authorize a visitor with a non-valid signature. Recommended response is to send an automatic bug report and show the user an error message with the recommendation to try using the chat later.

Notice that the session will be destroyed if this error occured.

Go to table of contents

WebimError protocol

Abstracts Webim service possible fatal error.

getErrorType() method

Returns parsed type of the error of FatalErrorType type.

getErrorString() method

Returns String representation of an error. Mostly useful if the error type is unknown.

Go to table of contents

AccessError enum

Error types that can be throwed by MessageStream methods.

INVALID_THREAD case

Error that is thrown if the method was called not from the thread the WebimSession object was created in.

INVALID_SESSION case

Error that is thrown if WebimSession object was destroyed.

Go to table of contents

WebimLogger protocol

Protocol that provides methods for implementing custom WebimClientLibrary network requests logging. It can be useful for debugging production releases if debug logs are not available.

log(entry:) method

Method which is called after new WebimClientLibrary network request log entry came out. New log entry passed inside entry parameter.