MessageClient
public class MessageClient
MessageClient represents a client to the Webex platform. It can send and receive messages.
Use Webex.messages
to get an instance of MessageClient.
Since
1.4.0-
The callback handler for incoming message events.
Since
1.4.0Declaration
Swift
public var onEvent: ((MessageEvent) -> Void)? { get set }
-
The callback handler for incoming message events.
Since
2.3.0Declaration
Swift
public var onEventWithPayload: ((MessageEvent, WebexEventPayload) -> Void)? { get set }
-
Lists all messages in a space by space Id. The list sorts the messages in descending order by creation date.
Note that the file attachments of the message are not downloaded. Use
downloadFile(...)
ordownloadThumbnail(...)
to download the actual content or the thumbnail of the attachment.Since
1.4.0Declaration
Parameters
spaceId
The identifier of the space.
max
Limit the maximum number of messages in the response, default is 50.
before
If not nil, only list messages sent before this condition.
mentionedPeople
List messages where a person (using
Mention.person
) or all (usingMention.all
) is mentioned.queue
If not nil, the queue on which the completion handler is dispatched. Otherwise, the handler is dispatched on the application’s main thread.
completionHandler
A closure to be executed once the request has finished with a list of messages based on the above criteria.
Return Value
Void
-
Posts a message with optional file attachments to a space by spaceId.
The content of the message can be plain text, html, or markdown.
To notify specific person or everyone in a space, mentions should be used. Having
@johndoe
in the content of the message does not generate notification.Since
2.3.0Declaration
Parameters
toSpace
The identifier of the space where the message is to be posted.
mentions
Notify these mentions.
withFiles
Local files to be uploaded to the space.
parent
If not nil, the sent message will belong to the thread of the parent message.
queue
If not nil, the queue on which the completion handler is dispatched. Otherwise, the handler is dispatched on the application’s main thread.
completionHandler
A closure to be executed once the message is posted.
Return Value
Void
-
Posts a message with optional file attachments to a user by id.
The content of the message can be plain text, html, or markdown.
Since
2.3.0Declaration
Parameters
toPerson
The identifier of the person where the message is to be posted.
withFiles
Local files to be uploaded to the space.
parent
If not nil, the sent message will belong to the thread of the parent message.
queue
If not nil, the queue on which the completion handler is dispatched. Otherwise, the handler is dispatched on the application’s main thread.
completionHandler
A closure to be executed once the message is posted.
Return Value
Void
-
Posts a message with optional file attachments to a user by email address.
The content of the message can be plain text, html, or markdown.
Since
2.3.0Declaration
Parameters
toPersonEmail
The email address of the user to whom the message is to be posted.
withFiles
Local files to be uploaded to the space.
parent
If not nil, the sent message will belong to the thread of the parent message.
queue
If not nil, the queue on which the completion handler is dispatched. Otherwise, the handler is dispatched on the application’s main thread.
completionHandler
A closure to be executed once the message is posted.
Return Value
Void
-
Edit a message.
Note
If a message has attachments, Only be able to edit the text and not the attachment.Since
2.8.0Declaration
Parameters
text
The message text is used to replace old one.
parent
The message you are editing.
mentions
Notify these mentions.
queue
If not nil, the queue on which the completion handler is dispatched. Otherwise, the handler is dispatched on the application’s main thread.
completionHandler
A closure to be executed once the message is edited, will callback an edited message object.
Return Value
Void
-
Mark all messages in the space read.
Since
2.3.0Declaration
Swift
public func markAsRead(spaceId: String, messageId: String, queue: DispatchQueue? = nil, completionHandler: @escaping (Result<Void>) -> Void)
Parameters
spaceId
The identifier of the space where the message is.
messageId
The identifier of the message which user read.
queue
If not nil, the queue on which the completion handler is dispatched. Otherwise, the handler is dispatched on the application’s main thread.
completionHandler
A closure to be executed once the request has finished.
Return Value
Void
-
Mark all messages in the space read.
Since
2.3.0Declaration
Swift
public func markAsRead(spaceId: String, queue: DispatchQueue? = nil, completionHandler: @escaping (Result<Void>) -> Void)
Parameters
spaceId
The identifier of the space where the message is.
queue
If not nil, the queue on which the completion handler is dispatched. Otherwise, the handler is dispatched on the application’s main thread.
completionHandler
A closure to be executed once the request has finished.
Return Value
Void
-
Retrieves the details of a message by id.
Note that the file attachment of the message are not downloaded. Use the
downloadFile(...)
ordownloadThumbnail(...)
to download the actual content or the thumbnail of the attachment.Since
1.2.0Declaration
Parameters
messageId
The identifier of the message.
queue
If not nil, the queue on which the completion handler is dispatched. Otherwise, the handler is dispatched on the application’s main thread.
completionHandler
A closure to be executed once the message is retrieved.
Return Value
Void
-
Deletes a message by id.
Since
1.2.0Declaration
Swift
public func delete(messageId: String, queue: DispatchQueue? = nil, completionHandler: @escaping (Result<Void>) -> Void)
Parameters
messageId
The identifier of the message to be deleted.
queue
If not nil, the queue on which the completion handler is dispatched. Otherwise, the handler is dispatched on the application’s main thread.
completionHandler
A closure to be executed once the message is deleted.
Return Value
Void
-
Download a file attachment to the specified local directory.
Since
1.4.0Declaration
Swift
public func downloadFile(_ file: RemoteFile, to: URL? = nil, progressHandler: ((Double) -> Void)? = nil, completionHandler: @escaping (Result<URL?>) -> Void)
Parameters
file
The RemoteFile object need to be downloaded. Use
Message.remoteFiles
to get the references.to
The local file directory for saving downloaded file attachment.
progressHandler
The download progress indicator.
completionHandler
A closure to be executed once the download is completed. The URL contains the path to the downloaded file.
Return Value
Void
-
Download the thumbnail for a file attachment to the specified local directory. Note Cisco Webex doesn’t generate thumbnail for all files.
Since
1.4.0Declaration
Swift
public func downloadThumbnail(for file: RemoteFile, to: URL? = nil, completionHandler: @escaping (Result<URL?>) -> Void)
Parameters
for
The RemoteFile object whose thumbnail needs to be downloaded.
to
The local file directory for saving downloaded thumbnail.
completionHandler
A closure to be executed once the download is completed. The URL contains the path to the downloaded thumbnail.
Return Value
Void