SendMessage.fromMap constructor

SendMessage.fromMap(
  1. Map<String, dynamic> map
)

Implementation

factory SendMessage.fromMap(Map<String, dynamic> map) {
  final messageType = map['type'] as String;
  switch (messageType) {
    case MessageType.TEXT:
    case MessageType.IMAGE:
    case MessageType.FILE:
    case MessageType.MEDIA_EMBED:
    case MessageType.GIF:
      return SendMessage(
        type: messageType,
        content: map['content'] as String,
      );
    case MessageType.META:
      return SendMessage(
        type: messageType,
        content: map['content'] as String,
        info: Info.fromJson(map['info']),
      );
    case MessageType.REACTION:
      return SendMessage(
        type: messageType,
        content: map['content'] as String,
        reference: map['reference'] as String?,
      );
    default:
      throw ArgumentError('Invalid message type: $messageType');
  }
}