fromJson method

Creates ID from the passed JSON

Implementation

@override
InputMessageContent fromJson(Map<String, Object?> json) {
  final isText = json['message_text'] != null;
  final isLocation = json['latitude'] != null && json['title'] == null;
  final isVenue = json['latitude'] != null && json['title'] != null;
  final isContact = json['phone_number'] != null;
  final isInVoice =
      json['currency'] != null && json['provider_token'] != null;

  if (isText) {
    return InputTextMessageContent.fromJson(json);
  } else if (isLocation) {
    return InputLocationMessageContent.fromJson(json);
  } else if (isVenue) {
    return InputVenueMessageContent.fromJson(json);
  } else if (isContact) {
    return InputContactMessageContent.fromJson(json);
  } else if (isInVoice) {
    return InputInvoiceMessageContent.fromJson(json);
  } else {
    throw TeleverseException(
      'Unknown InputMessageContent type',
      description:
          'The given JSON object does not match any InputMessageContent type.',
      type: TeleverseExceptionType.invalidParameter,
    );
  }
}