sendInteractiveMessage static method
Future<InteractiveMessage?>
sendInteractiveMessage(
- InteractiveMessage message, {
- MessageSentListener? listener,
- dynamic onSuccess(
- InteractiveMessage message
- dynamic onError(
- CometChatException excep
Marks a message as unread.
send Interactive messages which has to change its state according to some interactions.
Migration Note: Migrated from platform channels to native Dart implementation. Behavior and signature remain identical for backward compatibility.
Android Reference: MessagesRequest.sendInteractiveMessage(InteractiveMessage message)
The method could throw PlatformException with error codes specifying the cause
Offline (opt-in, additive): pass listener for the three-phase send.
A listener-less send never enters the outbox — see _offlineAdoptingSend.
Implementation
static Future<InteractiveMessage?> sendInteractiveMessage(
InteractiveMessage message, {
MessageSentListener? listener,
Function(InteractiveMessage message)? onSuccess,
Function(CometChatException excep)? onError,
}) async {
final offlineAcked = await _offlineAdoptingSend(message, listener);
if (offlineAcked != null) return offlineAcked as InteractiveMessage?;
try {
// Get SDK instance
final sdk = SdkRegistry.getInstance();
// Call native Dart message repository
final sentMessage = await sdk.messages.sendInteractiveMessage(message);
// A7: an own threaded send auto-subscribes the sender (BEH-FLAG-08).
// Queued, not awaited: the callback never waits on the cache.
unawaited(OfflineRuntime.instance.onOwnDirectSendSucceeded(sentMessage));
// Call success callback (listener wins — never both).
if (listener != null) {
listener.onMessageSent(sentMessage);
} else if (onSuccess != null) {
onSuccess(sentMessage);
}
return sentMessage;
} on SdkException catch (sdkEx) {
// Convert SdkException to CometChatException
final cometChatEx = CometChatException(
sdkEx.code,
sdkEx.details ?? sdkEx.message,
sdkEx.message,
);
if (listener != null) {
listener.onError(cometChatEx);
} else {
_errorCallbackHandler(cometChatEx, null, null, onError);
}
} catch (e) {
if (listener != null) {
listener.onError(
CometChatException('ERROR', e.toString(), e.toString()),
);
} else {
_errorCallbackHandler(null, null, e, onError);
}
}
return null;
}