dex-connector-intercom 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.
- dex_connector_intercom-0.1.0/.gitignore +16 -0
- dex_connector_intercom-0.1.0/LICENSE +21 -0
- dex_connector_intercom-0.1.0/PKG-INFO +19 -0
- dex_connector_intercom-0.1.0/README.md +7 -0
- dex_connector_intercom-0.1.0/examples/read_conversation/README.md +7 -0
- dex_connector_intercom-0.1.0/examples/read_conversation/__init__.py +3 -0
- dex_connector_intercom-0.1.0/examples/read_conversation/flow.py +69 -0
- dex_connector_intercom-0.1.0/examples/read_conversation/integration_test.py +93 -0
- dex_connector_intercom-0.1.0/examples/read_conversation/main.py +42 -0
- dex_connector_intercom-0.1.0/pyproject.toml +37 -0
- dex_connector_intercom-0.1.0/src/dex_connectors/intercom/__init__.py +30 -0
- dex_connector_intercom-0.1.0/src/dex_connectors/intercom/_generated/__init__.py +2 -0
- dex_connector_intercom-0.1.0/src/dex_connectors/intercom/_generated/config.py +26 -0
- dex_connector_intercom-0.1.0/src/dex_connectors/intercom/_generated/connection.py +164 -0
- dex_connector_intercom-0.1.0/src/dex_connectors/intercom/_generated/definitions.py +112 -0
- dex_connector_intercom-0.1.0/src/dex_connectors/intercom/_generated/mock.py +308 -0
- dex_connector_intercom-0.1.0/src/dex_connectors/intercom/_generated/models.py +369 -0
- dex_connector_intercom-0.1.0/src/dex_connectors/intercom/_generated/steps.py +296 -0
- dex_connector_intercom-0.1.0/src/dex_connectors/intercom/_generated/timestamps.py +60 -0
- dex_connector_intercom-0.1.0/src/dex_connectors/intercom/client.py +351 -0
- dex_connector_intercom-0.1.0/src/dex_connectors/intercom/connection.py +12 -0
- dex_connector_intercom-0.1.0/src/dex_connectors/intercom/dex-connector.json +201 -0
- dex_connector_intercom-0.1.0/src/dex_connectors/intercom/intercommock/__init__.py +6 -0
- dex_connector_intercom-0.1.0/src/dex_connectors/intercom/models.py +5 -0
- dex_connector_intercom-0.1.0/src/dex_connectors/intercom/operations.py +1093 -0
- dex_connector_intercom-0.1.0/src/dex_connectors/intercom/py.typed +0 -0
- dex_connector_intercom-0.1.0/src/dex_connectors/intercom/steps.py +5 -0
- dex_connector_intercom-0.1.0/tests/test_conformance.py +46 -0
- dex_connector_intercom-0.1.0/tests/test_validation.py +119 -0
- dex_connector_intercom-0.1.0/uv.lock +932 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
.DS_Store
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
node_modules/
|
|
5
|
+
dist/
|
|
6
|
+
sdkpython/dist/dex_connectors_sdk-0.1.0-py3-none-any.whl
|
|
7
|
+
/.bin/dexcli
|
|
8
|
+
/.bin/dex-server-zd
|
|
9
|
+
/sdkpython/.dexcli-data/
|
|
10
|
+
site/.catalog.yaml
|
|
11
|
+
coverage/
|
|
12
|
+
*.out
|
|
13
|
+
*.test
|
|
14
|
+
go.work
|
|
15
|
+
go.work.sum
|
|
16
|
+
.idea/
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Super Durable
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: dex-connector-intercom
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Intercom connector for Dex Flows
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Requires-Python: >=3.11
|
|
8
|
+
Requires-Dist: dex-connectors-sdk==0.1.0
|
|
9
|
+
Requires-Dist: dex-python-sdk>=1.28.0
|
|
10
|
+
Requires-Dist: httpx>=0.27
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
|
|
13
|
+
# Intercom Python connector
|
|
14
|
+
|
|
15
|
+
Dex Python operations for searching and reading Intercom conversations, replying as an admin, changing conversation state, and finding contacts by email. The package uses the static connection name declared in each application and resolves the current access token for each operation attempt.
|
|
16
|
+
|
|
17
|
+
The `examples/read_conversation/` application shows a runnable Dex Flow. The `intercommock` package contains generated outcomes for deterministic application tests.
|
|
18
|
+
|
|
19
|
+
Live provider authorization and behavior remain unverified.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Intercom Python connector
|
|
2
|
+
|
|
3
|
+
Dex Python operations for searching and reading Intercom conversations, replying as an admin, changing conversation state, and finding contacts by email. The package uses the static connection name declared in each application and resolves the current access token for each operation attempt.
|
|
4
|
+
|
|
5
|
+
The `examples/read_conversation/` application shows a runnable Dex Flow. The `intercommock` package contains generated outcomes for deterministic application tests.
|
|
6
|
+
|
|
7
|
+
Live provider authorization and behavior remain unverified.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Read a conversation
|
|
2
|
+
|
|
3
|
+
This example starts one Dex Flow with a conversation ID, reads the latest parts, and saves the result. Its static Dex Web connection name is `intercom-support-inbox`.
|
|
4
|
+
|
|
5
|
+
From `connectors/intercom/python`, run `uv sync`. Start `dexcli dev -dex-port 37301 -web-port 37302 -open=false` in another terminal, then set `DEX_FLOW_SERVICE_ADDRESS=127.0.0.1:37301`. Configure the `intercom-support-inbox` connection in Dex Web using the connector's authorization guide, and run `uv run python -m examples.read_conversation.main`.
|
|
6
|
+
|
|
7
|
+
To exercise the same Flow against a fake provider through a real Dex Worker and Client, run `DEX_FLOW_SERVICE_ADDRESS=127.0.0.1:37301 uv run pytest examples/read_conversation/integration_test.py`. The test sends a rate limit response followed by a successful conversation read. Live Intercom authorization and API behavior remain unverified.
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""Durable read of one Intercom conversation and its latest parts."""
|
|
4
|
+
|
|
5
|
+
import dex
|
|
6
|
+
from dex_connectors.sdk import QueryResult
|
|
7
|
+
|
|
8
|
+
from dex_connectors.intercom import (
|
|
9
|
+
Connection,
|
|
10
|
+
ConversationDetails,
|
|
11
|
+
GetConversationInput,
|
|
12
|
+
new_get_conversation_step,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
CONNECTION_NAME = "intercom-support-inbox"
|
|
16
|
+
FLOW_TYPE = "IntercomReadConversationPython"
|
|
17
|
+
_DETAILS = dex.Attribute("intercom-read-conversation-details", ConversationDetails)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
# dex:group group-id:intercom-read group-label:"Intercom conversation"
|
|
21
|
+
# dex:explanation text:"Save the retrieved Intercom conversation and complete the Flow."
|
|
22
|
+
class ConversationFound(dex.Step[QueryResult[ConversationDetails]]):
|
|
23
|
+
"""Persist the result for Dex Web and finish the Flow."""
|
|
24
|
+
|
|
25
|
+
def get_step_type(self) -> str:
|
|
26
|
+
"""Return the stable completion Step identity."""
|
|
27
|
+
return "ConversationFound"
|
|
28
|
+
|
|
29
|
+
def execute(self, context: dex.Context, input: QueryResult[ConversationDetails]) -> dex.StepDecision:
|
|
30
|
+
"""Save the selected conversation and complete."""
|
|
31
|
+
_DETAILS.set(context, input.value)
|
|
32
|
+
return dex.graceful_complete(input.value)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class ReadConversationFlow(dex.Flow[GetConversationInput]):
|
|
36
|
+
"""Read a conversation through the static Intercom connection."""
|
|
37
|
+
|
|
38
|
+
def __init__(self, connection: Connection) -> None:
|
|
39
|
+
"""Bind a named Intercom connection for Worker registration."""
|
|
40
|
+
if connection.reference.name != CONNECTION_NAME:
|
|
41
|
+
raise ValueError("read conversation requires the static Intercom connection")
|
|
42
|
+
self.found = ConversationFound()
|
|
43
|
+
# dex:group group-id:intercom-read group-label:"Intercom conversation"
|
|
44
|
+
# dex:explanation text:"Read one conversation and its newest parts from Intercom."
|
|
45
|
+
self.read = new_get_conversation_step(
|
|
46
|
+
step_type="GetConversation",
|
|
47
|
+
step_input_type=GetConversationInput,
|
|
48
|
+
annotations={
|
|
49
|
+
"groupId": "intercom-read",
|
|
50
|
+
"groupLabel": "Intercom conversation",
|
|
51
|
+
"explanation": "Read one conversation and its newest parts from Intercom.",
|
|
52
|
+
},
|
|
53
|
+
connection=connection,
|
|
54
|
+
connection_name=CONNECTION_NAME,
|
|
55
|
+
map_to_operation_input=lambda request: request,
|
|
56
|
+
found=self.found,
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
def get_flow_type(self) -> str:
|
|
60
|
+
"""Return the stable Dex Flow identity."""
|
|
61
|
+
return FLOW_TYPE
|
|
62
|
+
|
|
63
|
+
def get_steps(self) -> dex.StepList[GetConversationInput]:
|
|
64
|
+
"""Register the provider read and completion Steps."""
|
|
65
|
+
return dex.StepList.start_step(self.read).other_steps(self.found)
|
|
66
|
+
|
|
67
|
+
def get_persistence_schema(self) -> dex.PersistenceSchema:
|
|
68
|
+
"""Register the completed conversation Attribute."""
|
|
69
|
+
return dex.PersistenceSchema.of(_DETAILS)
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""Exercise Intercom Query retry and completion through a real Dex Worker."""
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
import os
|
|
7
|
+
import tempfile
|
|
8
|
+
from datetime import timedelta
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
from uuid import uuid4
|
|
11
|
+
|
|
12
|
+
import dex
|
|
13
|
+
import httpx
|
|
14
|
+
import pytest
|
|
15
|
+
from dex_connectors.sdk import ConnectionRef, SecretString, StaticCredentialProvider
|
|
16
|
+
|
|
17
|
+
from dex_connectors.intercom import (
|
|
18
|
+
Client,
|
|
19
|
+
Config,
|
|
20
|
+
ConversationDetails,
|
|
21
|
+
Credentials,
|
|
22
|
+
GetConversationInput,
|
|
23
|
+
new_connection,
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
from .flow import CONNECTION_NAME, ReadConversationFlow
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@pytest.mark.asyncio
|
|
30
|
+
async def test_read_conversation_retries_in_real_dex() -> None:
|
|
31
|
+
"""Verify one 429 retry and a persisted conversation result."""
|
|
32
|
+
server_address = os.environ["DEX_FLOW_SERVICE_ADDRESS"]
|
|
33
|
+
requests: list[httpx.Request] = []
|
|
34
|
+
|
|
35
|
+
def answer(request: httpx.Request) -> httpx.Response:
|
|
36
|
+
requests.append(request)
|
|
37
|
+
if len(requests) == 1:
|
|
38
|
+
return httpx.Response(429, headers={"Retry-After": "1"})
|
|
39
|
+
return httpx.Response(
|
|
40
|
+
200,
|
|
41
|
+
json={
|
|
42
|
+
"type": "conversation",
|
|
43
|
+
"id": "2002",
|
|
44
|
+
"state": "open",
|
|
45
|
+
"open": True,
|
|
46
|
+
"created_at": 1793008800,
|
|
47
|
+
"updated_at": 1793008800,
|
|
48
|
+
"source": {
|
|
49
|
+
"type": "conversation",
|
|
50
|
+
"body": "Please help",
|
|
51
|
+
"author": {"type": "user", "id": "contact-1"},
|
|
52
|
+
},
|
|
53
|
+
"conversation_parts": {"conversation_parts": [], "total_count": 0},
|
|
54
|
+
},
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
reference = ConnectionRef("intercom", CONNECTION_NAME)
|
|
58
|
+
async with httpx.AsyncClient(transport=httpx.MockTransport(answer)) as provider_http_client:
|
|
59
|
+
client = Client(
|
|
60
|
+
Config(),
|
|
61
|
+
StaticCredentialProvider(
|
|
62
|
+
{reference: Credentials(SecretString("intercom-inert-token"), SecretString(""))}
|
|
63
|
+
),
|
|
64
|
+
provider_http_client,
|
|
65
|
+
endpoint="http://127.0.0.1:37345",
|
|
66
|
+
)
|
|
67
|
+
connection = new_connection(client, reference)
|
|
68
|
+
flow = ReadConversationFlow(connection)
|
|
69
|
+
registry = dex.Registry([flow], allow_async_handlers=True)
|
|
70
|
+
with tempfile.TemporaryDirectory(prefix="dex-intercom-python-") as cache_directory:
|
|
71
|
+
cache = dex.open_blob_cache(dex.BlobCacheConfig(str(Path(cache_directory) / "blobs"), 1 << 24))
|
|
72
|
+
try:
|
|
73
|
+
worker = dex.AsyncWorker(registry, cache, dex.WorkerOptions(server_address=server_address))
|
|
74
|
+
worker_task = asyncio.create_task(worker.start())
|
|
75
|
+
try:
|
|
76
|
+
await worker.wait_pull_registered(timeout=15)
|
|
77
|
+
async with dex.AsyncClient(
|
|
78
|
+
registry, cache, dex.ClientOptions(server_address=server_address)
|
|
79
|
+
) as dex_client:
|
|
80
|
+
flow_id = f"intercom-python-read-{uuid4().hex}"
|
|
81
|
+
await dex_client.start_flow(flow, flow_id, GetConversationInput("2002", 2))
|
|
82
|
+
result = await asyncio.wait_for(
|
|
83
|
+
dex_client.wait_for_flow(flow_id, timedelta(seconds=20)), 30
|
|
84
|
+
)
|
|
85
|
+
assert result.status == dex.FlowStatus.COMPLETED, result.error_message
|
|
86
|
+
details = result.single_output(ConversationDetails)
|
|
87
|
+
assert details.conversation.id == "2002"
|
|
88
|
+
assert len(requests) == 2
|
|
89
|
+
finally:
|
|
90
|
+
await worker.stop()
|
|
91
|
+
await worker_task
|
|
92
|
+
finally:
|
|
93
|
+
cache.close()
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""Run the Intercom read conversation example Worker."""
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
import os
|
|
7
|
+
import tempfile
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
import dex
|
|
11
|
+
from dex_connectors.sdk.projectconfig import load_from_environment
|
|
12
|
+
|
|
13
|
+
from dex_connectors.intercom import new_project_connection
|
|
14
|
+
|
|
15
|
+
from .flow import CONNECTION_NAME, ReadConversationFlow
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
async def main() -> None:
|
|
19
|
+
"""Load the Intercom connection and serve the registered Flow."""
|
|
20
|
+
project = await load_from_environment()
|
|
21
|
+
connection = new_project_connection(project, CONNECTION_NAME)
|
|
22
|
+
cache_directory = os.environ.get(
|
|
23
|
+
"DEX_BLOB_CACHE_DIR", str(Path(tempfile.gettempdir()) / "dex-intercom-python-read-blobs")
|
|
24
|
+
)
|
|
25
|
+
cache = dex.open_blob_cache(dex.BlobCacheConfig(cache_directory, 1 << 30))
|
|
26
|
+
try:
|
|
27
|
+
registry = dex.Registry([ReadConversationFlow(connection)], allow_async_handlers=True)
|
|
28
|
+
worker = dex.AsyncWorker(
|
|
29
|
+
registry,
|
|
30
|
+
cache,
|
|
31
|
+
dex.WorkerOptions(server_address=os.environ.get("DEX_FLOW_SERVICE_ADDRESS", "localhost:8801")),
|
|
32
|
+
)
|
|
33
|
+
async with worker:
|
|
34
|
+
await worker.start()
|
|
35
|
+
finally:
|
|
36
|
+
cache.close()
|
|
37
|
+
await connection.aclose()
|
|
38
|
+
await project.close()
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
if __name__ == "__main__":
|
|
42
|
+
asyncio.run(main())
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.27"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "dex-connector-intercom"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Intercom connector for Dex Flows"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
dependencies = ["dex-connectors-sdk==0.1.0", "dex-python-sdk>=1.28.0", "httpx>=0.27"]
|
|
13
|
+
|
|
14
|
+
[dependency-groups]
|
|
15
|
+
dev = ["pytest>=8", "pytest-asyncio>=0.24", "mypy>=1.13", "ruff>=0.7", "pyyaml>=6", "types-PyYAML>=6"]
|
|
16
|
+
|
|
17
|
+
[tool.hatch.build.targets.wheel]
|
|
18
|
+
packages = ["src/dex_connectors"]
|
|
19
|
+
|
|
20
|
+
[tool.pytest.ini_options]
|
|
21
|
+
testpaths = ["tests"]
|
|
22
|
+
pythonpath = [".", "src"]
|
|
23
|
+
asyncio_mode = "auto"
|
|
24
|
+
asyncio_default_fixture_loop_scope = "function"
|
|
25
|
+
|
|
26
|
+
[tool.mypy]
|
|
27
|
+
python_version = "3.11"
|
|
28
|
+
strict = true
|
|
29
|
+
mypy_path = "src"
|
|
30
|
+
explicit_package_bases = true
|
|
31
|
+
|
|
32
|
+
[tool.ruff]
|
|
33
|
+
target-version = "py311"
|
|
34
|
+
line-length = 110
|
|
35
|
+
|
|
36
|
+
[tool.ruff.lint]
|
|
37
|
+
select = ["E", "F", "I", "UP", "B"]
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""Intercom connector for Dex Flows."""
|
|
4
|
+
|
|
5
|
+
from .client import Client, Config, Credentials
|
|
6
|
+
from .connection import Connection, new_connection, new_connection_with_operations, new_project_connection
|
|
7
|
+
from .models import * # noqa: F403
|
|
8
|
+
from .operations import (
|
|
9
|
+
FindContactByEmailOperation,
|
|
10
|
+
GetConversationOperation,
|
|
11
|
+
ReplyToConversationOperation,
|
|
12
|
+
SearchConversationsOperation,
|
|
13
|
+
UpdateConversationStateOperation,
|
|
14
|
+
)
|
|
15
|
+
from .steps import * # noqa: F403
|
|
16
|
+
|
|
17
|
+
__all__ = [
|
|
18
|
+
"Client",
|
|
19
|
+
"Config",
|
|
20
|
+
"Credentials",
|
|
21
|
+
"Connection",
|
|
22
|
+
"new_connection",
|
|
23
|
+
"new_connection_with_operations",
|
|
24
|
+
"new_project_connection",
|
|
25
|
+
"SearchConversationsOperation",
|
|
26
|
+
"GetConversationOperation",
|
|
27
|
+
"ReplyToConversationOperation",
|
|
28
|
+
"UpdateConversationStateOperation",
|
|
29
|
+
"FindContactByEmailOperation",
|
|
30
|
+
]
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
# ruff: noqa
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
|
|
7
|
+
from dex_connectors.sdk import SecretString
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@dataclass(frozen=True, slots=True)
|
|
11
|
+
class Config:
|
|
12
|
+
|
|
13
|
+
region: str = "us"
|
|
14
|
+
max_response_bytes: int = 4194304
|
|
15
|
+
webhook_max_body_bytes: int = 2097152
|
|
16
|
+
|
|
17
|
+
setattr(Config, '__module__', 'dex_connectors.intercom.client')
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@dataclass(frozen=True, slots=True)
|
|
21
|
+
class Credentials:
|
|
22
|
+
|
|
23
|
+
access_token: SecretString
|
|
24
|
+
client_secret: SecretString
|
|
25
|
+
|
|
26
|
+
setattr(Credentials, '__module__', 'dex_connectors.intercom.client')
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
# ruff: noqa
|
|
4
|
+
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
import httpx
|
|
8
|
+
from dex_connectors.sdk import ConnectionRef, Mutation, Query, Call, SecretString
|
|
9
|
+
from dex_connectors.sdk.projectconfig import ConnectionKey, LoadedProject
|
|
10
|
+
|
|
11
|
+
from ..client import Client, Config, Credentials
|
|
12
|
+
from .definitions import CONNECTOR_ID, FIND_CONTACT_BY_EMAIL_DEFINITION, GET_CONVERSATION_DEFINITION, REPLY_TO_CONVERSATION_DEFINITION, SEARCH_CONVERSATIONS_DEFINITION, UPDATE_CONVERSATION_STATE_DEFINITION
|
|
13
|
+
from ..models import ConversationDetails, FindContactByEmailInput, FindContactByEmailOutput, GetConversationInput, ReplyToConversationInput, ReplyToConversationOutput, SearchConversationsInput, SearchConversationsOutput, UpdateConversationStateInput, UpdateConversationStateOutput
|
|
14
|
+
|
|
15
|
+
class Connection:
|
|
16
|
+
|
|
17
|
+
__slots__ = ('_search_conversations', '_get_conversation', '_reply_to_conversation', '_update_conversation_state', '_find_contact_by_email', '_client', 'reference')
|
|
18
|
+
|
|
19
|
+
def __init__(self,
|
|
20
|
+
reference: ConnectionRef,
|
|
21
|
+
search_conversations: Query[SearchConversationsInput, SearchConversationsOutput],
|
|
22
|
+
get_conversation: Query[GetConversationInput, ConversationDetails],
|
|
23
|
+
reply_to_conversation: Mutation[ReplyToConversationInput, ReplyToConversationOutput],
|
|
24
|
+
update_conversation_state: Mutation[UpdateConversationStateInput, UpdateConversationStateOutput],
|
|
25
|
+
find_contact_by_email: Query[FindContactByEmailInput, FindContactByEmailOutput],
|
|
26
|
+
client: Client | None = None,
|
|
27
|
+
) -> None:
|
|
28
|
+
reference.validate()
|
|
29
|
+
if reference.provider != CONNECTOR_ID or search_conversations is None or get_conversation is None or reply_to_conversation is None or update_conversation_state is None or find_contact_by_email is None:
|
|
30
|
+
raise ValueError("Intercom connection provider and operations are required")
|
|
31
|
+
if search_conversations.definition().operation != SEARCH_CONVERSATIONS_DEFINITION.operation:
|
|
32
|
+
raise ValueError("Intercom connection operation identity differs")
|
|
33
|
+
if get_conversation.definition().operation != GET_CONVERSATION_DEFINITION.operation:
|
|
34
|
+
raise ValueError("Intercom connection operation identity differs")
|
|
35
|
+
if reply_to_conversation.definition().operation != REPLY_TO_CONVERSATION_DEFINITION.operation:
|
|
36
|
+
raise ValueError("Intercom connection operation identity differs")
|
|
37
|
+
if update_conversation_state.definition().operation != UPDATE_CONVERSATION_STATE_DEFINITION.operation:
|
|
38
|
+
raise ValueError("Intercom connection operation identity differs")
|
|
39
|
+
if find_contact_by_email.definition().operation != FIND_CONTACT_BY_EMAIL_DEFINITION.operation:
|
|
40
|
+
raise ValueError("Intercom connection operation identity differs")
|
|
41
|
+
self.reference = reference
|
|
42
|
+
self._search_conversations = search_conversations
|
|
43
|
+
self._get_conversation = get_conversation
|
|
44
|
+
self._reply_to_conversation = reply_to_conversation
|
|
45
|
+
self._update_conversation_state = update_conversation_state
|
|
46
|
+
self._find_contact_by_email = find_contact_by_email
|
|
47
|
+
self._client = client
|
|
48
|
+
|
|
49
|
+
def search_conversations(self) -> Query[SearchConversationsInput, SearchConversationsOutput]:
|
|
50
|
+
return self._search_conversations
|
|
51
|
+
|
|
52
|
+
def get_conversation(self) -> Query[GetConversationInput, ConversationDetails]:
|
|
53
|
+
return self._get_conversation
|
|
54
|
+
|
|
55
|
+
def reply_to_conversation(self) -> Mutation[ReplyToConversationInput, ReplyToConversationOutput]:
|
|
56
|
+
return self._reply_to_conversation
|
|
57
|
+
|
|
58
|
+
def update_conversation_state(self) -> Mutation[UpdateConversationStateInput, UpdateConversationStateOutput]:
|
|
59
|
+
return self._update_conversation_state
|
|
60
|
+
|
|
61
|
+
def find_contact_by_email(self) -> Query[FindContactByEmailInput, FindContactByEmailOutput]:
|
|
62
|
+
return self._find_contact_by_email
|
|
63
|
+
|
|
64
|
+
async def aclose(self) -> None:
|
|
65
|
+
if self._client is not None:
|
|
66
|
+
await self._client.aclose()
|
|
67
|
+
|
|
68
|
+
def __repr__(self) -> str:
|
|
69
|
+
return "intercom.Connection([REDACTED])"
|
|
70
|
+
|
|
71
|
+
def __reduce__(self) -> tuple[object, ...]:
|
|
72
|
+
raise TypeError("Intercom connections cannot be serialized")
|
|
73
|
+
|
|
74
|
+
setattr(Connection, '__module__', 'dex_connectors.intercom.connection')
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def new_connection(client: Client, reference: ConnectionRef) -> Connection:
|
|
78
|
+
if client is None:
|
|
79
|
+
raise ValueError("Intercom client is required")
|
|
80
|
+
return Connection(reference, client.search_conversations(), client.get_conversation(), client.reply_to_conversation(), client.update_conversation_state(), client.find_contact_by_email(), client)
|
|
81
|
+
|
|
82
|
+
setattr(new_connection, '__module__', 'dex_connectors.intercom.connection')
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def new_connection_with_operations(
|
|
86
|
+
search_conversations: Query[SearchConversationsInput, SearchConversationsOutput],
|
|
87
|
+
get_conversation: Query[GetConversationInput, ConversationDetails],
|
|
88
|
+
reply_to_conversation: Mutation[ReplyToConversationInput, ReplyToConversationOutput],
|
|
89
|
+
update_conversation_state: Mutation[UpdateConversationStateInput, UpdateConversationStateOutput],
|
|
90
|
+
find_contact_by_email: Query[FindContactByEmailInput, FindContactByEmailOutput],
|
|
91
|
+
reference: ConnectionRef,
|
|
92
|
+
) -> Connection:
|
|
93
|
+
return Connection(reference, search_conversations, get_conversation, reply_to_conversation, update_conversation_state, find_contact_by_email)
|
|
94
|
+
|
|
95
|
+
setattr(new_connection_with_operations, '__module__', 'dex_connectors.intercom.connection')
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
class _ProjectCredentialSource:
|
|
99
|
+
|
|
100
|
+
def __init__(self, project: LoadedProject, key: ConnectionKey) -> None:
|
|
101
|
+
self.project = project
|
|
102
|
+
self.key = key
|
|
103
|
+
|
|
104
|
+
async def resolve(self, call: Call) -> Credentials:
|
|
105
|
+
material = await self.project.resolve_credential(self.key, str(call.id))
|
|
106
|
+
if not isinstance(material, dict):
|
|
107
|
+
raise ValueError("Intercom stored credential does not match the connector credential fields")
|
|
108
|
+
if set(material) - set(('access_token', 'client_secret')):
|
|
109
|
+
raise ValueError("Intercom stored credential does not match the connector credential fields")
|
|
110
|
+
access_token = material.get("access_token")
|
|
111
|
+
if access_token is not None and not (isinstance(access_token, str)):
|
|
112
|
+
raise ValueError("Intercom credential access_token has an invalid type")
|
|
113
|
+
client_secret = material.get("client_secret")
|
|
114
|
+
if client_secret is not None and not (isinstance(client_secret, str)):
|
|
115
|
+
raise ValueError("Intercom credential client_secret has an invalid type")
|
|
116
|
+
if not access_token:
|
|
117
|
+
raise ValueError("Intercom credential access_token is required")
|
|
118
|
+
return Credentials(SecretString(access_token), SecretString(client_secret or ''))
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def new_project_connection(
|
|
122
|
+
project: LoadedProject, connection_name: str, http_client: httpx.AsyncClient | None = None
|
|
123
|
+
) -> Connection:
|
|
124
|
+
if project is None:
|
|
125
|
+
raise ValueError("Intercom connection requires loaded project configuration")
|
|
126
|
+
reference = ConnectionRef(CONNECTOR_ID, connection_name)
|
|
127
|
+
reference.validate()
|
|
128
|
+
key = ConnectionKey(CONNECTOR_ID, connection_name)
|
|
129
|
+
matching = [
|
|
130
|
+
entry
|
|
131
|
+
for entry in project.configuration.connections
|
|
132
|
+
if entry.connector_id == CONNECTOR_ID and entry.connection_name == connection_name
|
|
133
|
+
]
|
|
134
|
+
if len(matching) != 1:
|
|
135
|
+
raise ValueError("Intercom project connection is missing or duplicated")
|
|
136
|
+
if matching[0].provider != CONNECTOR_ID:
|
|
137
|
+
raise ValueError("Intercom project connection provider differs")
|
|
138
|
+
config = _decode_config(matching[0].configuration)
|
|
139
|
+
client = Client(config, _ProjectCredentialSource(project, key), http_client)
|
|
140
|
+
return new_connection(client, reference)
|
|
141
|
+
|
|
142
|
+
setattr(new_project_connection, '__module__', 'dex_connectors.intercom.connection')
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def _decode_config(value: dict[str, Any]) -> Config:
|
|
146
|
+
if set(value) - {"region", "maxResponseBytes", "webhookMaxBodyBytes"}:
|
|
147
|
+
raise ValueError("Intercom configuration has unknown fields")
|
|
148
|
+
config_arguments: dict[str, Any] = {}
|
|
149
|
+
if "region" in value and value["region"] != '':
|
|
150
|
+
region = value["region"]
|
|
151
|
+
if not (isinstance(region, str) and region in ('us', 'eu', 'au')):
|
|
152
|
+
raise ValueError("Intercom configuration region has an invalid type")
|
|
153
|
+
config_arguments['region'] = region
|
|
154
|
+
if "maxResponseBytes" in value and value["maxResponseBytes"] != '':
|
|
155
|
+
max_response_bytes = value["maxResponseBytes"]
|
|
156
|
+
if not (type(max_response_bytes) is int):
|
|
157
|
+
raise ValueError("Intercom configuration maxResponseBytes has an invalid type")
|
|
158
|
+
config_arguments['max_response_bytes'] = max_response_bytes
|
|
159
|
+
if "webhookMaxBodyBytes" in value and value["webhookMaxBodyBytes"] != '':
|
|
160
|
+
webhook_max_body_bytes = value["webhookMaxBodyBytes"]
|
|
161
|
+
if not (type(webhook_max_body_bytes) is int):
|
|
162
|
+
raise ValueError("Intercom configuration webhookMaxBodyBytes has an invalid type")
|
|
163
|
+
config_arguments['webhook_max_body_bytes'] = webhook_max_body_bytes
|
|
164
|
+
return Config(**config_arguments)
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
# ruff: noqa
|
|
4
|
+
|
|
5
|
+
from datetime import timedelta
|
|
6
|
+
|
|
7
|
+
from dex_connectors.sdk import (
|
|
8
|
+
BranchDefinition,
|
|
9
|
+
MutationDefinition,
|
|
10
|
+
OperationRef,
|
|
11
|
+
QueryDefinition,
|
|
12
|
+
RetryPolicy,
|
|
13
|
+
StepDefaults,
|
|
14
|
+
default_connector_step_execute_retry_policy,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
CONNECTOR_ID = "intercom"
|
|
18
|
+
PROVIDER = "intercom"
|
|
19
|
+
SEARCH_CONVERSATIONS_OPERATION_ID = "searchConversations"
|
|
20
|
+
GET_CONVERSATION_OPERATION_ID = "getConversation"
|
|
21
|
+
REPLY_TO_CONVERSATION_OPERATION_ID = "replyToConversation"
|
|
22
|
+
UPDATE_CONVERSATION_STATE_OPERATION_ID = "updateConversationState"
|
|
23
|
+
FIND_CONTACT_BY_EMAIL_OPERATION_ID = "findContactByEmail"
|
|
24
|
+
DEFECT = "defect"
|
|
25
|
+
FOUND = "found"
|
|
26
|
+
INVALID_RESPONSE = "invalidResponse"
|
|
27
|
+
NOT_FOUND = "notFound"
|
|
28
|
+
PROVIDER_REJECTED = "providerRejected"
|
|
29
|
+
REPLIED = "replied"
|
|
30
|
+
SEARCHED = "searched"
|
|
31
|
+
UNCERTAIN = "uncertain"
|
|
32
|
+
UPDATED = "updated"
|
|
33
|
+
|
|
34
|
+
SEARCH_CONVERSATIONS_DEFINITION = QueryDefinition(
|
|
35
|
+
OperationRef(CONNECTOR_ID, SEARCH_CONVERSATIONS_OPERATION_ID),
|
|
36
|
+
(
|
|
37
|
+
BranchDefinition(SEARCHED, "One page of matching conversations was returned; it may be empty.", False),
|
|
38
|
+
BranchDefinition(PROVIDER_REJECTED, "Intercom conclusively rejected the search, such as an invalid token, a missing permission, or an invalid cursor.", True),
|
|
39
|
+
BranchDefinition(INVALID_RESPONSE, "Intercom returned an invalid or oversized search page.", True),
|
|
40
|
+
BranchDefinition(DEFECT, "Local input, connection configuration, or connector definition is invalid.", True),
|
|
41
|
+
),
|
|
42
|
+
StepDefaults(
|
|
43
|
+
timedelta(seconds=30),
|
|
44
|
+
2,
|
|
45
|
+
execute_retry=default_connector_step_execute_retry_policy(),
|
|
46
|
+
),
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
GET_CONVERSATION_DEFINITION = QueryDefinition(
|
|
50
|
+
OperationRef(CONNECTOR_ID, GET_CONVERSATION_OPERATION_ID),
|
|
51
|
+
(
|
|
52
|
+
BranchDefinition(FOUND, "The conversation and its latest parts were read.", False),
|
|
53
|
+
BranchDefinition(NOT_FOUND, "The conversation does not exist or is not visible to the connection's token.", True),
|
|
54
|
+
BranchDefinition(PROVIDER_REJECTED, "Intercom conclusively rejected the conversation read.", True),
|
|
55
|
+
BranchDefinition(INVALID_RESPONSE, "Intercom returned an invalid or oversized conversation.", True),
|
|
56
|
+
BranchDefinition(DEFECT, "Local input, connection configuration, or connector definition is invalid.", True),
|
|
57
|
+
),
|
|
58
|
+
StepDefaults(
|
|
59
|
+
timedelta(seconds=30),
|
|
60
|
+
2,
|
|
61
|
+
execute_retry=default_connector_step_execute_retry_policy(),
|
|
62
|
+
),
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
REPLY_TO_CONVERSATION_DEFINITION = MutationDefinition(
|
|
66
|
+
OperationRef(CONNECTOR_ID, REPLY_TO_CONVERSATION_OPERATION_ID),
|
|
67
|
+
(
|
|
68
|
+
BranchDefinition(REPLIED, "The reply or note is in the conversation; a retried attempt that found its own earlier reply reports it instead of sending again.", False),
|
|
69
|
+
BranchDefinition(NOT_FOUND, "The conversation does not exist or is not visible to the connection's token; nothing was added.", True),
|
|
70
|
+
BranchDefinition(PROVIDER_REJECTED, "Intercom conclusively rejected the reply, such as an unknown admin or a closed channel; nothing was added.", True),
|
|
71
|
+
BranchDefinition(UNCERTAIN, "An earlier attempt sent the reply but its outcome cannot be confirmed and the conversation shows no matching part, so the reply may exist; the connector never resends it.", True),
|
|
72
|
+
BranchDefinition(INVALID_RESPONSE, "Intercom accepted the reply but returned an invalid or oversized conversation, so the reply exists.", True),
|
|
73
|
+
BranchDefinition(DEFECT, "Local input, connection configuration, or connector definition is invalid.", True),
|
|
74
|
+
),
|
|
75
|
+
StepDefaults(
|
|
76
|
+
timedelta(seconds=30),
|
|
77
|
+
1,
|
|
78
|
+
execute_retry=RetryPolicy(timedelta(seconds=1), 2, timedelta(seconds=60), 5, timedelta(seconds=300)),
|
|
79
|
+
),
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
UPDATE_CONVERSATION_STATE_DEFINITION = MutationDefinition(
|
|
83
|
+
OperationRef(CONNECTOR_ID, UPDATE_CONVERSATION_STATE_OPERATION_ID),
|
|
84
|
+
(
|
|
85
|
+
BranchDefinition(UPDATED, "The conversation is in the requested state; a repeated attempt that finds it there writes nothing.", False),
|
|
86
|
+
BranchDefinition(NOT_FOUND, "The conversation does not exist or is not visible to the connection's token.", True),
|
|
87
|
+
BranchDefinition(PROVIDER_REJECTED, "Intercom conclusively rejected the change, such as an unknown admin, and the conversation is not in the requested state.", True),
|
|
88
|
+
BranchDefinition(INVALID_RESPONSE, "Intercom returned an invalid or oversized conversation, so the change may have been applied.", True),
|
|
89
|
+
BranchDefinition(DEFECT, "Local input, connection configuration, or connector definition is invalid.", True),
|
|
90
|
+
),
|
|
91
|
+
StepDefaults(
|
|
92
|
+
timedelta(seconds=30),
|
|
93
|
+
2,
|
|
94
|
+
execute_retry=default_connector_step_execute_retry_policy(),
|
|
95
|
+
),
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
FIND_CONTACT_BY_EMAIL_DEFINITION = QueryDefinition(
|
|
99
|
+
OperationRef(CONNECTOR_ID, FIND_CONTACT_BY_EMAIL_OPERATION_ID),
|
|
100
|
+
(
|
|
101
|
+
BranchDefinition(FOUND, "At least one contact has the email address.", False),
|
|
102
|
+
BranchDefinition(NOT_FOUND, "No contact has the email address yet; Intercom can take a few minutes to index a new contact.", True),
|
|
103
|
+
BranchDefinition(PROVIDER_REJECTED, "Intercom conclusively rejected the contact search.", True),
|
|
104
|
+
BranchDefinition(INVALID_RESPONSE, "Intercom returned an invalid or oversized contact page.", True),
|
|
105
|
+
BranchDefinition(DEFECT, "Local input, connection configuration, or connector definition is invalid.", True),
|
|
106
|
+
),
|
|
107
|
+
StepDefaults(
|
|
108
|
+
timedelta(seconds=30),
|
|
109
|
+
2,
|
|
110
|
+
execute_retry=default_connector_step_execute_retry_policy(),
|
|
111
|
+
),
|
|
112
|
+
)
|