MiniProgramInteractionRequest constructor

MiniProgramInteractionRequest({
  1. required String requestId,
  2. required String sessionId,
  3. required int revision,
  4. required MiniProgramInteractionAction action,
  5. String? targetId,
  6. String? text,
})

Implementation

MiniProgramInteractionRequest({
  required String requestId,
  required String sessionId,
  required this.revision,
  required this.action,
  String? targetId,
  this.text,
}) : requestId = _identifier(requestId),
     sessionId = _identifier(sessionId),
     targetId = targetId == null ? null : _identifier(targetId) {
  if (revision < 1 || revision > 9007199254740991) {
    throw const FormatException('Invalid interaction revision.');
  }
  if (action == MiniProgramInteractionAction.back) {
    if (targetId != null) {
      throw const FormatException('Back does not accept a target.');
    }
  } else if (targetId == null) {
    throw const FormatException('An interaction target is required.');
  }
  if (action == MiniProgramInteractionAction.enterText) {
    if (text == null || text!.length > maxTextLength) {
      throw const FormatException('Invalid interaction text.');
    }
  } else if (text != null) {
    throw const FormatException('Only enterText accepts text.');
  }
}