sendMessage method

Future<SendMessageResponse> sendMessage({
  1. required String connectionToken,
  2. required String content,
  3. required String contentType,
  4. String? clientToken,
})

Sends a message. Note that ConnectionToken is used for invoking this API instead of ParticipantToken.

May throw AccessDeniedException. May throw InternalServerException. May throw ThrottlingException. May throw ValidationException.

Parameter connectionToken : The authentication token associated with the connection.

Parameter content : The content of the message.

Parameter contentType : The type of the content. Supported types are text/plain.

Parameter clientToken : A unique, case-sensitive identifier that you provide to ensure the idempotency of the request.

Implementation

Future<SendMessageResponse> sendMessage({
  required String connectionToken,
  required String content,
  required String contentType,
  String? clientToken,
}) async {
  ArgumentError.checkNotNull(connectionToken, 'connectionToken');
  _s.validateStringLength(
    'connectionToken',
    connectionToken,
    1,
    1000,
    isRequired: true,
  );
  ArgumentError.checkNotNull(content, 'content');
  _s.validateStringLength(
    'content',
    content,
    1,
    1024,
    isRequired: true,
  );
  ArgumentError.checkNotNull(contentType, 'contentType');
  _s.validateStringLength(
    'contentType',
    contentType,
    1,
    100,
    isRequired: true,
  );
  _s.validateStringLength(
    'clientToken',
    clientToken,
    0,
    500,
  );
  final headers = <String, String>{
    'X-Amz-Bearer': connectionToken.toString(),
  };
  final $payload = <String, dynamic>{
    'Content': content,
    'ContentType': contentType,
    'ClientToken': clientToken ?? _s.generateIdempotencyToken(),
  };
  final response = await _protocol.send(
    payload: $payload,
    method: 'POST',
    requestUri: '/participant/message',
    headers: headers,
    exceptionFnMap: _exceptionFns,
  );
  return SendMessageResponse.fromJson(response);
}