Class: Cadenya::Resources::WidgetSessions

Inherits:
Object
  • Object
show all
Defined in:
lib/cadenya/resources/widget_sessions.rb,
sig/cadenya/resources/widget_sessions.rbs

Overview

Mint and manage widget sessions. Session creation is server-to-server only: the customer's backend authenticates its visitor, asserts tenant/subject context, attaches any per-visitor secrets, and receives a short-lived bearer token the browser uses against the widget host.

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ WidgetSessions

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of WidgetSessions.

Parameters:



235
236
237
# File 'lib/cadenya/resources/widget_sessions.rb', line 235

def initialize(client:)
  @client = client
end

Instance Method Details

#create(spec:, workspace_id: nil, metadata: nil, secrets: nil, request_options: {}) ⇒ Cadenya::Models::WidgetSession

Some parameter documentations has been truncated, see Models::WidgetSessionCreateParams for more details.

Mints a session against a widget and returns the session bearer token (spec.token, returned only on creation) plus the authoritative widget hostname (info.host). Asserting a tenant upserts the tenant record; attached secrets flow to every conversation the session creates.

Parameters:

Returns:

See Also:



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/cadenya/resources/widget_sessions.rb', line 33

def create(params)
  parsed, options = Cadenya::WidgetSessionCreateParams.dump_request(params)
  workspace_id =
    parsed.delete(:workspace_id) do
      @client.workspace_id
    end
  @client.request(
    method: :post,
    path: ["v1/workspaces/%1$s/widget_sessions", workspace_id],
    body: parsed,
    model: Cadenya::WidgetSession,
    options: options
  )
end

#delete(id, workspace_id: nil, request_options: {}) ⇒ nil

Some parameter documentations has been truncated, see Models::WidgetSessionDeleteParams for more details.

Deletes a session and its secrets. The session's conversations are disassociated, not deleted; use the tenant-level delete for full erasure.

