Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(warehouse-sources): add Aircall Conversation Intelligence tables (#98108)

Tom Owers613c7a96266c
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
index 417769c1b5f7..071e3578cf5f 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/COVERAGE_GAPS_APPENDIX.md
@@ -135,14 +135,14 @@ Note: Airbrake's readable v4 surface is small and coverage is close to complete:
## Aircall — gaps
-Today (6): `calls`, `contacts`, `numbers`, `tags`, `teams`, `users`
+Today (10): `call_evaluations`, `call_sentiments`, `call_topics`, `call_transcriptions`, `calls`, `contacts`, `numbers`, `tags`, `teams`, `users`
Diffed against: <https://developer.aircall.io/api-references/>
-- [ ] `call transcription (GET /v1/calls/{call_id}/transcription)` — the transcript text behind every synced call; unlocks all text analysis (high)
-- [ ] `call sentiments (GET /v1/calls/{call_id}/sentiments)` — Conversation Intelligence sentiment scoring per call, a headline metric (high)
-- [ ] `call topics (GET /v1/calls/{call_id}/topics)` — topic breakdown dimension over calls we already sync (high)
-- [ ] `call evaluations (GET /v1/calls/{call_id}/evaluations)` — QA scorecards per call - the main agent-quality metric (high)
+- [x] `call transcription (GET /v1/calls/{call_id}/transcription)` — the transcript text behind every synced call; unlocks all text analysis (high)
+- [x] `call sentiments (GET /v1/calls/{call_id}/sentiments)` — Conversation Intelligence sentiment scoring per call, a headline metric (high)
+- [x] `call topics (GET /v1/calls/{call_id}/topics)` — topic breakdown dimension over calls we already sync (high)
+- [x] `call evaluations (GET /v1/calls/{call_id}/evaluations)` — QA scorecards per call - the main agent-quality metric (high)
- [ ] `call summary and custom summary result` — generated call summaries joinable to the calls table (medium)
- [ ] `predicted CSAT (GET /v1/calls/{call_id}/predicted_csat)` — per-call satisfaction prediction, a core support KPI (medium)
- [ ] `call action items` — extracted follow-ups per call for outcome tracking (medium)
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/aircall/aircall.py b/products/warehouse_sources/backend/temporal/data_imports/sources/aircall/aircall.py
index 6bf8b2df3da2..89b86e9796c1 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/aircall/aircall.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/aircall/aircall.py
@@ -1,7 +1,8 @@
import logging
import dataclasses
+from collections.abc import Iterable
from datetime import UTC, date, datetime
-from typing import Any, Optional
+from typing import Any, Optional, cast
from urllib.parse import parse_qs, urlencode, urlsplit
from requests import Request, Response
@@ -9,6 +10,7 @@ from requests.auth import HTTPBasicAuth
from products.warehouse_sources.backend.temporal.data_imports.sources.aircall.settings import (
AIRCALL_ENDPOINTS,
+ PAGE_SIZE,
AircallEndpointConfig,
)
from products.warehouse_sources.backend.temporal.data_imports.sources.common.http import make_tracked_session
@@ -16,7 +18,14 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.res
RESTAPIConfig,
rest_api_resource,
)
-from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.paginators import BasePaginator
+from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.fanout import (
+ build_dependent_resource,
+)
+from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.paginators import (
+ BasePaginator,
+ SinglePagePaginator,
+)
+from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.typing import ClientConfig
from products.warehouse_sources.backend.temporal.data_imports.sources.common.resumable import ResumableSourceManager
from products.warehouse_sources.backend.temporal.data_imports.sources.common.source_helpers import validate_via_probe
from products.warehouse_sources.backend.temporal.data_imports.sources.common.typings import SourceResponse
@@ -24,8 +33,6 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.typ
logger = logging.getLogger(__name__)
AIRCALL_BASE_URL = "https://api.aircall.io/v1"
-# Aircall caps list pages at 50 items.
-PAGE_SIZE = 50
# Aircall refuses to serve any record past the 10,000th of a single query and answers with a
# 400. It keeps advertising a `meta.next_page_link` across that boundary, so the link cannot be
# followed blindly: the offset it points at has to be range-checked first.
@@ -223,6 +230,66 @@ def validate_credentials(api_id: str, api_token: str) -> bool:
return ok
+def _client_config(api_id: str, api_token: str, paginator: BasePaginator) -> ClientConfig:
+ return {
+ "base_url": AIRCALL_BASE_URL,
+ "headers": {"Accept": "application/json"},
+ # Basic auth via the framework so the token is redacted from logs.
+ "auth": {"type": "http_basic", "username": api_id, "password": api_token},
+ "paginator": paginator,
+ }
+
+
+def _fanout_source(
+ api_id: str,
+ api_token: str,
+ endpoint: str,
+ team_id: int,
+ job_id: str,
+) -> SourceResponse:
+ """Fan a per-call Conversation Intelligence endpoint out over the calls list.
+
+ The parent calls list is re-fetched each sync (there is no incremental filter on the child
+ sub-resource), so the parent keeps the calls paginator to page past the 10k cap and reach
+ every call. The child returns one flat object per call, so it needs a single-page paginator
+ and the whole body as the row — the parent and child therefore run different paginators,
+ set per endpoint rather than on the shared client.
+ """
+ config = AIRCALL_ENDPOINTS[endpoint]
+ assert config.fanout is not None
+ calls_config = AIRCALL_ENDPOINTS[config.fanout.parent_name]
+ parent_paginator = AircallPaginator(calls_config, calls_config.reanchor_field, from_value=None)
+
+ dependent_resource = cast(
+ Iterable[Any],
+ build_dependent_resource(
+ endpoint_configs=AIRCALL_ENDPOINTS,
+ child_endpoint=endpoint,
+ fanout=config.fanout,
+ client_config=_client_config(api_id, api_token, SinglePagePaginator()),
+ path_format_values={},
+ team_id=team_id,
+ job_id=job_id,
+ # The child has no server-side time filter, so this fan-out is always full refresh.
+ db_incremental_field_last_value=None,
+ should_use_incremental_field=False,
+ page_size_param="per_page",
+ parent_endpoint_extra={"paginator": parent_paginator, "data_selector": calls_config.data_key},
+ child_endpoint_extra={"paginator": SinglePagePaginator(), "data_selector": config.data_key},
+ ),
+ )
+
+ return SourceResponse(
+ name=endpoint,
+ items=lambda: dependent_resource,
+ primary_keys=[config.primary_key],
+ # Child rows arrive in the parent's ascending-by-started_at order.
+ sort_mode="asc",
+ partition_count=1,
+ partition_size=1,
+ )
+
+
def aircall_source(
api_id: str,
api_token: str,
@@ -236,6 +303,9 @@ def aircall_source(
) -> SourceResponse:
config = AIRCALL_ENDPOINTS[endpoint]
+ if config.fanout is not None:
+ return _fanout_source(api_id, api_token, endpoint, team_id, job_id)
+
cursor_field = incremental_field or config.reanchor_field
from_value = _to_epoch(db_incremental_field_last_value) if should_use_incremental_field else None
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/aircall/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/aircall/canonical_descriptions.py
index c90389b51396..b21a6e2fbd94 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/aircall/canonical_descriptions.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/aircall/canonical_descriptions.py
@@ -99,4 +99,48 @@ CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {
"description": "Description of what the tag is used for.",
},
},
+ "call_transcriptions": {
+ "description": "The AI-generated transcription of a call, one row per call. Requires the AI Assist add-on.",
+ "docs_url": "https://developer.aircall.io/api-references/#retrieve-a-transcription",
+ "columns": {
+ "call_id": "Identifier of the call this transcription belongs to.",
+ "id": "Unique identifier for the transcription.",
+ "type": "Type of transcription.",
+ "content": "The transcription content, including the detected language and the list of spoken utterances.",
+ "created_at": "Time the transcription was generated, as an ISO 8601 timestamp.",
+ },
+ },
+ "call_sentiments": {
+ "description": "AI-generated sentiment analysis for a call, scored per participant, one row per call. Requires the AI Assist add-on.",
+ "docs_url": "https://developer.aircall.io/api-references/#retrieve-sentiments",
+ "columns": {
+ "call_id": "Identifier of the call this sentiment belongs to.",
+ "id": "Unique identifier for the sentiment record.",
+ "content": "Sentiment value per participant (for example positive, neutral, or negative).",
+ "created_at": "Time the sentiment was generated, as an ISO 8601 timestamp.",
+ },
+ },
+ "call_topics": {
+ "description": "AI-extracted key topics discussed on a call, one row per call. Requires the AI Assist add-on.",
+ "docs_url": "https://developer.aircall.io/api-references/#retrieve-topics",
+ "columns": {
+ "call_id": "Identifier of the call these topics belong to.",
+ "id": "Unique identifier for the topics record.",
+ "content": "The topics extracted from the call, as an array of topic strings.",
+ "created_at": "Time the topics were generated, as an ISO 8601 timestamp.",
+ },
+ },
+ "call_evaluations": {
+ "description": "QA scorecard evaluations submitted for a call, one row per call. Requires the AI Assist add-on.",
+ "docs_url": "https://developer.aircall.io/api-references/#retrieve-call-evaluations",
+ "columns": {
+ "call_id": "Identifier of the call this evaluation belongs to.",
+ "id": "Unique identifier for the evaluation.",
+ "ai_generated": "Whether the evaluation was generated by AI.",
+ "evaluations": "The list of scorecard evaluations, each with its score, categories, and questions.",
+ "reviewed_at": "Time the evaluation was reviewed, as an ISO 8601 timestamp.",
+ "created_at": "Time the evaluation was created, as an ISO 8601 timestamp.",
+ "updated_at": "Time the evaluation was last updated, as an ISO 8601 timestamp.",
+ },
+ },
}
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/aircall/settings.py b/products/warehouse_sources/backend/temporal/data_imports/sources/aircall/settings.py
index 37261c51109b..994c0361ec28 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/aircall/settings.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/aircall/settings.py
@@ -1,14 +1,24 @@
from dataclasses import dataclass, field
from typing import Optional
+from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.fanout import (
+ DependentEndpointConfig,
+)
+from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.typing import ResponseAction
from products.warehouse_sources.backend.types import IncrementalField, IncrementalFieldType
+# Aircall caps list pages at 50 items.
+PAGE_SIZE = 50
-@dataclass
+
+# frozen=False: the shared FanoutEndpointLike protocol declares mutable attributes, which a
+# frozen dataclass cannot satisfy. The instances are treated as immutable by convention.
+@dataclass(frozen=False)
class AircallEndpointConfig:
name: str
path: str
- # Key the list of objects is nested under in the response body (e.g. {"calls": [...]}).
+ # For a list endpoint, the key the objects are nested under (e.g. {"calls": [...]}). For a
+ # per-call Conversation Intelligence sub-resource, "$" — the whole body is the single row.
data_key: str
primary_key: str = "id"
incremental_fields: list[IncrementalField] = field(default_factory=list)
@@ -20,6 +30,30 @@ class AircallEndpointConfig:
# calls/contacts. Must be the same stable creation-time field the API's `from` filter
# applies to.
reanchor_field: Optional[str] = None
+ page_size: int = PAGE_SIZE
+ # Unused by the full-refresh CI children; kept so the config satisfies FanoutEndpointLike.
+ default_incremental_field: Optional[str] = None
+ fanout: Optional[DependentEndpointConfig] = None
+
+
+# The Conversation Intelligence sub-resources (transcription, sentiments, topics, evaluations)
+# are all fetched per call, so they fan out over the calls list. The fan-out shape is identical
+# for every one — only the path and table name differ — so a single shared config drives them.
+# A call with no AI data (or a call deleted between the parent listing and this fetch) answers
+# 404; ignoring it keeps the fan-out going instead of failing the whole table.
+_CI_404_IGNORE: list[ResponseAction] = [{"status_code": 404, "action": "ignore"}]
+_CALL_CI_FANOUT = DependentEndpointConfig(
+ parent_name="calls",
+ resolve_param="call_id",
+ resolve_field="id",
+ # Inject the parent call's id as `call_id` so the primary key is always present and unique
+ # (one CI object per call), regardless of what the sub-resource body itself carries.
+ include_from_parent=["id"],
+ parent_field_renames={"id": "call_id"},
+ # Walk the parent calls list ascending so its paginator can page past Aircall's 10k cap.
+ parent_params={"order": "asc"},
+ child_response_actions=_CI_404_IGNORE,
+)
# Aircall timestamps are UNIX epoch seconds, so candidate incremental fields are stored as
@@ -80,6 +114,38 @@ AIRCALL_ENDPOINTS: dict[str, AircallEndpointConfig] = {
path="/tags",
data_key="tags",
),
+ # Conversation Intelligence sub-resources, one object per call, fanned out over calls. Each
+ # returns a flat per-call object, so "$" selects the whole body as the single row. These need
+ # the AI Assist add-on on the account; without it every fetch is denied, which surfaces as an
+ # auth error rather than an empty table.
+ "call_transcriptions": AircallEndpointConfig(
+ name="call_transcriptions",
+ path="/calls/{call_id}/transcription",
+ data_key="$",
+ primary_key="call_id",
+ fanout=_CALL_CI_FANOUT,
+ ),
+ "call_sentiments": AircallEndpointConfig(
+ name="call_sentiments",
+ path="/calls/{call_id}/sentiments",
+ data_key="$",
+ primary_key="call_id",
+ fanout=_CALL_CI_FANOUT,
+ ),
+ "call_topics": AircallEndpointConfig(
+ name="call_topics",
+ path="/calls/{call_id}/topics",
+ data_key="$",
+ primary_key="call_id",
+ fanout=_CALL_CI_FANOUT,
+ ),
+ "call_evaluations": AircallEndpointConfig(
+ name="call_evaluations",
+ path="/calls/{call_id}/evaluations",
+ data_key="$",
+ primary_key="call_id",
+ fanout=_CALL_CI_FANOUT,
+ ),
}
ENDPOINTS = tuple(AIRCALL_ENDPOINTS.keys())
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/aircall/tests/test_aircall.py b/products/warehouse_sources/backend/temporal/data_imports/sources/aircall/tests/test_aircall.py
index 74bd3d72e8c7..9dd50982275a 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/sources/aircall/tests/test_aircall.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/aircall/tests/test_aircall.py
@@ -38,6 +38,13 @@ def _response(items_key: str, items: list[dict[str, Any]], next_link: str | None
return resp
+def _plain_response(status_code: int, body: dict[str, Any]) -> Response:
+ resp = Response()
+ resp.status_code = status_code
+ resp._content = json.dumps(body).encode()
+ return resp
+
+
def _make_manager(resume_state: AircallResumeConfig | None = None) -> mock.MagicMock:
manager = mock.MagicMock()
manager.can_resume.return_value = resume_state is not None
@@ -347,6 +354,52 @@ class TestPagination:
assert len(requests_seen) == 1
+class TestConversationIntelligenceFanout:
+ @mock.patch(CLIENT_SESSION_PATCH)
+ def test_child_rows_carry_call_id_from_parent(self, MockSession):
+ # The per-call sub-resource is fanned out over the calls list. Each child row must carry
+ # the parent call id as `call_id` (the primary key), overriding whatever the body itself
+ # holds, so one CI object per call stays uniquely keyed.
+ session = MockSession.return_value
+ requests_seen = _wire(
+ session,
+ [
+ _response("calls", [{"id": 1, "started_at": 100}, {"id": 2, "started_at": 200}], None),
+ _plain_response(200, {"id": 55, "content": "hi", "call_id": 999}),
+ _plain_response(200, {"id": 66, "content": "yo"}),
+ # The calls paginator re-anchors once the first window ends; an empty window stops it.
+ _response("calls", [], None),
+ ],
+ )
+
+ rows = _rows(_source("call_transcriptions", _make_manager()))
+
+ assert [(row["call_id"], row["id"], row["content"]) for row in rows] == [(1, 55, "hi"), (2, 66, "yo")]
+ child_urls = [req["url"] for req in requests_seen if "transcription" in (req["url"] or "")]
+ assert child_urls == [
+ "https://api.aircall.io/v1/calls/1/transcription",
+ "https://api.aircall.io/v1/calls/2/transcription",
+ ]
+
+ @mock.patch(CLIENT_SESSION_PATCH)
+ def test_calls_without_ci_data_are_skipped(self, MockSession):
+ # A call with no AI data answers 404; that call is skipped rather than sinking the table.
+ session = MockSession.return_value
+ _wire(
+ session,
+ [
+ _response("calls", [{"id": 1, "started_at": 100}, {"id": 2, "started_at": 200}], None),
+ _plain_response(404, {"error": "not found"}),
+ _plain_response(200, {"id": 66, "content": "yo"}),
+ _response("calls", [], None),
+ ],
+ )
+
+ rows = _rows(_source("call_evaluations", _make_manager()))
+
+ assert [row["call_id"] for row in rows] == [2]
+
+
class TestAircallSourceResponse:
@pytest.mark.parametrize("endpoint", list(ENDPOINTS))
@mock.patch(CLIENT_SESSION_PATCH)