CustomerProvider

public protocol CustomerProvider : Sendable

The provider for customer related properties and methods.

  • The customer currently using the app.

    Declaration

    Swift

    func get() -> CustomerIdentity?

    Return Value

    Returns customer if it is set. Otherwise; returns nil.

  • Sets the customer currently using the app.

    If you set your customer ID, you must ensure that it is unique and that it is not used by any other customer.

    Note

    Setting your own Customer ID may result in security vulnerabilities. It is recommended to use the customer ID provided by the SDK. If you want to update the customer name, use the setName(firstName:lastName:) method.

    Warning

    This method must be called before SDK initialization via prepare(environment:brandId:channelId:).

    Throws

    illegalChatState if the chat is already initialized.

    Declaration

    Swift

    func set(customer: CustomerIdentity?) throws

    Parameters

    customer

    The customer identity. Can be nil.

  • Registers a device to be used for push notifications.

    Declaration

    Swift

    func setDeviceToken(_ token: String)

    Parameters

    token

    The unique token for the device to be registered.

  • Registers a device to be used for push notifications.

    Declaration

    Swift

    func setDeviceToken(_ tokenData: Data)

    Parameters

    tokenData

    The unique token for the device to be registered.

  • Provides a connection token and its expiry to the SDK for the implicit OAuth flow.

    Call this before connect() with the JWT obtained from your OAuth provider, and again whenever the SDK reports the token is no longer valid by throwing invalidAccessToken from an outbound method — obtain a fresh token, provide it here, and retry the operation that threw.

    The SDK uses expiresAt to detect an expired token before sending an event (a backend rejection of an already-open socket is not otherwise observable) and to signal you to refresh in time. The SDK never sources tokens on its own — it always obtains them from the integrator, either via this call or via the listener registered with setTokenDelegateListener(_:).

    Declaration

    Swift

    func setConnectionToken(_ token: String, expiresAt: Date)

    Parameters

    token

    A valid JWT obtained from the OAuth provider.

    expiresAt

    The absolute time at which token expires (e.g. derived from the provider’s expires_in).

  • Registers a listener the SDK calls to obtain a fresh connection token for the implicit OAuth flow.

    When registered, the SDK requests a fresh token automatically — shortly before the current one expires (tokenExpired) or after the backend rejects it at connect (tokenInvalid). It pauses the pending operation, obtains the token, and resumes it, so outbound events are not interrupted. Concurrent operations queue behind a single refresh. The listener obtains a token from your OAuth provider and returns an OAuthToken; if it throws, the pending operation fails with invalidAccessToken.

    The initial token is still provided via setConnectionToken(_:expiresAt:); this listener handles subsequent refreshes. When no listener is registered, an expired token surfaces reactively as invalidAccessToken from the outbound method.

    Declaration

    Swift

    func setTokenDelegateListener(_ listener: TokenDelegateListener?)

    Parameters

    listener

    The token listener, or nil to remove a previously registered one.

  • Sets the authorization code for the explicit OAuth flow (PKCE).

    Call this before connect() when using an explicit OAuth flow.

    Declaration

    Swift

    func setAuthorizationCode(_ code: String)

    Parameters

    code

    The authorization code received from the OAuth provider.

  • Sets the PKCE code verifier for the explicit OAuth flow.

    Call this before connect() when using an explicit OAuth flow.

    Declaration

    Swift

    func setCodeVerifier(_ verifier: String)

    Parameters

    verifier

    The PKCE code verifier generated locally before the authorization request.

  • Sets the name to be used for the customer in the chat.

    Declaration

    Swift

    func setName(firstName: String, lastName: String)

    Parameters

    firstName

    The first name for the customer.

    lastName

    The last name for the customer.