createChannel method

Future<CreateChannelResponse> createChannel({
  1. required String appInstanceArn,
  2. required String name,
  3. String? clientRequestToken,
  4. String? metadata,
  5. ChannelMode? mode,
  6. ChannelPrivacy? privacy,
  7. List<Tag>? tags,
})

Creates a channel to which you can add users and send messages.

Restriction: You can't change a channel's privacy.

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

Parameter appInstanceArn : The ARN of the channel request.

Parameter name : The name of the channel.

Parameter clientRequestToken : The client token for the request. An Idempotency token.

Parameter metadata : The metadata of the creation request. Limited to 1KB and UTF-8.

Parameter mode : The channel mode: UNRESTRICTED or RESTRICTED. Administrators, moderators, and channel members can add themselves and other members to unrestricted channels. Only administrators and moderators can add members to restricted channels.

Parameter privacy : The channel's privacy level: PUBLIC or PRIVATE. Private channels aren't discoverable by users outside the channel. Public channels are discoverable by anyone in the app instance.

Implementation

Future<CreateChannelResponse> createChannel({
  required String appInstanceArn,
  required String name,
  String? clientRequestToken,
  String? metadata,
  ChannelMode? mode,
  ChannelPrivacy? privacy,
  List<Tag>? tags,
}) async {
  ArgumentError.checkNotNull(appInstanceArn, 'appInstanceArn');
  _s.validateStringLength(
    'appInstanceArn',
    appInstanceArn,
    5,
    1600,
    isRequired: true,
  );
  ArgumentError.checkNotNull(name, 'name');
  _s.validateStringLength(
    'name',
    name,
    1,
    256,
    isRequired: true,
  );
  _s.validateStringLength(
    'clientRequestToken',
    clientRequestToken,
    2,
    64,
  );
  _s.validateStringLength(
    'metadata',
    metadata,
    0,
    1024,
  );
  final $payload = <String, dynamic>{
    'AppInstanceArn': appInstanceArn,
    'Name': name,
    'ClientRequestToken': clientRequestToken ?? _s.generateIdempotencyToken(),
    if (metadata != null) 'Metadata': metadata,
    if (mode != null) 'Mode': mode.toValue(),
    if (privacy != null) 'Privacy': privacy.toValue(),
    if (tags != null) 'Tags': tags,
  };
  final response = await _protocol.send(
    payload: $payload,
    method: 'POST',
    requestUri: '/channels',
    exceptionFnMap: _exceptionFns,
  );
  return CreateChannelResponse.fromJson(response);
}