sendChannelMessage method

Future<SendChannelMessageResponse> sendChannelMessage({
  1. required String channelArn,
  2. required String content,
  3. required ChannelMessagePersistenceType persistence,
  4. required ChannelMessageType type,
  5. String? clientRequestToken,
  6. String? metadata,
})

Sends a message to a particular channel that the member is a part of.

May throw BadRequestException. May throw ConflictException. May throw ForbiddenException. May throw UnauthorizedClientException. May throw ThrottledClientException. May throw ServiceUnavailableException. May throw ServiceFailureException.

Parameter channelArn : The ARN of the channel.

Parameter content : The content of the message.

Parameter persistence : Boolean that controls whether the message is persisted on the back end. Required.

Parameter type : The type of message, STANDARD or CONTROL.

Parameter clientRequestToken : The Idempotency token for each client request.

Parameter metadata : The optional metadata for each message.

Implementation

Future<SendChannelMessageResponse> sendChannelMessage({
  required String channelArn,
  required String content,
  required ChannelMessagePersistenceType persistence,
  required ChannelMessageType type,
  String? clientRequestToken,
  String? metadata,
}) async {
  ArgumentError.checkNotNull(channelArn, 'channelArn');
  _s.validateStringLength(
    'channelArn',
    channelArn,
    5,
    1600,
    isRequired: true,
  );
  ArgumentError.checkNotNull(content, 'content');
  _s.validateStringLength(
    'content',
    content,
    1,
    4096,
    isRequired: true,
  );
  ArgumentError.checkNotNull(persistence, 'persistence');
  ArgumentError.checkNotNull(type, 'type');
  _s.validateStringLength(
    'clientRequestToken',
    clientRequestToken,
    2,
    64,
  );
  _s.validateStringLength(
    'metadata',
    metadata,
    0,
    1024,
  );
  final $payload = <String, dynamic>{
    'Content': content,
    'Persistence': persistence.toValue(),
    'Type': type.toValue(),
    'ClientRequestToken': clientRequestToken ?? _s.generateIdempotencyToken(),
    if (metadata != null) 'Metadata': metadata,
  };
  final response = await _protocol.send(
    payload: $payload,
    method: 'POST',
    requestUri: '/channels/${Uri.encodeComponent(channelArn)}/messages',
    exceptionFnMap: _exceptionFns,
  );
  return SendChannelMessageResponse.fromJson(response);
}