sendMessage method

Future<VIMessageEvent> sendMessage({
  1. String? text,
  2. List<Map<String, Object>>? payload,
})

Send a message to the conversation.

Sending messages is available only for participants that have write permissions (VIConversationParticipant.canWrite is true).

Other parties of the conversation (online participants and logged in clients) can be informed about sending messages to the conversation via the VIMessenger.onSendMessage callback.

To be informed about sending messages while being offline, participants can subscribe to the VIMessengerNotification.onSendMessage messenger push notification.

Optional text - Message text, maximum 5000 characters

Optional payload - Message payload

Throws VIException, if operation failed, otherwise returns VIMessageEvent instance. For all possible errors see VIMessagingError

Implementation

Future<VIMessageEvent> sendMessage({
  String? text,
  List<Map<String, Object>>? payload,
}) async {
  try {
    Map<String, dynamic>? data = await _methodChannel.invokeMapMethod(
        'Messaging.sendMessage',
        {'conversation': uuid, 'text': text, 'payload': payload});
    if (data == null) {
      _VILog._e('VIConversation: sendMessage: data was null, skipping');
      throw VIException(
        VIMessagingError.ERROR_INTERNAL,
        'VIConversation:sendMessage: data was null',
      );
    }
    return VIMessageEvent._fromMap(data);
  } on PlatformException catch (e) {
    throw VIException(e.code, e.message);
  }
}