sendMessage method

  1. @override
Future<SendResult> sendMessage(
  1. String text, {
  2. Map<String, dynamic>? metadata,
})
override

Sends a text text. Runs the beforeSend interceptor if set, then pushes the payload over the transport. Returns a SendResult reflecting the outcome.

Implementation

@override
Future<SendResult> sendMessage(
  String text, {
  Map<String, dynamic>? metadata,
}) async {
  final draft = MessageDraft(body: text, metadata: metadata ?? const {});
  recorded.sentMessages.add(draft);
  if (_scriptedSends.isEmpty) {
    return SendFailure(
      const ValidationError(
        'FakeChataptorClient: no scripted result — call '
        'inject.completeNextSend first',
        fieldErrors: {},
      ),
      draft,
    );
  }
  return _scriptedSends.removeAt(0);
}