createChannelMembership method

Future<CreateChannelMembershipResponse> createChannelMembership({
  1. required String channelArn,
  2. required String chimeBearer,
  3. required String memberArn,
  4. required ChannelMembershipType type,
  5. String? subChannelId,
})

Adds a member to a channel. The InvitedBy field in ChannelMembership is derived from the request header. A channel member can:

  • List messages
  • Send messages
  • Receive messages
  • Edit their own messages
  • Leave the channel
Privacy settings impact this action as follows:
  • Public Channels: You do not need to be a member to list messages, but you must be a member to send messages.
  • Private Channels: You must be a member to list or send messages.

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

Parameter channelArn : The ARN of the channel to which you're adding users.

Parameter chimeBearer : The ARN of the AppInstanceUser or AppInstanceBot that makes the API call.

Parameter memberArn : The AppInstanceUserArn of the member you want to add to the channel.

Parameter type : The membership type of a user, DEFAULT or HIDDEN. Default members are always returned as part of ListChannelMemberships. Hidden members are only returned if the type filter in ListChannelMemberships equals HIDDEN. Otherwise hidden members are not returned. This is only supported by moderators.

Parameter subChannelId : The ID of the SubChannel in the request.

Implementation

Future<CreateChannelMembershipResponse> createChannelMembership({
  required String channelArn,
  required String chimeBearer,
  required String memberArn,
  required ChannelMembershipType type,
  String? subChannelId,
}) async {
  final headers = <String, String>{
    'x-amz-chime-bearer': chimeBearer.toString(),
  };
  final $payload = <String, dynamic>{
    'MemberArn': memberArn,
    'Type': type.value,
    if (subChannelId != null) 'SubChannelId': subChannelId,
  };
  final response = await _protocol.send(
    payload: $payload,
    method: 'POST',
    requestUri: '/channels/${Uri.encodeComponent(channelArn)}/memberships',
    headers: headers,
    exceptionFnMap: _exceptionFns,
  );
  return CreateChannelMembershipResponse.fromJson(response);
}