sendInteractiveMessage static method

Future<InteractiveMessage?> sendInteractiveMessage(
  1. InteractiveMessage message,
  2. {required dynamic onSuccess(
    1. InteractiveMessage message
    )?,
  3. required dynamic onError(
    1. CometChatException excep
    )?}
)

send Interactive messages which has to change its state according to some interactions.

The method could throw PlatformException with error codes specifying the cause

Implementation

static Future<InteractiveMessage?> sendInteractiveMessage(InteractiveMessage message, {
  required Function(InteractiveMessage message)? onSuccess, required Function(CometChatException excep)? onError}) async {
  try {
    final result = await channel.invokeMethod('sendInteractiveMessage', {
      'receiverId': message.receiverUid,
      'type': message.type,
      'receiverType': message.receiverType,
      'interactiveData': message.interactiveData,
      'interactionGoal': message.interactionGoal?.toMap(),
      'muid': message.muid,
      'parentMessageId': message.parentMessageId,
      'metadata' :  json.encode(message.metadata ?? {},),
      'tags': message.tags,
      'allowSenderInteraction': message.allowSenderInteraction,
    });
    final res = InteractiveMessage.fromMap(result);

    if(onSuccess != null) onSuccess(res);
    return res;
  } on PlatformException catch (platformException) {
    if(onError != null) onError(CometChatException(platformException.code, platformException.details, platformException.message));
  } catch (e) {
    debugPrint("Error: $e");
    if(onError != null) onError(CometChatException(ErrorCode.errorUnhandledException, e.toString() , e.toString()));
  }
  return null;
}