sendEvent method

Future<SendEventResponse> sendEvent({
  1. required String connectionToken,
  2. required String contentType,
  3. String? clientToken,
  4. String? content,
})
Sends an event. Message receipts are not supported when there are more than two active participants in the chat. Using the SendEvent API for message receipts when a supervisor is barged-in will result in a conflict exception.

For security recommendations, see Connect Customer Chat security best practices. The Amazon Connect Participant Service APIs do not use Signature Version 4 authentication.

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

Parameter connectionToken : The authentication token associated with the participant's connection.

Parameter contentType : The content type of the request. Supported types are:

  • application/vnd.amazonaws.connect.event.typing
  • application/vnd.amazonaws.connect.event.connection.acknowledged (is no longer maintained since December 31, 2024)
  • application/vnd.amazonaws.connect.event.message.delivered
  • application/vnd.amazonaws.connect.event.message.read

Parameter clientToken : A unique, case-sensitive identifier that you provide to ensure the idempotency of the request. If not provided, the Amazon Web Services SDK populates this field. For more information about idempotency, see Making retries safe with idempotent APIs.

Parameter content : The content of the event to be sent (for example, message text). For content related to message receipts, this is supported in the form of a JSON string.

Sample Content: "{"messageId":"11111111-aaaa-bbbb-cccc-EXAMPLE01234"}"

Implementation

Future<SendEventResponse> sendEvent({
  required String connectionToken,
  required String contentType,
  String? clientToken,
  String? content,
}) async {
  final headers = <String, String>{
    'X-Amz-Bearer': connectionToken.toString(),
  };
  final $payload = <String, dynamic>{
    'ContentType': contentType,
    'ClientToken': clientToken ?? _s.generateIdempotencyToken(),
    if (content != null) 'Content': content,
  };
  final response = await _protocol.send(
    payload: $payload,
    method: 'POST',
    requestUri: '/participant/event',
    headers: headers,
    exceptionFnMap: _exceptionFns,
  );
  return SendEventResponse.fromJson(response);
}