Skip to content

create_channel_membership

create_channel_membership(
    channel_arn: ChimeArn,
    member_arn: ChimeArn,
    type: ChannelMembershipType,
    chime_bearer: ChimeArn,
    *,
    config_overrides: Optional[ChimeSDKMessagingClientConfig] = None,
    sub_channel_id: Optional[SubChannelId] = None,
) -> CreateChannelMembershipResponse

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.

The x-amz-chime-bearer request header is mandatory. Use the ARN of the AppInstanceUserArn or AppInstanceBot that makes the API call as the value in the header.

Parameters:

  • channel_arn (ChimeArn) –

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

  • member_arn (ChimeArn) –

    The AppInstanceUserArn of the member you want to add to the channel.

  • type (ChannelMembershipType) –

    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.

  • chime_bearer (ChimeArn) –

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

  • sub_channel_id (Optional[SubChannelId], default: None ) –

    The ID of the SubChannel in the request.

    Only required when creating membership in a SubChannel for a moderator in an elastic channel.

Raises:

Source code in docs_src/capo_chime_sdk_messaging/_services/chime_sdk_messaging.py
def create_channel_membership(
    self,
    channel_arn: "capo_chime_sdk_messaging.types.chime_arn.ChimeArn",
    member_arn: "capo_chime_sdk_messaging.types.chime_arn.ChimeArn",
    type: "capo_chime_sdk_messaging.types.channel_membership_type.ChannelMembershipType",
    chime_bearer: "capo_chime_sdk_messaging.types.chime_arn.ChimeArn",
    *,
    config_overrides: Optional[ChimeSDKMessagingClientConfig] = None,
    sub_channel_id: Optional[
        "capo_chime_sdk_messaging.types.sub_channel_id.SubChannelId"
    ] = None,
) -> "capo_chime_sdk_messaging.types.create_channel_membership_response.CreateChannelMembershipResponse":
    """<p>Adds a member to a channel. The <code>InvitedBy</code> field in <code>ChannelMembership</code> is derived from the request header. A channel member can:</p> <ul> <li> <p>List messages</p> </li> <li> <p>Send messages</p> </li> <li> <p>Receive messages</p> </li> <li> <p>Edit their own messages</p> </li> <li> <p>Leave the channel</p> </li> </ul> <p>Privacy settings impact this action as follows:</p> <ul> <li> <p>Public Channels: You do not need to be a member to list messages, but you must be a member to send messages.</p> </li> <li> <p>Private Channels: You must be a member to list or send messages.</p> </li> </ul> <note> <p>The <code>x-amz-chime-bearer</code> request header is mandatory. Use the ARN of the <code>AppInstanceUserArn</code> or <code>AppInstanceBot</code> that makes the API call as the value in the header.</p> </note>

    Args:
        channel_arn: <p>The ARN of the channel to which you're adding users.</p>
        member_arn: <p>The <code>AppInstanceUserArn</code> of the member you want to add to the channel.</p>
        type: <p>The membership type of a user, <code>DEFAULT</code> or <code>HIDDEN</code>. Default members are always returned as part of <code>ListChannelMemberships</code>. Hidden members are only returned if the type filter in <code>ListChannelMemberships</code> equals <code>HIDDEN</code>. Otherwise hidden members are not returned. This is only supported by moderators.</p>
        chime_bearer: <p>The ARN of the <code>AppInstanceUser</code> or <code>AppInstanceBot</code> that makes the API call.</p>
        sub_channel_id: <p>The ID of the SubChannel in the request.</p> <note> <p>Only required when creating membership in a SubChannel for a moderator in an elastic channel.</p> </note>

    Raises:
        capo_chime_sdk_messaging.errors.bad_request_exception.BadRequestException: <p>The input parameters don't match the service's restrictions.</p>
        capo_chime_sdk_messaging.errors.conflict_exception.ConflictException: <p>The request could not be processed because of conflict in the current state of the resource.</p>
        capo_chime_sdk_messaging.errors.forbidden_exception.ForbiddenException: <p>The client is permanently forbidden from making the request.</p>
        capo_chime_sdk_messaging.errors.not_found_exception.NotFoundException: <p>One or more of the resources in the request does not exist in the system.</p>
        capo_chime_sdk_messaging.errors.resource_limit_exceeded_exception.ResourceLimitExceededException: <p>The request exceeds the resource limit.</p>
        capo_chime_sdk_messaging.errors.service_failure_exception.ServiceFailureException: <p>The service encountered an unexpected error.</p>
        capo_chime_sdk_messaging.errors.service_unavailable_exception.ServiceUnavailableException: <p>The service is currently unavailable.</p>
        capo_chime_sdk_messaging.errors.throttled_client_exception.ThrottledClientException: <p>The client exceeded its request rate limit.</p>
        capo_chime_sdk_messaging.errors.unauthorized_client_exception.UnauthorizedClientException: <p>The client is not currently authorized to make the request.</p>
        capo_chime_sdk_messaging.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_chime_sdk_messaging.types.create_channel_membership_request.CreateChannelMembershipRequest]",
    ) -> OperationResponse[
        "capo_chime_sdk_messaging.types.create_channel_membership_response.CreateChannelMembershipResponse"
    ]:
        import capo_chime_sdk_messaging._operations.chime_messaging_service.create_channel_membership

        output, http_response = (
            capo_chime_sdk_messaging._operations.chime_messaging_service.create_channel_membership.create_channel_membership(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    def _redact_output(
        output: "capo_chime_sdk_messaging.types.create_channel_membership_response.CreateChannelMembershipResponse",
    ) -> dict[str, Any]:
        import capo_chime_sdk_messaging.types.create_channel_membership_response

        return capo_chime_sdk_messaging.types.create_channel_membership_response.redact_sensitive(
            output
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging("CreateChannelMembership", redact_output=_redact_output),
    )
    input_: capo_chime_sdk_messaging.types.create_channel_membership_request.CreateChannelMembershipRequest = {
        "channel_arn": channel_arn,
        "member_arn": member_arn,
        "type": type,
        "chime_bearer": chime_bearer,
    }
    if sub_channel_id is not None:
        input_["sub_channel_id"] = sub_channel_id

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output