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
spaceIdThe identifier of the space. (Derived parameter: Use
SpaceClient.list(...)to get the list of spaces. Then useSpace.idto retrieve the spaceId)maxLimit the maximum number of messages in the response, default is 50.
beforeIf not nil, only list messages sent before this condition.
mentionedPeopleList messages where a person (using
Mention.person) or all (usingMention.all) is mentioned.queueIf not nil, the queue on which the completion handler is dispatched. Otherwise, the handler is dispatched on the application’s main thread.
completionHandlerA 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
@johndoein the content of the message does not generate notification.Since
2.3.0Declaration
Parameters
toSpaceThe identifier of the space where the message is to be posted. (Derived parameter: Use
SpaceClient.list(...)to get the list of spaces. Then useSpace.idto retrieve the spaceId)mentionsNotify these mentions.
withFilesLocal files to be uploaded to the space.
parentIf not nil, the sent message will belong to the thread of the parent message.
queueIf not nil, the queue on which the completion handler is dispatched. Otherwise, the handler is dispatched on the application’s main thread.
completionHandlerA 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
toPersonThe identifier of the person where the message is to be posted. (Derived parameter: Use
MembershipClient.list(...)to get the list of members. Then useMembership.personIdto get the personId of the member)withFilesLocal files to be uploaded to the space.
parentIf not nil, the sent message will belong to the thread of the parent message.
queueIf not nil, the queue on which the completion handler is dispatched. Otherwise, the handler is dispatched on the application’s main thread.
completionHandlerA 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
toPersonEmailThe email address of the user to whom the message is to be posted. (Derived parameter: Use
MembershipClient.list(...)to get the list of members. Then useMembership.personEmailto get the email address of the member)withFilesLocal files to be uploaded to the space.
parentIf not nil, the sent message will belong to the thread of the parent message.
queueIf not nil, the queue on which the completion handler is dispatched. Otherwise, the handler is dispatched on the application’s main thread.
completionHandlerA 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
textThe message text is used to replace old one.
parentThe message you are editing.
mentionsNotify these mentions.
queueIf not nil, the queue on which the completion handler is dispatched. Otherwise, the handler is dispatched on the application’s main thread.
completionHandlerA 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
spaceIdThe identifier of the space where the message is. (Derived parameter: Use
SpaceClient.list(...)to get the list of spaces. Then useSpace.idto retrieve the spaceId)messageIdThe identifier of the message which user read. (Derived parameter: Use
MessageClient.list(...)to get a list of messages. Then useMessage.idto retrieve the messageId)queueIf not nil, the queue on which the completion handler is dispatched. Otherwise, the handler is dispatched on the application’s main thread.
completionHandlerA 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
spaceIdThe identifier of the space where the message is. (Derived parameter: Use
SpaceClient.list(...)to get the list of spaces. Then useSpace.idto retrieve the spaceId)queueIf not nil, the queue on which the completion handler is dispatched. Otherwise, the handler is dispatched on the application’s main thread.
completionHandlerA 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
messageIdThe identifier of the message. (Derived parameter: Use
MessageClient.list(...)to get a list of messages. Then useMessage.idto retrieve the messageId)queueIf not nil, the queue on which the completion handler is dispatched. Otherwise, the handler is dispatched on the application’s main thread.
completionHandlerA 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
messageIdThe identifier of the message to be deleted. (Derived parameter: Use
MessageClient.list(...)to get a list of messages. Then useMessage.idto retrieve the messageId)queueIf not nil, the queue on which the completion handler is dispatched. Otherwise, the handler is dispatched on the application’s main thread.
completionHandlerA 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
fileThe RemoteFile object need to be downloaded. Use
Message.remoteFilesto get the references.toThe local file directory for saving downloaded file attachment.
progressHandlerThe download progress indicator.
completionHandlerA 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
forThe RemoteFile object whose thumbnail needs to be downloaded.
toThe local file directory for saving downloaded thumbnail.
completionHandlerA closure to be executed once the download is completed. The URL contains the path to the downloaded thumbnail.
Return Value
Void
View on GitHub