Parameters:

  • id (String)

    Session ID. Accepts the canonical wsess_… form or the external_id:<value> fo

  • workspace_id (String)

    Workspace ID.

  • request_options (Cadenya::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

  • (nil)

See Also:



151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/cadenya/resources/widget_sessions.rb', line 151

def delete(id, params = {})
  parsed, options = Cadenya::WidgetSessionDeleteParams.dump_request(params)
  workspace_id =
    parsed.delete(:workspace_id) do
      @client.workspace_id
    end
  @client.request(
    method: :delete,
    path: ["v1/workspaces/%1$s/widget_sessions/%2$s", workspace_id, id],
    model: NilClass,
    options: options
  )
end

#delete_tenant(workspace_id: nil, tenant_id: nil, request_options: {}) ⇒ Cadenya::Models::WidgetSessionDeleteTenantResponse

Some parameter documentations has been truncated, see Models::WidgetSessionDeleteTenantParams for more details.

Deletes every session belonging to a tenant across all widgets in the workspace, along with the conversations those sessions created — built for GDPR erasure requests. The tenant is required; an empty value is rejected rather than matching everything.

Parameters:

  • workspace_id (String)

    Path param: Workspace ID.

  • tenant_id (String)

    Query param: Tenant whose sessions to delete. Required — an empty value is rejec

  • request_options (Cadenya::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/cadenya/resources/widget_sessions.rb', line 184

def delete_tenant(params = {})
  parsed, options = Cadenya::WidgetSessionDeleteTenantParams.dump_request(params)
  query = Cadenya::Internal::Util.encode_query_params(parsed)
  workspace_id =
    parsed.delete(:workspace_id) do
      @client.workspace_id
    end
  @client.request(
    method: :delete,
    path: ["v1/workspaces/%1$s/widget_sessions", workspace_id],
    query: query.transform_keys(tenant_id: "tenantId"),
    model: Cadenya::Models::WidgetSessionDeleteTenantResponse,
    options: options
  )
end

#list(workspace_id: nil, cursor: nil, include_info: nil, labels: nil, limit: nil, sort_order: nil, state: nil, subject_id: nil, tenant_id: nil, widget_id: nil, request_options: {}) ⇒ Cadenya::Internal::CursorPagination<Cadenya::Models::WidgetSession>

Some parameter documentations has been truncated, see Models::WidgetSessionListParams for more details.

Lists widget sessions in a workspace, filterable by widget, tenant, subject, and state

Parameters:

  • workspace_id (String)

    Path param: Workspace ID.

  • cursor (String)

    Query param: Pagination cursor from previous response.

  • include_info (Boolean)

    Query param: When true, the info field on each returned session is populated.

  • labels (String)

    Query param: Filters by metadata labels. Comma-separated key=value pairs,

  • limit (Integer)

    Query param: Maximum number of results to return.

  • sort_order (String)

    Query param: Sort order for results (asc or desc by creation time).

  • state (Symbol, Cadenya::Models::WidgetSessionListParams::State)

    Query param: Filter by state.

  • subject_id (String)

    Query param: Filter to sessions asserted for a subject. Accepts the canonical

  • tenant_id (String)

    Query param: Filter to sessions belonging to a tenant. Accepts the canonical

  • widget_id (String)

    Query param: Filter to sessions on a specific widget. Accepts the canonical `wgt

  • request_options (Cadenya::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/cadenya/resources/widget_sessions.rb', line 111

def list(params = {})
  parsed, options = Cadenya::WidgetSessionListParams.dump_request(params)
  query = Cadenya::Internal::Util.encode_query_params(parsed)
  workspace_id =
    parsed.delete(:workspace_id) do
      @client.workspace_id
    end
  @client.request(
    method: :get,
    path: ["v1/workspaces/%1$s/widget_sessions", workspace_id],
    query: query.transform_keys(
      include_info: "includeInfo",
      sort_order: "sortOrder",
      subject_id: "subjectId",
      tenant_id: "tenantId",
      widget_id: "widgetId"
    ),
    page: Cadenya::Internal::CursorPagination,
    model: Cadenya::WidgetSession,
    options: options
  )
end

#retrieve(id, workspace_id: nil, request_options: {}) ⇒ Cadenya::Models::WidgetSession

Some parameter documentations has been truncated, see Models::WidgetSessionRetrieveParams for more details.

Retrieves a widget session. The bearer token is never returned on reads.

Parameters:

  • id (String)

    Session ID. Accepts the canonical wsess_… form or the external_id:<value> fo

  • workspace_id (String)

    Workspace ID.

  • request_options (Cadenya::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/cadenya/resources/widget_sessions.rb', line 64

def retrieve(id, params = {})
  parsed, options = Cadenya::WidgetSessionRetrieveParams.dump_request(params)
  workspace_id =
    parsed.delete(:workspace_id) do
      @client.workspace_id
    end
  @client.request(
    method: :get,
    path: ["v1/workspaces/%1$s/widget_sessions/%2$s", workspace_id, id],
    model: Cadenya::WidgetSession,
    options: options
  )
end

#revoke(id, workspace_id: nil, request_options: {}) ⇒ Cadenya::Models::WidgetSession

Some parameter documentations has been truncated, see Models::WidgetSessionRevokeParams for more details.

Transitions a session to STATE_REVOKED. Outstanding tokens stop working immediately, open event streams close within seconds, and the session's secrets are deleted. Terminal.

Parameters:

  • id (String)

    Session ID. Accepts the canonical wsess_… form or the external_id:<value> fo

  • workspace_id (String)

    Workspace ID.

  • request_options (Cadenya::RequestOptions, Hash{Symbol=>Object}, nil)

Returns:

See Also:



218
219
220
221
222
223
224
225
226
227
228
229
230
# File 'lib/cadenya/resources/widget_sessions.rb', line 218

def revoke(id, params = {})
  parsed, options = Cadenya::WidgetSessionRevokeParams.dump_request(params)
  workspace_id =
    parsed.delete(:workspace_id) do
      @client.workspace_id
    end
  @client.request(
    method: :post,
    path: ["v1/workspaces/%1$s/widget_sessions/%2$s:revoke", workspace_id, id],
    model: Cadenya::WidgetSession,
    options: options
  )
end