send method

Future<void> send(
  1. String text
)

Sends text; shows the pre-chat form first when the team is away and the site wants an email.

Implementation

Future<void> send(String text) async {
  final content = text.trim();
  if (content.isEmpty) return;
  final cfg = _state.config;
  if (!_state.online &&
      cfg != null &&
      cfg.offlineCapture != OfflineCapture.off &&
      (_state.visitorEmail == null || _state.visitorEmail!.isEmpty) &&
      !_state.skippedEmail) {
    _emit(_state.copyWith(needsEmail: true, draft: content));
    return;
  }
  final p = PendingMessage(clientId: ids.clientId(), content: content, createdAt: clock.now());
  _emit(_state.copyWith(pending: [..._state.pending, p], clearDraft: true));
  _stopTyping();
  await _sendPending(p);
}