CreateBlogSupport
Log inSign up
Home
Webex Messaging
  • Overview
  • Guides
  • REST API Basics
  • API REFERENCE
  • All APIs
  • Changelog
  • SDK
  • AI Assistant for Developers
  • Widgets
  • Tutorials
  • Suite Sandbox
  • Beta Program
  • Webex Status API
  • XML API Deprecation

Webex Messaging

API Guide

This article provides detailed information on the messaging features and methods provided by the Webex iOS Messaging SDK.

The SDK lets you easily implement real-time messaging capabilities including posting new messages, and deleting, listing, and editing existing messages.

anchorBefore Continuing: Sync Webex Spaces

anchor

Before working with spaces or messages within them, ensure that all spaces are synced using the following method:

// Indicates if the latest conversations have been synced to the local data warehouse.
// Returns true if the sync is completed.
// Returns false if the sync is in progress.
webex.spaces.isSpacesSyncCompleted 
    
// The callback handler for sync status changes.
webex.spaces.onSyncingSpacesStatusChanged = { isSpacesSyncInProgress in
    // isSpacesSyncInProgress is true if a space sync is in progress.
    // isSpacesSyncInProgress is false if a space sync is complete.
 }

Messaging Flow Diagram

anchorPost a Text Message to a Person by ID

anchor

To post a text message to a particular participant using their personId:

webex.messages.post(personId: "{personId}", text: "text..."){ response in
     switch response.result {
         case .success(let message):
             // ...
             break
         case let .failure(let error):
             // ...
             break
     }
}
Post a Text Message to a Person by Email

To post a text message to a person using their email address:

guard let emailAddress = EmailAddress.fromString("{person email address}") else{ return }

webex.messages.post(personEmail: emailAddress, text: "text..."){ response in
     switch response.result {
         case .success(let message):
             // ...
             break
         case let .failure(let error):
             // ...
             break
     }
}
Post a Text Message to a Room

To post a text message to a room using its roomId:

webex.messages.post(roomId: "{roomId}", text: "text..."){ response in
     switch response.result {
         case .success(let message):
             // ...
             break
         case let .failure(let error):
             // ...
             break
     }
}
Post Single Mentions

To post a message that includes mention(s) of individual person(s):

//create person mention items with personId
let mentionItem1 = Mention.person("{personId1}")
let mentionItem2 = Mention.person("{personId2}")
let mentionArray = [mentionItem1, mentionItem2]

webex.messages.post(roomId: "{roomId}", text: "text...", mentions: mentionArray){ response in
     switch response.result {
         case .success(let message):
             // ...
             break
         case let .failure(let error):
             // ...
             break
     }
}
Post a Group Mention

To post a message that includes a group mention:

//create a group mention item.
let mentionItem = Mention.all
let mentionArray = [mentionItem]

webex.messages.post(roomId: "{roomId}", text: "text...", mentions: mentionArray){ response in
     switch response.result {
         case .success(let message):
             // ...
             break
         case let .failure(let error):
             // ...
             break
     }
}

anchorPost Local Files

anchor

To post a message with attached files using local paths:

let fileItem1 = LocalFile.init(path: "{local file path}")
let fileItem2 = LocalFile.init(path: "{local file path}", name: "{file name}", mime: "{file mime type}")
let fileArray = [fileItem1, fileItem2]

webex.messages.post(roomId: "{room id}", text: "{text...}", files: fileArray){ response in
    switch response.result {
        case .success(let message):
            // ...
            break
        case let .failure(let error):
            // ...
            break
    }
}
Post Files with Uploading Progress

To post a message with a file and monitor the uploading progress:

