createParticipantConnection method

Future<CreateParticipantConnectionResponse> createParticipantConnection({
  1. required String participantToken,
  2. required List<ConnectionType> type,
})

Creates the participant's connection. Note that ParticipantToken is used for invoking this API instead of ConnectionToken.

The participant token is valid for the lifetime of the participant – until they are part of a contact.

The response URL for WEBSOCKET Type has a connect expiry timeout of 100s. Clients must manually connect to the returned websocket URL and subscribe to the desired topic.

For chat, you need to publish the following on the established websocket connection:

{"topic":"aws/subscribe","content":{"topics":"aws/chat"}}

Upon websocket URL expiry, as specified in the response ConnectionExpiry parameter, clients need to call this API again to obtain a new websocket URL and perform the same steps as before.

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

Parameter participantToken : This is a header parameter.

The Participant Token as obtained from StartChatContact API response.

Parameter type : Type of connection information required.

Implementation

Future<CreateParticipantConnectionResponse> createParticipantConnection({
  required String participantToken,
  required List<ConnectionType> type,
}) async {
  ArgumentError.checkNotNull(participantToken, 'participantToken');
  _s.validateStringLength(
    'participantToken',
    participantToken,
    1,
    1000,
    isRequired: true,
  );
  ArgumentError.checkNotNull(type, 'type');
  final headers = <String, String>{
    'X-Amz-Bearer': participantToken.toString(),
  };
  final $payload = <String, dynamic>{
    'Type': type.map((e) => e.toValue()).toList(),
  };
  final response = await _protocol.send(
    payload: $payload,
    method: 'POST',
    requestUri: '/participant/connection',
    headers: headers,
    exceptionFnMap: _exceptionFns,
  );
  return CreateParticipantConnectionResponse.fromJson(response);
}