intelligence-cloud 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. intelligence_cloud-0.1.0/.gitignore +17 -0
  2. intelligence_cloud-0.1.0/CHANGELOG.md +42 -0
  3. intelligence_cloud-0.1.0/LICENSE +22 -0
  4. intelligence_cloud-0.1.0/PKG-INFO +410 -0
  5. intelligence_cloud-0.1.0/README.md +371 -0
  6. intelligence_cloud-0.1.0/SECURITY.md +9 -0
  7. intelligence_cloud-0.1.0/examples/_common.py +23 -0
  8. intelligence_cloud-0.1.0/examples/after-call-sample.json +27 -0
  9. intelligence_cloud-0.1.0/examples/alert_webhook_receiver.py +114 -0
  10. intelligence_cloud-0.1.0/examples/export_calls.py +20 -0
  11. intelligence_cloud-0.1.0/examples/provision_seat.py +48 -0
  12. intelligence_cloud-0.1.0/examples/webhook_receiver.py +151 -0
  13. intelligence_cloud-0.1.0/examples/whoami.py +6 -0
  14. intelligence_cloud-0.1.0/pyproject.toml +34 -0
  15. intelligence_cloud-0.1.0/src/intelligence_cloud/__init__.py +62 -0
  16. intelligence_cloud-0.1.0/src/intelligence_cloud/_base.py +75 -0
  17. intelligence_cloud-0.1.0/src/intelligence_cloud/_generated.py +533 -0
  18. intelligence_cloud-0.1.0/src/intelligence_cloud/_spec.py +334 -0
  19. intelligence_cloud-0.1.0/src/intelligence_cloud/_version.py +1 -0
  20. intelligence_cloud-0.1.0/src/intelligence_cloud/auth.py +142 -0
  21. intelligence_cloud-0.1.0/src/intelligence_cloud/client.py +433 -0
  22. intelligence_cloud-0.1.0/src/intelligence_cloud/data/spec.json +6391 -0
  23. intelligence_cloud-0.1.0/src/intelligence_cloud/errors.py +179 -0
  24. intelligence_cloud-0.1.0/src/intelligence_cloud/intelligence.py +292 -0
  25. intelligence_cloud-0.1.0/src/intelligence_cloud/py.typed +0 -0
  26. intelligence_cloud-0.1.0/src/intelligence_cloud/receiver.py +197 -0
  27. intelligence_cloud-0.1.0/src/intelligence_cloud/resources.py +358 -0
  28. intelligence_cloud-0.1.0/src/intelligence_cloud/workflows.py +791 -0
  29. intelligence_cloud-0.1.0/tests/__init__.py +0 -0
  30. intelligence_cloud-0.1.0/tests/live/test_live.py +449 -0
  31. intelligence_cloud-0.1.0/tests/unit/__init__.py +0 -0
  32. intelligence_cloud-0.1.0/tests/unit/fake_api.py +420 -0
  33. intelligence_cloud-0.1.0/tests/unit/test_client.py +617 -0
  34. intelligence_cloud-0.1.0/tests/unit/test_intelligence.py +209 -0
  35. intelligence_cloud-0.1.0/tests/unit/test_review2.py +408 -0
  36. intelligence_cloud-0.1.0/tests/unit/test_workflows.py +362 -0
  37. intelligence_cloud-0.1.0/tools/generate.py +239 -0
