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.0

    Declaration

    Swift

    public var onEvent: ((MessageEvent) -> Void)?
  • The callback handler for incoming message events.

    Since

    2.3.0

    Declaration

    Swift

    public var onEventWithPayload: ((MessageEvent, WebexEventPayload) -> Void)?
  • Lists all messages in a space by space Id. The list sorts the messages in descending order by creation date.

    Note that the file attachment of the message are not downloaded. Use the downloadFile(...) or downloadThumbnail(...) to download the actual content or the thumbnail of the attachment.

    Since

    1.4.0

    Declaration

    Swift

    public func list(spaceId: String,
                     before: Before? = nil,
                     max: Int = 50,
                     mentionedPeople: Mention? = nil,
                     queue: DispatchQueue? = nil,
                     completionHandler: @escaping (ServiceResponse<[Message]>) -> Void)

    Parameters

    spaceId

    The identifier of the space.

    before

    If not nil, only list messages sent before this condition.

    max

    Limit the maximum number of messages in the response, default is 50.

    mentionedPeople

    List messages where a person (using Mention.person) or all (using Mention.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 user by email address.

    The content of the message can be plain text, html, or markdown.

    Since

    2.3.0

    Declaration

    Swift

    public func post(_ text: Message.Text? = nil,
                     toPersonEmail: EmailAddress,
                     withFiles: [LocalFile]? = nil,
                     parent: Message? = nil,
                     queue: DispatchQueue? = nil,
                     completionHandler: @escaping (ServiceResponse<Message>) -> Void)

    Parameters

    toPersonEmail

    The email address of the user to whom the message is to be posted.

    withFiles

    Local files to be uploaded with the message.

    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.0

    Declaration

    Swift

    public func post(_ text: Message.Text? = nil,
                     toPerson: String,
                     withFiles: [LocalFile]? = nil,
                     parent: Message? = nil,
                     queue: DispatchQueue? = nil,
                     completionHandler: @escaping (ServiceResponse<Message>) -> Void)

    Parameters

    toPerson

    The id of the user to whom the message is to be posted.

    withFiles

    Local files to be attached to the message.

    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 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.0

    Declaration

    Swift

    public func post(_ text: Message.Text? = nil,
                     toSpace: String,
                     mentions: [Mention]? = nil,
                     withFiles: [LocalFile]? = nil,
                     parent: Message? = nil,
                     queue: DispatchQueue? = nil,
                     completionHandler: @escaping (ServiceResponse<Message>) -> Void)

    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

  • Edit a message without attachment.

    Note

    Only be able to edit messages without attachments.

    Since

    2.8.0

    Declaration

    Swift

    public func edit(_ text: Message.Text,
                     parent: Message,
                     mentions: [Mention]? = nil,
                     queue: DispatchQueue? = nil,
                     completionHandler: @escaping (ServiceResponse<Message>) -> Void)

    Parameters

    text

    The message text is used to replace old one.

    parent

    The message you are editing.

    mentions

    new message Mention objects.

    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

  • Retrieves the details of a message by id.

    Note that the file attachment of the message are not downloaded. Use the downloadFile(...) or downloadThumbnail(...) to download the actual content or the thumbnail of the attachment.

    Since

    1.2.0

    Declaration

    Swift

    public func get(messageId: String, queue: DispatchQueue? = nil, completionHandler: @escaping (ServiceResponse<Message>) -> Void)

    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.0

    Declaration

    Swift

    public func delete(messageId: String, queue: DispatchQueue? = nil, completionHandler: @escaping (ServiceResponse<Any>) -> 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

  • Mark all messages in the space read.

    Since

    2.3.0

    Declaration

    Swift

    public func markAsRead(spaceId: String, messageId: String, queue: DispatchQueue? = nil, completionHandler: @escaping (ServiceResponse<Any>) -> 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.0

    Declaration

    Swift

    public func markAsRead(spaceId: String, queue: DispatchQueue? = nil, completionHandler: @escaping (ServiceResponse<Any>) -> 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

  • Download a file attachement to the specified local directory.

    Since

    1.4.0

    Declaration

    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 dwonloaded file attahement.

    progressHandler

    The download progress indicator.

    completionHandler

    A closure to be executed once the download is completed. The URL contains the path to the downloded 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.0

    Declaration

    Swift

    public func downloadThumbnail(for file: RemoteFile, to: URL? = nil, progressHandler: ((Double) -> Void)? = nil, completionHandler: @escaping (Result<URL>) -> Void)

    Parameters

    file

    The RemoteFile object whose thumbnail needs to be downloaded.

    to

    The local file directory for saving downloaded thumbnail.

    progressHandler

    The download progress indicator.

    completionHandler

    A closure to be executed once the download is completed. The URL contains the path to the downloded thumbnail.

    Return Value

    Void

Deprecated

  • 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

    1.4.0

    Declaration

    Swift

    @available(*, deprecated)
    public func post(personEmail: EmailAddress,
                     text: String? = nil,
                     files: [LocalFile]? = nil,
                     queue: DispatchQueue? = nil,
                     completionHandler: @escaping (ServiceResponse<Message>) -> Void)

    Parameters

    personEmail

    The email address of the user to whom the message is to be posted.

    content

    The content of message to be posted to the user. The content can be plain text, html, or markdown.

    files

    Local files to be uploaded with 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 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

    1.4.0

    Declaration

    Swift

    @available(*, deprecated)
    public func post(personId: String,
                     text: String? = nil,
                     files: [LocalFile]? = nil,
                     queue: DispatchQueue? = nil,
                     completionHandler: @escaping (ServiceResponse<Message>) -> Void)

    Parameters

    personId

    The id of the user to whom the message is to be posted.

    text

    The content message to be posted to the user. The content can be plain text, html, or markdown.

    files

    Local files to be attached to 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 posted.

    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

    1.4.0

    Declaration

    Swift

    @available(*, deprecated)
    public func post(spaceId: String,
                     text: String? = nil,
                     mentions: [Mention]? = nil,
                     files: [LocalFile]? = nil,
                     queue: DispatchQueue? = nil,
                     completionHandler: @escaping (ServiceResponse<Message>) -> Void)

    Parameters

    spaceId

    The identifier of the space where the message is to be posted.

    text

    The content message to be posted to the space. The content can be plain text, html, or markdown.

    mentions

    Notify these mentions.

    files

    Local files to be uploaded to the space.

    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