Skip to main content

Send a message

Send messages to direct channels, group channels, and open channels.

Message content types

TypeClassBase classDescription
TextNCTextMessageNCMessageContentPlain text
Reference replyNCReferenceMessageNCMessageContentQuoted reply
ImageNCImageMessageNCMediaMessageContentImage (supports original)
GIFNCGIFMessageNCMediaMessageContentAnimated GIF
FileNCFileMessageNCMediaMessageContentFile attachment
VoiceNCVoiceMessageNCMediaMessageContentHD voice
Mention (@)N/AN/ANot a standalone type — see below
tip
  • Use sendMessage for regular messages and sendMediaMessage for media messages.
  • Rate limit: max 5 messages per second.

Send a regular message

Messages are sent through a channel instance. In Swift, create the channel, build SendMessageParams, and call sendMessage. The Objective-C equivalent is included below.

swift
import NexconnChatSDK

guard let channel = DirectChannel(channelId: "targetUserId") else {
return
}

let textContent = TextMessage(text: "Hello")
let params = SendMessageParams(content: textContent)

channel.sendMessage(
params: params,
attachedHandler: { message in
// Message persisted locally — update UI here
},
completionHandler: { message, error in
if let error {
print("Send failed: \(error.localizedDescription)")
} else {
print("Sent successfully: \(message?.messageId ?? "")")
}
}
)

NCSendMessageParams properties:

PropertyTypeDefaultDescription
contentNCMessageContent *Message content (required)
directedUserIdsNSArray<NSString *> *nilDirected recipient user IDs. nil or empty sends to all channel members.
disableUpdateLastMessageBOOLNOWhether to skip updating the channel's last message
needReceiptBOOLNOWhether a read receipt is required
disableNotificationBOOLNOWhether to disable remote push and local notifications
metadataNSDictionary<NSString *, NSString *> *nilMessage extension metadata
pushConfigNCPushConfig *nilPush notification configuration. nil uses the default strategy.

Send a media message

Use sendMediaMessage with NCSendMediaMessageParams for image, voice, video, file, and other media types.

swift
let imageContent = ImageMessage(imageURI: imageLocalPath)
let params = SendMediaMessageParams(content: imageContent)

channel.sendMediaMessage(
params: params,
attachedHandler: { message in
// Message persisted locally
},
progressHandler: { progress, message in
// Upload progress: 0-100
},
completionHandler: { message, error in
if let error {
print("Send failed: \(error.localizedDescription)")
} else {
print("Sent successfully: \(message?.messageId ?? "")")
}
},
cancelHandler: { message in
// Upload cancelled
}
)

Send a targeted message

Send a message visible only to specific users in a channel. Set directedUserIds in NCSendMessageParams:

swift
let params = SendMessageParams(content: textContent)
params.directedUserIds = ["userId1", "userId2"]

Send a mention (@) message

Set the mentionedInfo property on the message content:

swift
let textContent = TextMessage(text: "@user1 check this")
let mentionedInfo = MentionedInfo(
type: .users,
userIdList: ["userId1"],
mentionedContent: nil
)
textContent.mentionedInfo = mentionedInfo

To mention all members:

swift
let mentionedInfo = MentionedInfo(
type: .all,
userIdList: nil,
mentionedContent: nil
)

Configure push notification attributes

Set pushConfig in NCSendMessageParams to customize push behavior:

swift
let pushConfig = PushConfig()
pushConfig.pushTitle = "Custom Title"
pushConfig.pushContent = "Custom Content"
pushConfig.iOSConfig = IOSPushConfig()
pushConfig.iOSConfig?.threadId = "groupId"

let params = SendMessageParams(content: textContent)
params.pushConfig = pushConfig

NCPushConfig properties:

PropertyTypeDescription
disablePushTitleBOOLWhether to hide the push notification title. Default: NO.
pushTitleNSString *Push notification title. nil uses the default.
pushContentNSString *Push notification content. nil uses the default.
pushDataNSString *Extra data attached to the push notification.
forceShowDetailContentBOOLWhether to force showing notification detail content. Default: NO.
templateIdNSString *Push template ID for localized push content.
iOSConfigNCIOSPushConfig *iOS-specific push configuration.
androidConfigNCAndroidPushConfig *Android-specific push configuration.

Send a transient message

Transient messages are not stored and are not counted toward unread totals. Ideal for typing indicators. Use a message content class with NCMessagePersistentStatus set to not persist, then send via sendMessage:

swift
// Transient message content (for example, TypingStatusMessage or a custom non-persisted type)
let params = SendMessageParams(content: typingContent)
channel.sendMessage(params: params, attachedHandler: nil, completionHandler: nil)