@@ -0,0 +1,17 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *.egg-info/
4
+ .venv/
5
+ venv/
6
+ build/
7
+ dist/
8
+ *.whl
9
+ .pytest_cache/
10
+ .ruff_cache/
11
+ .mypy_cache/
12
+ .coverage
13
+ coverage/
14
+ htmlcov/
15
+ uv.lock
16
+ .env
17
+ .DS_Store
@@ -0,0 +1,42 @@
1
+ # Changelog
2
+
3
+ ## 0.1.0: Base Intelligence Seat manager lines (2026-11-18)
4
+
5
+ - On the Base Intelligence Seat a manager's own phone line is not captured. `add_manager(customer, user, *, activate_alerts=True)` no longer takes `own_extension` (`activate_alerts` is keyword-only, so an extension passed positionally raises `TypeError`): a manager is mapped to exactly the end-user lines at the location, and their own extension is never mapped, nor added to First Alert or Insights Hub.
6
+ - `sync_numbers` sets every manager's mapping to exactly the lines (as for integration users); a number on a manager that is not a line is removed.
7
+
8
+ ## 0.1.0: review changes (2026-11-17)
9
+
10
+ - Licence: the Intelligence Cloud SDK Licence (Copyright (c) 2026 Creo Solutions, Inc. d/b/a Tresic), the same text in every SDK: partners, their customers and contractors may use, copy, modify and distribute the SDK solely to access Intelligence Cloud; provided as is.
11
+ - **Python 3.10 or later, `httpx` 0.27 or later.** The package ships `py.typed`.
12
+ - `provision_seat_customer` never adopts a company by its name alone. Pass `SeatCustomerSpec.company_id` (store it from the first run). Without it, a same-named company is used only when its primary contact email is `admin_email`; otherwise `ConflictError` (code `company_name_conflict`) is raised before anything is written. New helper `companies.find_companies`.
13
+ - Integration users: `add_integration_user` (password sign-in, tagged `department: "integration"`, all products, both groups, alert email off, every line) and `list_integration_users`. Integration users are never counted as seats or managers and get every new line. A manager now needs all three products.
14
+ - `remove_user` releases only an end user's line, and only when no other end user holds it. Removing a manager, an integration user or anyone holding several lines never takes a line off anyone else. `sync_numbers` counts as lines only end users holding exactly one number.
15
+ - `SeatCustomer.exclude_user_ids` / `exclude_emails`: users every workflow ignores.
16
+ - `offboard_customer`: pause the After Call webhook, clear the First Alert webhook, stop the connector, deactivate integration users, deactivate the company.
17
+ - Connectors are matched on their phone-system domain. A re-run updates a connector in `error`, stopped or changed with the settings passed (including a new key) and restarts it; it never creates a second one.
18
+ - `parse_after_call_event` returns `UnknownEvent` for event types it doesn't handle, and takes `max_bytes` (256 KB, `MAX_EVENT_BYTES`; `PayloadTooLargeError` above it).
19
+ - Token stores may implement `lock()` for sharing tokens across processes; new `FileTokenStore`. A 429 on renewal retries the same refresh token instead of signing in.
20
+ - `Retry-After` is honoured up to 60 seconds; a longer one raises `RateLimitError` at once. `Client(login_rate_limit_wait=60)` makes the sign-in wait configurable.
21
+ - `Client(keep_unknown_fields=True)` keeps response fields the reference doesn't list yet on customer-lifecycle reads (never sign-in links; conversation-data reads always keep only documented fields).
22
+ - `base_url` must be https (http only for localhost). A `datetime` without a time zone is refused. Alert `numbers` send North American numbers as their last 10 digits.
23
+ - Exception text carries only the status, code and request id (plus text the SDK wrote); the server's text stays on `.message`.
24
+ - Examples: receivers read their path token from the environment and refuse one shorter than 32 characters; the After Call receiver caps bodies at 256 KB, stores each call id in a persistent queue before answering and reads the call before using it. `examples/after-call-sample.json` for local tests.
25
+ - `tools/generate.py` takes the spec path (required) and `--check`.
26
+
27
+ ## 0.1.0 (2026-11-16)
28
+
29
+ First release.
30
+
31
+ - Client with email and password sign-in for a dedicated integration user, automatic token renewal (single-use refresh tokens, renewal serialised across threads) and a pluggable token store.
32
+ - One method per API operation, grouped by reference section, with `iter_*` paging.
33
+ - Filters checked before sending: unknown filters, date-only values, enum values, up to 25 numbers and 50 location ids.
34
+ - Responses carry only the fields in the published reference.
35
+ - Read-merge-write helpers for every full-replacement write.
36
+ - User create with an idempotency key and recovery when a refused create left the user behind.
37
+ - Connector create, reactivate and deactivate wait for the final status, checking every 10 seconds for up to 10 minutes (`timeout=`, `ConnectorsAPI.check_interval`).
38
+ - Base Intelligence Seat workflows: provision a customer, add managers and end users, change an extension, remove a user, list users by type, sync numbers.
39
+ - Workflows email each user's invitation last, after their lines are mapped. Alert rules are created switched off and come on with the first manager (`activate_seat_alerts`).
40
+ - Conversation intelligence: calls, transcripts, recording links, alerts, tasks, insights.
41
+ - After Call and First Alert webhook configuration, After Call event parsing and de-duplication.
42
+ - New calls and alerts reach you on the After Call and First Alert webhooks (2026-11-17). `examples/alert_webhook_receiver.py` is a First Alert receiver: it reads only the alert id, answers at once and fetches the alert and its call with `get_alert(alert_id, with_call=True)`. The README covers a one-off catch-up after an outage.
@@ -0,0 +1,22 @@
1
+ Intelligence Cloud SDK Licence
2
+
3
+ Copyright (c) 2026 Creo Solutions, Inc. d/b/a Tresic
4
+
5
+ Permission is granted to Intelligence Cloud partners, their customers, and contractors working for
6
+ either, to use, copy, modify and distribute this software, in source or compiled form and as part of
7
+ their own applications, solely to access Intelligence Cloud services under an agreement with Tresic
8
+ or an authorised Tresic partner. Keep this notice in copies of the source.
9
+
10
+ Use of the Intelligence Cloud API, with or without this software, is governed by the Intelligence
11
+ Cloud API and SDK Terms (https://docs.intelligence.cloud/terms/api) and by your
12
+ agreement with Tresic or with your provider.
13
+
14
+ This licence grants no right in any Tresic patent or patent application, trademark, or the
15
+ Intelligence Cloud service, other than the right to use this software as provided. This licence ends
16
+ when your right to access Intelligence Cloud ends.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
19
+ WITHOUT LIMITATION THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20
+ NON-INFRINGEMENT. CREO SOLUTIONS, INC. D/B/A TRESIC IS NOT LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR ITS USE.
@@ -0,0 +1,410 @@
1
+ Metadata-Version: 2.5
2
+ Name: intelligence-cloud
3
+ Version: 0.1.0
4
+ Summary: Python client for the Intelligence Cloud partner API: customer lifecycle and conversation intelligence.
5
+ Project-URL: Homepage, https://docs.intelligence.cloud
6
+ Project-URL: Documentation, https://docs.intelligence.cloud/api
7
+ Project-URL: Source, https://github.com/tresic-cloud/intelligence-cloud-sdk-python
8
+ Author: Tresic
9
+ License: Intelligence Cloud SDK Licence
10
+
11
+ Copyright (c) 2026 Creo Solutions, Inc. d/b/a Tresic
12
+
13
+ Permission is granted to Intelligence Cloud partners, their customers, and contractors working for
14
+ either, to use, copy, modify and distribute this software, in source or compiled form and as part of
15
+ their own applications, solely to access Intelligence Cloud services under an agreement with Tresic
16
+ or an authorised Tresic partner. Keep this notice in copies of the source.
17
+
18
+ Use of the Intelligence Cloud API, with or without this software, is governed by the Intelligence
19
+ Cloud API and SDK Terms (https://docs.intelligence.cloud/terms/api) and by your
20
+ agreement with Tresic or with your provider.
21
+
22
+ This licence grants no right in any Tresic patent or patent application, trademark, or the
23
+ Intelligence Cloud service, other than the right to use this software as provided. This licence ends
24
+ when your right to access Intelligence Cloud ends.
25
+
26
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
27
+ WITHOUT LIMITATION THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28
+ NON-INFRINGEMENT. CREO SOLUTIONS, INC. D/B/A TRESIC IS NOT LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29
+ LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
30
+ SOFTWARE OR ITS USE.
31
+ License-File: LICENSE
32
+ Classifier: License :: Other/Proprietary License
33
+ Classifier: Operating System :: OS Independent
34
+ Classifier: Programming Language :: Python :: 3
35
+ Classifier: Typing :: Typed
36
+ Requires-Python: >=3.10
37
+ Requires-Dist: httpx<1,>=0.27
38
+ Description-Content-Type: text/markdown
39
+
40
+ # Intelligence Cloud Python SDK
41
+
42
+ Python client for the Intelligence Cloud partner API. It covers both jobs:
43
+
44
+ - **Customer lifecycle** with admin credentials (a reseller admin login): companies, locations, users, products, connectors, First Alert, Insights Hub, and the Base Intelligence Seat workflows.
45
+ - **Conversation intelligence** with frontline credentials (a frontline user login): calls, transcripts, recordings, alerts, tasks, insights, and the After Call webhook.
46
+
47
+ Version 0.1.0. Python 3.10 or later. One dependency: `httpx` (0.27 or later).
48
+
49
+ The API reference is at https://docs.intelligence.cloud/reference.html, built from https://docs.intelligence.cloud/openapi.yaml.
50
+
51
+ ## Install
52
+
53
+ ```bash
54
+ pip install intelligence-cloud # or: uv add intelligence-cloud
55
+ ```
56
+
57
+ The import name is `intelligence_cloud`.
58
+
59
+ Alternative, from the source download:
60
+
61
+ ```bash
62
+ unzip python.zip && cd python
63
+ pip install . # or: uv pip install .
64
+ ```
65
+
66
+ To run the examples without installing: `uv run --with httpx --with-editable . python examples/whoami.py`.
67
+
68
+ ## Credentials
69
+
70
+ Today every integration signs in with the email and password of a **dedicated integration user**. Turn MFA off for that user's company (`mfa_off=True` in `provision_seat_customer`, or `PATCH /companies/{id}` with `mfa_enforced: false`). **API keys arrive in December 2026.**
71
+
72
+ Use one client per credential:
73
+
74
+ | Credential | Role | Use it for |
75
+ |---|---|---|
76
+ | Admin | `reseller_admin` | `client.companies`, `client.users`, ... and `client.workflows` |
77
+ | Frontline | `frontline_user` | `client.intelligence` (calls, alerts, tasks, insights) |
78
+
79
+ Admin logins get empty lists from the conversation-data endpoints by design. `client.intelligence` checks the role once and raises `FrontlineRequiredError` instead of returning empty data.
80
+
81
+ Keep credentials out of source code. Read them from your secret store or environment. Send secrets to Tresic only through **security@tresic.cloud**, and report security issues there too.
82
+
83
+ ```python
84
+ import os
85
+ from intelligence_cloud import Client
86
+
87
+ admin = Client(email=os.environ["IC_ADMIN_EMAIL"], password=os.environ["IC_ADMIN_PASSWORD"])
88
+ data = Client(email=os.environ["IC_DATA_EMAIL"], password=os.environ["IC_DATA_PASSWORD"])
89
+ ```
90
+
91
+ `Client(base_url="https://app.intelligence.cloud/api/v1", email, password, token_store=None, timeout=30)`; also `user_agent=` (prefixed to the SDK's own), `max_retries=3`, `login_rate_limit_wait=60` (seconds; `0` raises `RateLimitError` at once, better inside a web request) and `keep_unknown_fields=False` (see "Rules the SDK applies for you"). `base_url` must be `https://` (`http://` only for `localhost`). If you pass your own `transport=`, keep certificate verification on.
92
+
93
+ ### Sign-in, tokens and sign-out
94
+
95
+ - The client signs in on first use and keeps the access and refresh tokens in memory.
96
+ - Sign-in is limited to 5 per minute per IP. Sign in once per job and reuse the client. On a 429 at sign-in the client waits `login_rate_limit_wait` seconds (60) once.
97
+ - On a 401 the client renews the token once and retries. Refresh tokens are single-use: the new pair is stored before it is used and an old refresh token is never sent again. Renewal is serialised with a lock, so threads sharing a client renew once. A 429 on renewal is waited out and the same refresh token is sent again; it never turns into a sign-in.
98
+ - To keep tokens across runs, pass a `token_store` with `get()` and `set(tokens)`. Store tokens like passwords.
99
+ - **Several processes, one integration user** (workers, serverless, a cron job next to a web app): use one shared store that also has `lock()`, a context manager holding a lock across processes. The client signs in and renews inside it and re-reads the store first, so two processes never send the same refresh token (a replayed refresh token ends the session everywhere). `FileTokenStore(path)` does this for processes on one machine (file mode 0600, lock file beside it). Never create a client per request.
100
+ - `client.close()` closes connections. It does **not** sign out.
101
+ - `client.logout()` signs out and **ends every session of that user, including the web app**. The SDK never calls it by itself.
102
+ - Sign-in returning `mfa_required` raises `MfaRequiredError`: "Integration users need MFA off for their company. API keys arrive in December 2026."
103
+
104
+ ## Quick start: customer lifecycle (admin)
105
+
106
+ Provision a Base Intelligence Seat customer: one location, After Call for end users, First Alert and Insights Hub for managers, the "Upset Customer" and "Customer Threat" alerts routed to "Manager Alerts", and an "Insights Hub Access" group.
107
+
108
+ ```python
109
+ from intelligence_cloud import Client, SeatCustomerSpec, LocationSpec, ConnectorSpec, UserSpec
110
+
111
+ admin = Client(email=..., password=...)
112
+
113
+ customer = admin.workflows.provision_seat_customer(SeatCustomerSpec(
114
+ company_id=saved_company_id, # None the first time; store customer.company_id and pass it on re-runs
115
+ company_name="Riverbend Auto Group",
116
+ admin_name="Pat Lee", admin_email="pat.lee@example.com", admin_phone="+15555550100",
117
+ location=LocationSpec(name="Riverbend - Main", street="1 River Rd", city="Springfield",
118
+ state="IL", country="US", zipcode="62701", vertical="<vertical id or key>"),
119
+ threat_phrases=customer_threat_phrases, # from your Tresic contact
120
+ mfa_off=True, # the company has an integration user
121
+ connector=ConnectorSpec(api_url="https://pbx.example.com/ns-api/v2",
122
+ domain="riverbend.example.com", api_key=phone_system_key),
123
+ sso_domain="riverbend.example.com", # optional: returns the DNS TXT record to publish
124
+ ))
125
+
126
+ # End users first: each line is mapped, then the invitation is emailed.
127
+ admin.workflows.add_frontline_user(customer, UserSpec("sam.ortiz@example.com", "Sam", "Ortiz"), "2101")
128
+ # The first manager switches the two alerts on, then gets the invitation.
129
+ admin.workflows.add_manager(customer, UserSpec("dana.cho@example.com", "Dana", "Cho"))
130
+ ```
131
+
132
+ - **Customer Threat phrases are provided by your Tresic contact.** Pass them as `threat_phrases`. Creating the Customer Threat alert without them raises `InvalidRequestError`.
133
+ - The primary contact (`admin_email`) is always invited as customer admin by email.
134
+ - Every workflow can be run again. **Store `customer.company_id` and pass it as `company_id` on every re-run.** Without it, a company with the same name is used only when its primary contact email is `admin_email`; any other company with that name raises `ConflictError` (code `company_name_conflict`) before anything is written. The location, groups and rules are found by name, users by email, and the connector by its phone-system domain. A company or location found inactive raises unless `reactivate=True`.
135
+ - Both alert rules are created **switched off**. `add_manager` switches them on once the manager is set up (`activate_alerts=True`, the default). To switch them on yourself, pass `activate_alerts=False` and call `activate_seat_alerts(customer)` when you are ready. Re-running `provision_seat_customer` never switches a rule off.
136
+ - Users are created **without** an invitation. The workflow maps their lines and sets their products and groups, and only then emails the invitation. If a mapping is refused, `ExtensionMappingError` is raised and no invitation has been sent. Pass `UserSpec(..., send_invitation=False)` to invite later with `admin.users.resend_invitation(company_id, user_id)`.
137
+ - The connector connects in the background. The workflow checks it every 10 seconds, for up to 10 minutes (`ConnectorSpec(timeout=...)`), until it is `active` or `error`, and records `connector_status` and `connector_state_reason` on the result. A key that cannot create call subscriptions ends in `error` / `invalid_permissions`: use a read/write key. Re-run the workflow with the corrected key: a connector found in `error`, stopped, or with changed settings is updated with the settings you pass and restarted, never duplicated.
138
+ - Get the customer object back later with `admin.workflows.get_seat_customer(company_id)`.
139
+
140
+ ### Seat workflows
141
+
142
+ | Method | Does |
143
+ |---|---|
144
+ | `provision_seat_customer(spec)` | Company, MFA off (optional), products, location, groups, both rules (switched off), connector (optional), Insights Hub access, SSO domain claim (optional). Returns `SeatCustomer` with every id. |
145
+ | `get_seat_customer(company_id)` | Rebuilds `SeatCustomer` from what is configured. |
146
+ | `add_frontline_user(customer, user, extension)` | Creates an end user (no invitation yet) with After Call on their own line and alert email off, maps the line, adds it to every manager, First Alert and Insights Hub, then emails the invitation. |
147
+ | `add_manager(customer, user, *, activate_alerts=True)` | Creates a manager (no invitation yet) with all three products, both groups and alert email on, maps all end-user lines at the location, switches both alerts on, then emails the invitation. The manager's own phone line is not captured on the Seat: it is never mapped, nor added to First Alert or Insights Hub. |
148
+ | `activate_seat_alerts(customer)` | Switches on the Upset Customer and Customer Threat rules. Returns the ids it switched on. |
149
+ | `change_user_extension(customer, user_id, old, new)` | Moves an end user's line: their mapping, every manager, First Alert, Insights Hub. |
150
+ | `add_integration_user(customer, user)` | Creates the customer's integration (data-reading) user: password sign-in, tagged `department: "integration"`, all three products, both groups, alert email off, every line. Never counted as a seat or manager; later end users' lines are added to it. Invitation last. |
151
+ | `remove_user(customer, user_id, keep_extensions=False)` | Removes the user from groups, clears their numbers, then deactivates. Only an end user's line is released, and only when no other end user holds it: it comes off managers, integration users, First Alert and Insights Hub (unless kept). Removing a manager, an integration user or anyone holding several lines never takes a line off anyone else. |
152
+ | `list_frontline_users(customer)` / `list_managers(customer)` / `list_integration_users(customer)` | The location's users, classified: end users have After Call only; managers have all three products; integration users are tagged `department: "integration"`. |
153
+ | `sync_numbers(customer, dry_run=False)` | Recomputes the location's lines (each end user's single extension) and pushes them to managers, integration users, First Alert and Insights Hub. Managers and integration users end up with exactly the lines; any other number on their mapping is removed. `dry_run=True` returns the changes only. |
154
+ | `offboard_customer(customer, deactivate_company=True)` | A customer leaves: pauses the After Call webhook, clears the First Alert webhook, stops the connector, deactivates the integration users, then deactivates the company. Safe to run again. |
155
+
156
+ To keep a user out of every workflow (for example a person you manage by hand), list them in `customer.exclude_user_ids` or `customer.exclude_emails`.
157
+
158
+ Number mappings need an **active** connector. When a mapping is refused, the workflow raises `ExtensionMappingError` with `user_id` set: the user exists but has not been invited, and you run the workflow again once the connector is active. The re-run finds the user, finishes the setup and emails the invitation. A re-run also re-sends the invitation to any user who has not accepted one yet. An extension can belong to one location only: a conflict raises `ConflictError` with the message "Extension is already monitored at another location." and the clashing numbers in `.extensions`.
159
+
160
+ ## Quick start: conversation intelligence (frontline)
161
+
162
+ ```python
163
+ from datetime import datetime, timedelta, timezone
164
+ from intelligence_cloud import Client
165
+
166
+ data = Client(email=..., password=...)
167
+ since = datetime.now(timezone.utc) - timedelta(days=1)
168
+
169
+ for call in data.intelligence.iter_calls(date_from=since, sentiment="negative"):
170
+ detail = data.intelligence.get_call(call["id"])
171
+ transcript = data.intelligence.get_transcript(call["id"])
172
+
173
+ for alert in data.intelligence.iter_alerts(alert_name="Upset Customer", date_from=since):
174
+ print(alert["id"], alert["call_id"])
175
+ ```
176
+
177
+ - `phone` and `text` both search the one search field (names, numbers, summary and transcript text). Pass one or the other.
178
+ - Without `date_from`, calls and alerts start at 00:00 UTC seven days ago.
179
+ - Dates accept time-zone-aware `datetime` objects or full RFC 3339 strings and are sent in UTC. A date alone (`2026-11-01`) and a `datetime` without a time zone are refused: use `2026-11-01T00:00:00Z` or `datetime.now(timezone.utc)`.
180
+ - `alert_name` is the exact, case-sensitive rule name.
181
+ - Calls and alerts as they happen arrive on the After Call and First Alert [webhooks](#webhooks). Don't poll the API for new data: read it when a person asks for something or when a webhook tells you to fetch details, and run scheduled jobs (exports, digests) at most once a day over a bounded date window.
182
+
183
+ ### Recordings
184
+
185
+ ```python
186
+ link = data.intelligence.get_recording_url(call_id)
187
+ if link:
188
+ audio = httpx.get(link.url) # WAV; no Authorization header; Range requests work
189
+ ```
190
+
191
+ The link is signed and valid for 120 minutes (`link.expires_at`). Anyone with the link can download the audio: treat it as a secret, never log it, and fetch a new one when it expires. Returns `None` when the call has no recording.
192
+
193
+ ## Method list
194
+
195
+ Every API operation is a method named after its `operationId` in snake case, grouped by reference section. Path ids are positional; filters are keyword arguments; request bodies are a `dict` with the field names from the reference.
196
+
197
+ - List methods return a `Page` (`items`, `next_cursor`, `has_more`, `total`, `raw`). `items` holds the records with the `type`/`attributes` wrapper removed.
198
+ - Each list method has an `iter_*` twin that follows cursors 100 at a time.
199
+ - Single reads and writes return the response body as documented (`intelligence_cloud.unwrap(body)` returns the record inside).
200
+
201
+ | Namespace | Methods |
202
+ |---|---|
203
+ | `client.resellers` | `get_reseller_branding`, `update_reseller_branding`, `get_reseller_smtp_settings`, `save_reseller_smtp_settings`, `delete_reseller_smtp_settings` |
204
+ | `client.companies` | `list_companies` / `iter_companies`, `create_company`, `get_companies_mfa_summary`, `get_company`, `update_company`, `deactivate_company`, `reactivate_company`, `get_company_branding`, `update_company_branding`; helpers `add_products`, `remove_products`, `find_company`, `find_companies` |
205
+ | `client.sso` | `list_company_domains`, `claim_company_domain`, `remove_company_domain`, `list_domain_verifications`, `verify_domain`, `get_identity_provider`, `connect_identity_provider`, `disconnect_identity_provider`, `test_identity_provider` |
206
+ | `client.products` | `list_products`, `list_company_products`, `list_user_products`, `enable_user_product`, `disable_user_product` |
207
+ | `client.locations` | `list_verticals`, `list_company_locations` / `iter_company_locations`, `create_location`, `get_location`, `update_location`, `deactivate_location`, `reactivate_location`; helpers `add_products`, `remove_products`, `find_location` |
208
+ | `client.groups` | `list_user_groups` / `iter_user_groups`, `create_user_group`, `get_user_group`, `update_user_group`, `delete_user_group`, `get_user_group_membership`, `set_user_group_membership`; helpers `add_members`, `remove_members`, `add_user_to_groups`, `remove_user_from_groups`, `user_group_ids`, `find_group` |
209
+ | `client.connectors` | `list_connector_types`, `test_connector`, `list_location_connectors` / `iter_location_connectors`, `create_connector`, `get_connector`, `update_connector`, `deactivate_connector`, `reactivate_connector`, `list_company_connectors` / `iter_company_connectors`; helpers `wait_for_status`, `find_connector` |
210
+ | `client.first_alert` | `list_alert_rules` / `iter_alert_rules`, `create_alert_rule`, `get_alert_rule`, `update_alert_rule`, `delete_alert_rule`, `duplicate_alert_rule`, `get_first_alert_config`, `save_first_alert_config`, `test_first_alert_webhook`, `get_alert_notification_preferences`, `set_alert_email_preferences`, `set_alert_digest_preferences`; helpers `add_monitored_numbers`, `remove_monitored_numbers`, `set_monitored_numbers`, `add_rule_groups`, `remove_rule_groups`, `find_rule` |
211
+ | `client.insights_hub` | `get_insights_hub_setup`, `save_insights_hub_setup`, `update_insights_hub_setup`, `get_insights_hub_config`, `update_insights_hub_config`, `get_user_insights_hub_access`; helpers `add_numbers`, `remove_numbers`, `set_numbers`, `add_groups`, `remove_groups` |
212
+ | `client.users` | `list_company_users` / `iter_company_users`, `create_company_user`, `get_company_user`, `update_company_user`, `deactivate_company_user`, `reactivate_company_user`, `resend_invitation`, `reset_password`, `get_user_number_mappings`, `set_user_number_mappings`, `list_location_users` / `iter_location_users`, `get_location_user`; helpers `find_user_by_email`, `add_locations`, `remove_locations`, `user_numbers`, `add_numbers`, `remove_numbers`, `set_numbers` |
213
+ | `client.after_call_settings` | `get_user_after_call_settings`, `update_user_after_call_settings` |
214
+ | `client.account` | `get_me`, `list_visible_locations` / `iter_visible_locations` |
215
+ | `client.calls` | `list_calls` / `iter_calls`, `get_call`, `get_call_transcript` |
216
+ | `client.alerts` | `list_alerts` / `iter_alerts`, `get_alerts_dashboard` |
217
+ | `client.tasks` | `list_tasks` / `iter_tasks` |
218
+ | `client.insights` | `get_insights_dashboard`, `list_topic_calls` / `iter_topic_calls` |
219
+ | `client.webhooks` | `get_after_call_webhook`, `save_after_call_webhook`, `test_after_call_webhook` |
220
+ | `client.intelligence` | `whoami`, `require_frontline`, `search_calls` / `iter_calls`, `get_call`, `get_transcript`, `get_recording_url`, `search_alerts` / `iter_alerts`, `get_alert(alert_id, with_call=False)`, `get_alerts_dashboard`, `list_tasks` / `iter_tasks`, `get_insights_dashboard`, `list_topic_calls` / `iter_topic_calls`, `get_after_call_webhook`, `set_after_call_webhook`, `test_after_call_webhook`, `get_first_alert_webhook`, `set_first_alert_webhook`, `test_first_alert_webhook` |
221
+ | `client.workflows` | see "Seat workflows" |
222
+ | `client` | `login`, `logout`, `close` |
223
+
224
+ Module level: `parse_after_call_event`, `UnknownEvent`, `MAX_EVENT_BYTES`, `Deduplicator`, `FileTokenStore`, `unwrap`, `Page`, the error classes and the spec dataclasses.
225
+
226
+ ### Rules the SDK applies for you
227
+
228
+ - **Filters:** list methods accept only the filters the API supports. The API ignores unknown parameters silently, so the SDK refuses them before sending (`TypeError` for an unknown keyword, `InvalidRequestError` for a bad value). Enums are checked; `numbers` takes up to 25 entries and strips `+`, `-`, spaces and brackets, and sends a North American number as its last 10 digits (`+1 555-555-0142` becomes `5555550142`, which also matches records stored without the 1); `location_id` lists take up to 50 ids.
229
+ - **Full-replacement writes** (group members, a user's groups, number mappings, First Alert monitored numbers, Insights Hub numbers and groups, company and location products, rule groups) have `add_*` / `remove_*` helpers that read, merge and write. The First Alert helpers always resend the webhook URL so it is not cleared.
230
+ - **User create** always sends an `Idempotency-Key` (reused on retries). If the create returns 422 but left the user behind, the SDK finds the user by email and applies `location_ids`.
231
+ - **Connectors:** `create_connector`, `reactivate_connector` and `deactivate_connector` wait for the final status, checking every 10 seconds for up to 10 minutes (`timeout=` in seconds; `wait=False` to return at once). An `error` raises `ConnectorError` with `state_reason`; no final status in time raises `ConnectorTimeoutError`.
232
+ - **Responses** carry only the fields in the published reference. Anything else is dropped. With `Client(keep_unknown_fields=True)` new fields the reference does not list yet are kept on the customer-lifecycle (admin) reads; `get_me`, sign-in and every conversation-data read (calls, transcripts, alerts, tasks, insights) always keep only the documented fields. Either way, the one-time sign-in link a user create can return is never passed through or logged.
233
+ - **Test endpoints** (connector dry run, webhook tests) report only success and the HTTP status.
234
+ - **Retries:** 429 and 5xx are retried up to 3 times with backoff and jitter, honouring `Retry-After` up to 60 seconds. A longer `Retry-After` is not waited out: `RateLimitError` is raised at once with `.retry_after`. 5xx is retried only for reads, updates, deletes and user create, never for other creates.
235
+
236
+ ## Error handling
237
+
238
+ ```python
239
+ from intelligence_cloud import ApiError, NotFoundError, ConflictError, ValidationError
240
+
241
+ try:
242
+ admin.companies.get_company(company_id)
243
+ except NotFoundError:
244
+ ... # also returned for records outside this login's scope
245
+ except ApiError as e:
246
+ log.warning("Intelligence Cloud error %s %s request_id=%s", e.status, e.code, e.request_id)
247
+ ```
248
+
249
+ Log `status`, `code` and `request_id`, not exception text or response bodies. `str(error)` carries only the status, code and request id, plus text the SDK wrote itself (such as "Extension is already monitored at another location."). The server's own text is on `e.message`: it can echo numbers or names from the request, so keep it out of logs.
250
+
251
+ | Error | When |
252
+ |---|---|
253
+ | `ApiError` | Any API error: `status`, `code`, `message`, `request_id` |
254
+ | `AuthError` (401), `PasswordExpiredError` | Sign-in failed, or the token could not be renewed |
255
+ | `NotFoundError` (404) | Not found, or outside what this login can see |
256
+ | `ConflictError` (409) | Duplicate name or email, already active or inactive, extension already monitored (`.extensions`) |
257
+ | `ValidationError` (400, 422) | Malformed request or refused value |
258
+ | `RateLimitError` (429) | Still rate limited after retries (`.retry_after`) |
259
+ | `InvalidRequestError` | Refused by the SDK before sending |
260
+ | `MfaRequiredError` | The integration user's company has MFA on |
261
+ | `FrontlineRequiredError` | Conversation data asked for with an admin login |
262
+ | `ConnectorError`, `ConnectorTimeoutError` | A connector ended in `error`, or did not finish in time |
263
+ | `ExtensionMappingError` | A workflow could not map numbers (`.user_id`, `.cause`) |
264
+ | `WebhookPayloadError` | A webhook body is not JSON, or is a malformed After Call event (answer 400) |
265
+ | `PayloadTooLargeError` | A webhook body is over `max_bytes` (256 KB; answer 413) |
266
+
267
+ All derive from `IntelligenceCloudError`.
268
+
269
+ ## Webhooks
270
+
271
+ Webhooks are how your integration hears about new calls and alerts: the After Call webhook for every call, the First Alert webhook for each alert as it fires. Subscribe to them; don't poll the API for new data.
272
+
273
+ ### Configure (admin)
274
+
275
+ ```python
276
+ admin.intelligence.set_after_call_webhook(location_id, f"https://hooks.example.com/ic/after-call/{path_token}")
277
+ admin.intelligence.test_after_call_webhook(location_id) # WebhookTestResult(success, http_status)
278
+
279
+ admin.intelligence.set_first_alert_webhook(location_id, f"https://hooks.example.com/ic/alerts/{alert_path_token}")
280
+ admin.intelligence.test_first_alert_webhook(location_id)
281
+ ```
282
+
283
+ - The After Call webhook sends **every call at the location**. One URL per location. Pause it with `enabled=False`; there is no delete.
284
+ - The First Alert location webhook is set in the location's First Alert configuration. `set_first_alert_webhook` keeps the monitored numbers.
285
+
286
+ ### Receive
287
+
288
+ - Use HTTPS and put a token of at least 32 random characters in the path, one per location, read from your secret store: `python -c "import secrets; print(secrets.token_urlsafe(32))"`. Compare it in constant time (`hmac.compare_digest` on bytes). Requests are not signed: treat the URL as a secret and keep it out of proxy, load balancer and APM logs.
289
+ - Answer 2xx within 2 seconds and do the work afterwards. Redirects count as failures. Delivery is tried 3 times, then dropped.
290
+ - `parse_after_call_event` refuses bodies over 256 KB (`PayloadTooLargeError`: answer 413) and returns `UnknownEvent` for event types it doesn't handle: answer 2xx and ignore them. Answer 400 only for a body that isn't JSON or a malformed After Call event, and 404 for a wrong token.
291
+ - Treat an event as a notification. Before you write anything from it into another system, read the call with `get_call(event.call.id)` using your frontline integration user; a `NotFoundError` means drop the event.
292
+ - Expect repeats of the same `call.id` (retries, and calls with several legs); a later one can carry newer data. Store events durably before acknowledging, and upsert on `call.id`.
293
+ - To test locally, post the sample event: `curl -X POST http://localhost:8080/ic/after-call/$IC_WEBHOOK_TOKEN -H 'Content-Type: application/json' -d @examples/after-call-sample.json`, or run `python examples/webhook_receiver.py --self-test`.
294
+
295
+ FastAPI:
296
+
297
+ ```python
298
+ import hmac
299
+ import os
300
+
301
+ from fastapi import BackgroundTasks, FastAPI, HTTPException, Request
302
+ from intelligence_cloud import (AfterCallEvent, Deduplicator, PayloadTooLargeError, WebhookPayloadError,
303
+ parse_after_call_event)
304
+
305
+ app = FastAPI()
306
+ dedup = Deduplicator()
307
+ PATH_TOKEN = os.environ["IC_WEBHOOK_TOKEN"] # from your secret store
308
+ if len(PATH_TOKEN) < 32:
309
+ raise SystemExit("IC_WEBHOOK_TOKEN must be at least 32 characters")
310
+
311
+ @app.post("/ic/after-call/{token}")
312
+ async def after_call(token: str, request: Request, background: BackgroundTasks):
313
+ if not hmac.compare_digest(token.encode(), PATH_TOKEN.encode()):
314
+ raise HTTPException(status_code=404)
315
+ try:
316
+ event = parse_after_call_event(await request.body())
317
+ except PayloadTooLargeError:
318
+ raise HTTPException(status_code=413)
319
+ except WebhookPayloadError:
320
+ raise HTTPException(status_code=400)
321
+ if isinstance(event, AfterCallEvent) and not event.is_test and not dedup.is_duplicate(event):
322
+ background.add_task(handle, event.call.id) # read the call with get_call, then upsert on its id
323
+ return {"ok": True}
324
+ ```
325
+
326
+ Flask:
327
+
328
+ ```python
329
+ import hmac
330
+
331
+ from flask import Flask, abort, request
332
+ from intelligence_cloud import AfterCallEvent, PayloadTooLargeError, WebhookPayloadError, parse_after_call_event
333
+
334
+ app = Flask(__name__)
335
+ app.config["MAX_CONTENT_LENGTH"] = 262_144
336
+
337
+ @app.post("/ic/after-call/<token>")
338
+ def after_call(token):
339
+ if not hmac.compare_digest(token.encode(), PATH_TOKEN.encode()):
340
+ abort(404)
341
+ try:
342
+ event = parse_after_call_event(request.get_data())
343
+ except PayloadTooLargeError:
344
+ abort(413)
345
+ except WebhookPayloadError:
346
+ abort(400)
347
+ if isinstance(event, AfterCallEvent) and not event.is_test:
348
+ durable_queue.put_once(event.call.id) # a persistent queue keyed on call.id; process outside the request
349
+ return {"ok": True}
350
+ ```
351
+
352
+ `Deduplicator.is_duplicate(...)` returns True for a repeat (the same name and meaning in all three SDKs: `isDuplicate` in PHP and TypeScript). It keeps the last 10,000 call ids in memory. With several workers, pass a shared `store` whose `add(key)` returns True only for a new key (for example a shared cache's set-if-absent with an expiry). Use it to skip repeat work, not to drop updates: when you keep a copy of the call, upsert on `call.id`.
353
+
354
+ ### Receive First Alert
355
+
356
+ The First Alert webhook posts the alert that fired: the alert id, the rule, the location, the call and the time. Read only the alert id, answer 2xx at once, then fetch the alert and its call with a frontline integration user in Manager Alerts:
357
+
358
+ ```python
359
+ @app.post("/ic/alerts/{token}")
360
+ async def first_alert(token: str, request: Request, background: BackgroundTasks):
361
+ if not hmac.compare_digest(token.encode(), ALERT_TOKEN.encode()): # IC_ALERT_WEBHOOK_TOKEN, 32+ characters
362
+ raise HTTPException(status_code=404)
363
+ alert_id = alert_id_from(await request.body()) # see examples/alert_webhook_receiver.py
364
+ if alert_id is None:
365
+ raise HTTPException(status_code=400)
366
+ if not alert_dedup.is_duplicate(alert_id): # a second Deduplicator, keyed on the alert id
367
+ background.add_task(handle_alert, alert_id)
368
+ return {"ok": True}
369
+
370
+ def handle_alert(alert_id: str):
371
+ alert = data.intelligence.get_alert(alert_id, with_call=True) # None when this login can't see it
372
+ if alert:
373
+ page_on_call_manager(alert["id"], alert["call_id"]) # ids only; never log the summary
374
+ ```
375
+
376
+ If your receiver was unavailable, read the window you missed once and skip alerts you have already handled:
377
+
378
+ ```python
379
+ for alert in data.intelligence.iter_alerts(date_from=went_down - timedelta(minutes=30), date_to=came_back):
380
+ if not alert_dedup.is_duplicate(alert["id"]):
381
+ handle_alert(alert["id"])
382
+ ```
383
+
384
+ Alerts are dated by their call, so start the window 30 minutes before the receiver went down.
385
+
386
+ ## Examples
387
+
388
+ | File | Shows | Credential |
389
+ |---|---|---|
390
+ | `examples/whoami.py` | Sign in and print the role | any |
391
+ | `examples/export_calls.py` | Export yesterday's calls to CSV (ids, dates, sentiment, duration) | frontline |
392
+ | `examples/provision_seat.py` | Provision a Seat customer and add an end user and a manager (dry run unless `--apply`; phrases from the file in `IC_THREAT_PHRASES_FILE`) | admin |
393
+ | `examples/webhook_receiver.py` | A dependency-free After Call webhook receiver: 256 KB cap, a persistent queue keyed on `call.id`, a worker that reads each call (`--self-test` to try it offline) | frontline (worker) |
394
+ | `examples/after-call-sample.json` | A sample After Call event for local tests | none |
395
+ | `examples/alert_webhook_receiver.py` | A dependency-free First Alert webhook receiver that fetches each alert and its call (`--self-test` to try it offline) | frontline |
396
+
397
+ The admin examples read `IC_ADMIN_EMAIL` and `IC_ADMIN_PASSWORD`; the frontline examples read `IC_DATA_EMAIL` and `IC_DATA_PASSWORD`. `whoami.py` uses whichever pair is set.
398
+
399
+ ## Regenerating from the spec
400
+
401
+ `src/intelligence_cloud/_generated.py` and `data/spec.json` are generated from `openapi.yaml` (download it from https://docs.intelligence.cloud/openapi.yaml):
402
+
403
+ ```bash
404
+ uv run --with pyyaml python tools/generate.py openapi.yaml # rewrite both files
405
+ uv run --with pyyaml python tools/generate.py openapi.yaml --check # exit 1 if either is out of date
406
+ ```
407
+
408
+ ## License
409
+
410
+ Intelligence Cloud SDK Licence. Copyright (c) 2026 Creo Solutions, Inc. d/b/a Tresic. Partners, their customers and contractors working for either may use, copy, modify and distribute the SDK solely to access Intelligence Cloud. Use of the API is governed by the Intelligence Cloud API and SDK Terms (https://docs.intelligence.cloud/terms/api) and your agreement with Tresic or your provider. Provided as is. See `LICENSE`.