KBMConversation Class Reference
| Inherits from | NSObject |
|---|---|
| Conforms to | NSSecureCoding |
| Declared in | KBMConversation.h |
Overview
The KBMConversation class provides an interface to interact with the current user’s conversation.
To obtain an instance, use [BrandMessenger conversation]. +initWithSettings:completionHandler: must have been called prior to retrieving the shared conversation object.
To send a message, use -sendMessage: with an KBMMessage object
Example:
[[BrandMessenger conversation] sendMessage:[[KBMMessage alloc] initWithText:@"Hello World!"]];
A notification will be fired indicating the success or failure of the message. To subscribe to these notifications, use NSNotificationCenter.
Example:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(messageUploaded:) name:KBMMessageUploadCompletedNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(messageFailed:) name:KBMMessageUploadFailedNotification object:nil];
conversationId
The unique identifier of the conversation. May be nil if a conversation doesn’t exist for the current user
@property (readonly, nullable) NSString *conversationIdDeclared In
KBMConversation.h
messages
The array of KBMMessage objects representing the conversation.
@property (readonly, nullable) NSArray *messagesSee Also
Declared In
KBMConversation.h
messageCount
The total number of messages in the conversation, including user-generated messages.
@property (readonly) NSUInteger messageCountDeclared In
KBMConversation.h
unreadCount
Count of unread messages in the conversation.
@property (readonly) NSUInteger unreadCountDiscussion
The primary use of this property is to be able to display an indicator / badge when the conversation has unread messages.
Declared In
KBMConversation.h
businessLastRead
Date when the business last read the user messages
@property (readonly, nullable) NSDate *businessLastReadDeclared In
KBMConversation.h
metadata
Metadata associated with the conversation.
@property (readonly, nullable) NSDictionary *metadataDiscussion
A flat dictionary of metadata set through the REST API. May be nil.
Declared In
KBMConversation.h
delegate
A delegate object for receiving notifications related to the conversation.
@property (weak, nullable) id<KBMConversationDelegate> delegateSee Also
Declared In
KBMConversation.h
hasPreviousMessages
Boolean representing whether there are previous messages in the conversation that can be fetched or not
@property (readonly) BOOL hasPreviousMessagesDiscussion
Returns YES if there are previous messages in the conversation, NO otherwise. For fetching previous messages, use [KBMConversation loadPreviousMessages]
Declared In
KBMConversation.h
lastUpdatedAt
NSDate representation of when the conversation was last updated.
@property (readonly, nullable) NSDate *lastUpdatedAtDiscussion
NSDate object set through the REST API and Web Socket. May be nil.
Declared In
KBMConversation.h
displayName
A display name for the conversation.
@property (readonly, nullable) NSString *displayNameDiscussion
This is set when a conversation is created. Can be nil.
Declared In
KBMConversation.h
conversationDescription
A conversation description for the conversation.
@property (readonly, nullable) NSString *conversationDescriptionDiscussion
This is set when a conversation is created. Can be nil.
Declared In
KBMConversation.h
iconUrl
A iconUrl for the conversation.
@property (readonly, nullable) NSString *iconUrlDiscussion
This is set when a conversation is created. Can be nil.
Declared In
KBMConversation.h
participants
An array of KBMParticipant objects currently in the conversation.
@property (readonly, nullable) NSArray *participantsSee Also
Declared In
KBMConversation.h
– markAllAsRead
Marks all unread messages as read.
- (void)markAllAsReadDiscussion
Marks all unread messages as read, and notifies that the unread count changed.
See Also
Declared In
KBMConversation.h
– loadPreviousMessages
Loads previous messages for this conversation, if any
- (void)loadPreviousMessagesDiscussion
Will get previous messages for this conversation based on the timestamp of the current oldest message and will notify the delegate of new incoming messages through [KBMConversationDelegate conversation:didReceivePreviousMessages:]
Declared In
KBMConversation.h
– sendMessage:
Adds a new message to the conversation.
- (void)sendMessage:(KBMMessage *)messageDiscussion
For each message added using sendMessage, a notification will be fired indicating the success or failure status of the upload.
Declared In
KBMConversation.h
– sendImage:withProgress:completion:
Adds an image message to the conversation.
- (void)sendImage:(UIImage *)image withProgress:(nullable KBMImageUploadProgressBlock)progressBlock completion:(nullable KBMImageUploadCompletionBlock)completionBlockParameters
image |
The image to upload. Must not be nil. |
|---|---|
progressBlock |
Called to report progress updates. May be nil. |
completionBlock |
Called when the upload completes or fails. May be nil. |
Discussion
Use the progress block to track the progress of the upload. Progress is reported as a number between 0 and 1.
The completion block is called when the operation completes, either in success or failure. Both blocks are guaranteed to be called on the main thread.
In case of success, the error parameter will be nil, and the message parameter will contain the newly created message. The message will already be part of the messages array when this block is called.
In case of failure, the message parameter will be nil, and the error parameter will contain the error that occurred.
Declared In
KBMConversation.h
– postback:completion:
Sends a postback to the server.
- (void)postback:(KBMMessageAction *)messageAction completion:(nullable void ( ^ ) ( NSError *_Nullable error ))completionBlockParameters
messageAction |
The messageAction for which to send the postback. Must not be nil. |
|---|---|
completionBlock |
Called when the postback completes or fails. May be nil. |
Discussion
The completion block is called when the operation completes, either in success or failure.
In case of success, the error parameter will be nil.
In case of failure, the error parameter will contain the error that occurred.
Declared In
KBMConversation.h
– retryMessage:
Retries a message that failed to send.
- (void)retryMessage:(KBMMessage *)failedMessageDiscussion
The failed message will be removed from the messages array, and a new message will be constructed with the same text as the failed message. A notification will be fired indicating the success or failure status of the upload.
Declared In
KBMConversation.h
– startTyping
Notify the server that the user is typing.
- (void)startTypingDiscussion
This method is called automatically when using the default conversation view controller. Only call this method if your application implements its own conversation view.
Typing updates are automatically throttled, so you may call this method as often as necessary. The typing stop event will automatically fire 10 seconds after the most recent call to this method.
Declared In
KBMConversation.h
– stopTyping
Notify the server that the user has finished typing.
- (void)stopTypingDiscussion
This method is called automatically when using the default conversation view controller. Only call this method if your application implements its own conversation view.
If the user was not flagged as typing recently, this method will result in a no-op.
Declared In
KBMConversation.h