Webex Messaging
Webex Messaging
Quickstart
This article provides examples of common methods used in the meetings flow for the iOS Messaging SDK. For detailed method parameters, refer to the SDK API Reference.
The Webex
instance is the primary entry point for the SDK, allowing access to all Webex SDK APIs.
anchorCreate a New Webex Space
anchorTo create a new Webex space:
webex.spaces.create("Hello World", null, CompletionHandler<Space?> { result ->
if (result.isSuccessful) {
val space = result.data
} else {
val error= result.error
}
})
anchorAdd a User to a Space
anchorTo add a user to a space:
webex.memberships.create(space.id, null, "person@example.com", true, CompletionHandler<Membership?> { result ->
if (result.isSuccessful) {
val space = result.data
} else {
val error= result.error
}
})
Post a Message in a Space
To post a message in the space:
webex.messages.postToSpace(space.id, Message.Text.plain("Hello"), null, null, CompletionHandler<Message> { result ->
if(result != null && result.isSuccessful){
val message = result.data
}
})
anchorPost a Message with an Attachment
anchorTo post a message to a space with an attachment:
// targetId is the spaceId or personId or email address
webex.messages.post(targetId, Message.draft(Message.Text.markdown("**Hello**", null, null)).addAttachments(localFile), CompletionHandler { result ->
if (result.isSuccessful) {
// message sent successfully
} else {
val error = result.error
// message sent failed
}
})
anchorPost a Message as a Reply to a Thread
anchorTo post a message as a reply to a thread:
webex.messages.post(targetId, Message.draft(Message.Text.markdown("**Hello**", null, null))
.addAttachments(localFile)
.setParent(parentMessage),
CompletionHandler { result ->
if (result.isSuccessful) {
// message sent successfully
} else {
val error = result.error
// message sent failed
}
})
anchorIntercept Messaging Events
anchorTo intercept messaging events:
webex.messages.setMessageObserver(object : MessageObserver {
override fun onEvent(event: MessageObserver.MessageEvent) {
when (event) {
is MessageObserver.MessageReceived -> {
val message = event.getMessage()
if (message?.getParentId() != null) {
// Threaded message
}
}
is MessageObserver.MessageDeleted -> {
// message deleted
}
is MessageObserver.MessageFileThumbnailsUpdated -> {
// thumbnails updated for files
}
is MessageObserver.MessageEdited -> {
// message edited successfully. event.getMessage() returns the edited message.
}
}
}
})
anchorManage the Background Connection
anchorTo maintain a websocket connection in the background (allowing background syncing of messages):
webex.phone.enableBackgroundConnection(enable: Boolean)
anchorEnable or Disable Console Logging
anchorTo enable/disable console login:
webex.enableConsoleLogger(enable: Boolean)
anchorCheck Feature Entitlements for a Logged-In User
anchorTo determine what entitlements a particular logged-in user has:
var capability = webex.people.getProductCapability()
var hasCalling = capability.isCallingSupported()
var hasMessaging = capability.isMessagingSupported()
var hasMeeting = capability.isMeetingSupported()