MessageSingleResponse.fromJson constructor

MessageSingleResponse.fromJson(
  1. Map<String, dynamic> json
)

Implementation

factory MessageSingleResponse.fromJson(Map<String, dynamic> json) {
  var type = json["type"] as String;

  if (type == MessageType.text.name) {
    return MessageSingleResponse(
        createdAt: json["createdAt"] ?? 0,
        id: json["id"] ?? "",
        integrationId: json["integrationId"] ?? "",
        recipientId: json["recipientId"] ?? "",
        senderId: json["senderId"] ?? "",
        type: json["type"] ?? "",
        data: [MessageResponseData.text(json["data"])],
        sessionUuid: json["sessionUuid"] ?? "");
  } else if (type == MessageType.carousel.name) {
    var data = json["data"] as List;
    return MessageSingleResponse(
        createdAt: json["createdAt"] ?? 0,
        id: json["id"] ?? "",
        integrationId: json["integrationId"] ?? "",
        recipientId: json["recipientId"] ?? "",
        senderId: json["senderId"] ?? "",
        type: json["type"] ?? "",
        data: data.map((e) => MessageResponseData.carousel(e)).toList(),
        sessionUuid: json["sessionUuid"] ?? "");
  } else if (type == MessageType.button.name) {
    var data = json["data"] as Map<String, dynamic>;
    return MessageSingleResponse(
        createdAt: json["createdAt"] ?? 0,
        id: json["id"] ?? "",
        integrationId: json["integrationId"] ?? "",
        recipientId: json["recipientId"] ?? "",
        senderId: json["senderId"] ?? "",
        type: json["type"] ?? "",
        data: [MessageResponseData.buttons(data)],
        sessionUuid: json["sessionUuid"] ?? "");
  } else if (type == MessageType.media.name ||
      type == MessageType.image.name ||
      type == MessageType.video.name) {
    var data = json["data"] as Map<String, dynamic>;
    return MessageSingleResponse(
        createdAt: json["createdAt"] ?? 0,
        id: json["id"] ?? "",
        integrationId: json["integrationId"] ?? "",
        recipientId: json["recipientId"] ?? "",
        senderId: json["senderId"] ?? "",
        type: json["type"] ?? "",
        data: [MessageResponseData.image(data)],
        sessionUuid: json["sessionUuid"] ?? "");
  } else if (type == MessageType.location.name) {
    var data = json["data"] as Map<String, dynamic>;
    return MessageSingleResponse(
        createdAt: json["createdAt"] ?? 0,
        id: json["id"] ?? "",
        integrationId: json["integrationId"] ?? "",
        recipientId: json["recipientId"] ?? "",
        senderId: json["senderId"] ?? "",
        type: json["type"] ?? "",
        data: [MessageResponseData.location(data)],
        sessionUuid: json["sessionUuid"] ?? "");
  } else {
    var data = json["data"] as Map<String, dynamic>;
    return MessageSingleResponse(
        createdAt: json["createdAt"] ?? 0,
        id: json["id"] ?? "",
        integrationId: json["integrationId"] ?? "",
        recipientId: json["recipientId"] ?? "",
        senderId: json["senderId"] ?? "",
        type: json["type"] ?? "",
        data: [MessageResponseData.file(data)],
        sessionUuid: json["sessionUuid"] ?? "");
  }
}