sendText method

Future<SentMessage?> sendText(
  1. String text
)

Sends a text message to the agent.

Returns the SentMessage if the message was sent by all senders, or null if a sender failed. When a sender fails, the session error is set to SessionErrorKind.sender.

Implementation

Future<SentMessage?> sendText(String text) async {
  final message = SentMessage(
    id: _uuid.v4(),
    timestamp: DateTime.timestamp(),
    content: SentUserInput(text),
  );

  try {
    for (final sender in _senders) {
      await sender.send(message);
    }
    return message;
  } catch (error, stackTrace) {
    logger.warning('Session.sendText() failed: $error', error, stackTrace);
    _setError(SessionError.sender(error));
    return null;
  }
}