sendMessage method

Future<Map> sendMessage(
  1. dynamic message,
  2. String toConversationID,
  3. dynamic conversationType,
  4. dynamic config,
  5. int? messageAttachedCallbackID,
  6. int messageID,
)

Implementation

Future<Map<dynamic, dynamic>> sendMessage(
    dynamic message,
    String toConversationID,
    dynamic conversationType,
    dynamic config,
    int? messageAttachedCallbackID,
    int messageID) async {
  final _message = mapToJSObj(message);
  final _config = mapToJSObj(config);

  Map notification = {
    'onMessageAttached': allowInterop((message) {
      ZIMMessageAttachedCallback? callback = ZIMCommonData
          .zimMessageAttachedCallbackMap[messageAttachedCallbackID];

      if (callback != null) {
        ZIMMessage zimMessage = getZIMMessage(message);

        callback(zimMessage);
      }
    })
  };

  final result = await promiseToFuture(ZIM.getInstance()!.sendMessage(
          _message,
          toConversationID,
          conversationType,
          _config,
          mapToJSObj(notification)))
      .catchError((e) {
    throw PlatformException(code: e.code.toString(), message: e.message);
  });

  Map resultMap = jsObjectToMap(result);

  return resultMap;
}