guard let fileItem  = LocalFile.init(path: "{local file path}", name: "{file name}", mime: "{file mime type}", 
    progressHandler: { (progress) in // progress as double }) else {return}

webex.messages.post(roomId: "{room id}", text: "{text...}", files: [fileItem]){ response in
    switch response.result {
        case .success(let message):
            // ...
            break
        case let .failure(let error):
            // ...
            break
    }
}
Post Files with a Thumbnail Preview

To post a message with a file that includes a thumbnail:

let fileThumb = LocalFile.Thumbnail.init(path: "{file path}", mime: "{mime type}", width: 320, height: 400)
guard let fileItem  = LocalFile.init(path: "{local file path}", name: "{file name}", mime: "{file mime type}", 
    thumbnail: fileThumb, progressHandler: { (progress) in // progress as double }) else {return}

webex.messages.post(roomId: "{room id}", text: "{text...}", files: [fileItem]){ response in
    switch response.result {
        case .success(let message):
            // ...
            break
        case let .failure(let err):
            // ...
            break
    }
}

anchorDelete a Message

anchor

To delete a message using its messageId:

webex.messages.delete(messageId: "{message id}", completionHandler: { (response) in
    switch response.result{
        case .success(_):
            // delete operation successful.
            break
        case .failure(let err):
            // delete operation failed
            break
        }
})

anchorList Messages Before a Specific Date

anchor

To list messages before a particular date point within a room, with max specifying the maximum number of messages to return:

let before = Before.date("{one date point}")

webex.messages.list(roomId: "{room id}", before: before, max: 50) { response in
    switch response.result {
    case .success(let messages):
        // ...
        break
    case .failure(let err):
        // ...
        break
    }
}

anchorList Messages Before a Specific Message

anchor

To list messages before a particular message within a room:

let beforeMessage = Before.message("{message id}")

webex.messages.list(roomId: "{room id}", before: beforeMessage, max: 50) { response in
    switch response.result {
    case .success(let messages):
       // ...
       break
    case .failure(let err):
        // ...
        break
     }
}

anchorList Messages That Mentioned Your ID

anchor

To list messages in which your ID is mentioned within a group room:

let mentioned = Mention.person("me")
webex.messages.list(roomId: "{room id}", max: 50, mentionedPeople: mentioned) { response in
    switch response.result {
    case .success(let messages):
        // ...
        break
    case .failure(let err):
        // ...
        break
    }
}

anchorMessage Reception Events

anchor

To handle message reception events:

webex.messages.onEvent = { messageEvent in
    switch messageEvent{
    case .messageReceived(let message):
        // received message...
        break
    case .messageDeleted(let messageId):
        // deleted messageId...
        break
    }
}

anchorDownload Simple Files

anchor

When a message with files is received, this code will download each file to default location:

webex.messages.onEvent = { messageEvent in
    switch messageEvent{
    case .messageReceived(let message):
        if let files = message.files {
            for file in files {
                webex.messages.downloadFile(file) { result in
                    if let localUrl = result.data{
                        // file downloaded successfully in localUrl ...
                    }
                }
            }
        }
        break
    case .messageDeleted(let messageId):
        // ...
        break
    }
}

anchorDownload Files to a Particular Destination

anchor

This code snippet is similar to the previous one, but it specifies a destination directory where the files should be downloaded:

webex.messages.onEvent = { messageEvent in
    switch messageEvent{
    case .messageReceived(let message):
        let destination = URL.init(string: "{destination directory}")
        if let files = message.files {
            for file in files {
               webex.messages.downloadFile(file, to: destination) { result in
                    if let localUrl = result.data{
                       // file downloaded successfully in localUrl ...
                    }
               }
            }
        }
        break
    case .messageDeleted(let messageId):
        // ...
        break
    }
}

anchorDownload Files with a Progress Handler

anchor

In addition to downloading the files, this snippet provides a progress handler that reports the progress of the file download:

webex.messages.onEvent = { messageEvent in
    switch messageEvent{
    case .messageReceived(let message):
        if let files = message.files {
            for file in files {
               webex.messages.downloadFile(file, progressHandler: { progress in
                      // progress in double
               }) { result in
                    if let localUrl = result.data{
                      // file downloaded successfully in localUrl ...
                  }
               } 
            }
        }
        break
    case .messageDeleted(let messageId):
        // ...
        break
    }
}

anchorDownload Thumbnails

anchor

To download the thumbnails of the files included in a message:

webex.messages.onEvent = { messageEvent in
    switch messageEvent{
    case .messageReceived(let message):
        if let files = message.files {
            for file in files {
                webex.messages.downloadThumbnail(for: file) { result in
                    if let localUrl = result.data{
                        // file downloaded successfully in localUrl ...
                    }
                }
            }
        }
        break
    case .messageDeleted(let messageId):
        // ...
        break
    }
}

anchorDownload Thumbnails to a Particular Destination

anchor

Similar to downloading files, this snippet specifies a destination for the downloaded thumbnails:

webex.messages.onEvent = { messageEvent in
    switch messageEvent{
    case .messageReceived(let message):
        let destination = URL.init(string: "{destination directory}")
        if let files = message.files {
            for file in files {
               webex.messages.downloadThumbnail(for: file, to: destination) { result in
                    if let localUrl = result.data{
                       // file downloaded successfully in localUrl ...
                    }
               }
            }
        }
        break
    case .messageDeleted(let messageId):
        // ...
        break
    }
}

anchorDownload Thumbnails with a Progress Handler

anchor

To download thumbnails with a progress handler to monitor the download progress:

webex.messages.onEvent = { messageEvent in
    switch messageEvent{
    case .messageReceived(let message):
        if let files = message.files {
            for file in files {
               webex.messages.downloadThumbnail(for: file, progressHandler: { progress in
                      // progress in double
               }) { result in
                    if let localUrl = result.data{
                      // file downloaded successfully in localUrl ...
                  }
               } 
            }
        }
        break
    case .messageDeleted(let messageId):
        // ...
        break
    }
}
In This Article
  • Before Continuing: Sync Webex Spaces
  • Post a Text Message to a Person by ID
  • Post Local Files
  • Delete a Message
  • List Messages Before a Specific Date
  • List Messages Before a Specific Message
  • List Messages That Mentioned Your ID
  • Message Reception Events
  • Download Simple Files
  • Download Files to a Particular Destination
  • Download Files with a Progress Handler
  • Download Thumbnails
  • Download Thumbnails to a Particular Destination
  • Download Thumbnails with a Progress Handler

Connect

Support

Developer Community

Developer Events

Contact Sales

Handy Links

Webex Ambassadors

Webex App Hub

Resources

Open Source Bot Starter Kits

Download Webex

DevNet Learning Labs

Terms of Service

Privacy Policy

Cookie Policy

Trademarks

© 2025 Cisco and/or its affiliates. All rights reserved.