dex-connector-microsoft-teams 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_microsoft_teams-0.1.0/.gitignore +16 -0
- dex_connector_microsoft_teams-0.1.0/LICENSE +21 -0
- dex_connector_microsoft_teams-0.1.0/PKG-INFO +17 -0
- dex_connector_microsoft_teams-0.1.0/README.md +5 -0
- dex_connector_microsoft_teams-0.1.0/examples/list_thread_replies/README.md +5 -0
- dex_connector_microsoft_teams-0.1.0/examples/list_thread_replies/__init__.py +3 -0
- dex_connector_microsoft_teams-0.1.0/examples/list_thread_replies/flow.py +77 -0
- dex_connector_microsoft_teams-0.1.0/examples/list_thread_replies/input.example.json +5 -0
- dex_connector_microsoft_teams-0.1.0/examples/list_thread_replies/integration_test.py +122 -0
- dex_connector_microsoft_teams-0.1.0/examples/list_thread_replies/start.py +63 -0
- dex_connector_microsoft_teams-0.1.0/examples/list_thread_replies/worker.py +51 -0
- dex_connector_microsoft_teams-0.1.0/pyproject.toml +38 -0
- dex_connector_microsoft_teams-0.1.0/src/dex_connectors/microsoft_teams/__init__.py +45 -0
- dex_connector_microsoft_teams-0.1.0/src/dex_connectors/microsoft_teams/_generated/__init__.py +2 -0
- dex_connector_microsoft_teams-0.1.0/src/dex_connectors/microsoft_teams/_generated/config.py +28 -0
- dex_connector_microsoft_teams-0.1.0/src/dex_connectors/microsoft_teams/_generated/connection.py +201 -0
- dex_connector_microsoft_teams-0.1.0/src/dex_connectors/microsoft_teams/_generated/definitions.py +90 -0
- dex_connector_microsoft_teams-0.1.0/src/dex_connectors/microsoft_teams/_generated/mock.py +227 -0
- dex_connector_microsoft_teams-0.1.0/src/dex_connectors/microsoft_teams/_generated/models.py +207 -0
- dex_connector_microsoft_teams-0.1.0/src/dex_connectors/microsoft_teams/_generated/refresh.py +9 -0
- dex_connector_microsoft_teams-0.1.0/src/dex_connectors/microsoft_teams/_generated/steps.py +234 -0
- dex_connector_microsoft_teams-0.1.0/src/dex_connectors/microsoft_teams/_generated/timestamps.py +60 -0
- dex_connector_microsoft_teams-0.1.0/src/dex_connectors/microsoft_teams/client.py +492 -0
- dex_connector_microsoft_teams-0.1.0/src/dex_connectors/microsoft_teams/connection.py +8 -0
- dex_connector_microsoft_teams-0.1.0/src/dex_connectors/microsoft_teams/dex-connector.json +148 -0
- dex_connector_microsoft_teams-0.1.0/src/dex_connectors/microsoft_teams/models.py +28 -0
- dex_connector_microsoft_teams-0.1.0/src/dex_connectors/microsoft_teams/operations.py +910 -0
- dex_connector_microsoft_teams-0.1.0/src/dex_connectors/microsoft_teams/refresh.py +8 -0
- dex_connector_microsoft_teams-0.1.0/src/dex_connectors/microsoft_teams/steps.py +8 -0
- dex_connector_microsoft_teams-0.1.0/src/dex_connectors/microsoft_teams/teamsmock/__init__.py +6 -0
- dex_connector_microsoft_teams-0.1.0/tests/refresh_agreement_cases.json +355 -0
- dex_connector_microsoft_teams-0.1.0/tests/test_conformance.py +47 -0
- dex_connector_microsoft_teams-0.1.0/tests/test_encoding.py +114 -0
- dex_connector_microsoft_teams-0.1.0/tests/test_refresh_agreement.py +278 -0
- dex_connector_microsoft_teams-0.1.0/uv.lock +923 -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,17 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: dex-connector-microsoft-teams
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Microsoft Teams connector for Dex Flows
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Requires-Python: >=3.11
|
|
8
|
+
Requires-Dist: dex-connectors-sdk==0.7.0
|
|
9
|
+
Requires-Dist: dex-python-sdk>=1.28.0
|
|
10
|
+
Requires-Dist: httpx>=0.27
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
|
|
13
|
+
# Microsoft Teams Python connector
|
|
14
|
+
|
|
15
|
+
`dex-connector-microsoft-teams==0.1.0` provides the four Microsoft Teams operations for Dex Flows. Configure a named Microsoft Teams connection in Dex Web before running a Flow. Live Microsoft authorization and provider calls have not been verified.
|
|
16
|
+
|
|
17
|
+
Decoded sender IDs and Graph request IDs retain printable values up to 128 bytes; message type, importance, and content type are limited to 64 bytes.
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# Microsoft Teams Python connector
|
|
2
|
+
|
|
3
|
+
`dex-connector-microsoft-teams==0.1.0` provides the four Microsoft Teams operations for Dex Flows. Configure a named Microsoft Teams connection in Dex Web before running a Flow. Live Microsoft authorization and provider calls have not been verified.
|
|
4
|
+
|
|
5
|
+
Decoded sender IDs and Graph request IDs retain printable values up to 128 bytes; message type, importance, and content type are limited to 64 bytes.
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
# Read Microsoft Teams thread replies
|
|
2
|
+
|
|
3
|
+
Create a Dex Web connection named `microsoft-teams-incident` using the [Microsoft Teams authorization guide](../../../README.md). From `python/`, run `uv sync --locked`, start `uv run python -m examples.list_thread_replies.worker`, then run `uv run python -m examples.list_thread_replies.start teams-replies-1 examples/list_thread_replies/input.example.json`. Set `DEX_FLOW_SERVICE_ADDRESS` if Dex uses another port. The Flow stores one bounded reply page in an Attribute. An unwired optional branch fails the Flow.
|
|
4
|
+
|
|
5
|
+
The integration test runs this Flow through a real Dex Worker and Client against a local Graph stand-in. Live Microsoft authorization and Graph calls remain unverified.
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""Read a Teams thread through a Dex Query Step."""
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass, field
|
|
6
|
+
|
|
7
|
+
import dex
|
|
8
|
+
from dex_connectors.sdk import QueryResult
|
|
9
|
+
|
|
10
|
+
from dex_connectors.microsoft_teams import (
|
|
11
|
+
Connection,
|
|
12
|
+
ListThreadRepliesInput,
|
|
13
|
+
ListThreadRepliesOutput,
|
|
14
|
+
new_list_thread_replies_step,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
CONNECTION_NAME = "microsoft-teams-incident"
|
|
18
|
+
FLOW_TYPE = "MicrosoftTeamsListThreadRepliesPython"
|
|
19
|
+
REPLIES = dex.Attribute("microsoft-teams-replies", ListThreadRepliesOutput)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@dataclass(frozen=True, slots=True)
|
|
23
|
+
class ThreadRequest:
|
|
24
|
+
"""Identify one Teams thread and bound its first page."""
|
|
25
|
+
|
|
26
|
+
team_id: str = field(metadata={"dex_json_name": "teamId"})
|
|
27
|
+
channel_id: str = field(metadata={"dex_json_name": "channelId"})
|
|
28
|
+
message_id: str = field(metadata={"dex_json_name": "messageId"})
|
|
29
|
+
|
|
30
|
+
def to_operation_input(self) -> ListThreadRepliesInput:
|
|
31
|
+
"""Request one page of replies from Graph."""
|
|
32
|
+
return ListThreadRepliesInput(self.team_id, self.channel_id, self.message_id)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
# dex:group group-id:teams-replies group-label:"Teams replies"
|
|
36
|
+
# dex:explanation text:"Store one bounded page of Teams replies and complete the Flow."
|
|
37
|
+
class CompleteThreadRead(dex.Step[QueryResult[ListThreadRepliesOutput]]):
|
|
38
|
+
"""Persist the read page for clients of this Flow."""
|
|
39
|
+
|
|
40
|
+
def execute(self, context: dex.Context, input: QueryResult[ListThreadRepliesOutput]) -> dex.StepDecision:
|
|
41
|
+
"""Complete with the provider's reply page."""
|
|
42
|
+
REPLIES.set(context, input.value)
|
|
43
|
+
return dex.graceful_complete(input.value)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class ThreadRepliesFlow(dex.Flow[ThreadRequest]):
|
|
47
|
+
"""Read replies through the static Teams connection."""
|
|
48
|
+
|
|
49
|
+
def __init__(self, connection: Connection) -> None:
|
|
50
|
+
if connection.reference.name != CONNECTION_NAME:
|
|
51
|
+
raise ValueError("Teams replies require the static connection")
|
|
52
|
+
self.complete = CompleteThreadRead()
|
|
53
|
+
self.read = new_list_thread_replies_step(
|
|
54
|
+
step_type="ReadMicrosoftTeamsThreadReplies",
|
|
55
|
+
step_input_type=ThreadRequest,
|
|
56
|
+
annotations={
|
|
57
|
+
"groupId": "teams-replies",
|
|
58
|
+
"groupLabel": "Teams replies",
|
|
59
|
+
"explanation": "Read one bounded page of a Teams thread.",
|
|
60
|
+
},
|
|
61
|
+
connection=connection,
|
|
62
|
+
connection_name=CONNECTION_NAME,
|
|
63
|
+
map_to_operation_input=ThreadRequest.to_operation_input,
|
|
64
|
+
read=self.complete,
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
def get_flow_type(self) -> str:
|
|
68
|
+
"""Return the stable Flow identity."""
|
|
69
|
+
return FLOW_TYPE
|
|
70
|
+
|
|
71
|
+
def get_steps(self) -> dex.StepList[ThreadRequest]:
|
|
72
|
+
"""Register the Teams Query and completion Step."""
|
|
73
|
+
return dex.StepList.start_step(self.read).other_steps(self.complete)
|
|
74
|
+
|
|
75
|
+
def get_persistence_schema(self) -> dex.PersistenceSchema:
|
|
76
|
+
"""Register the reply page Attribute."""
|
|
77
|
+
return dex.PersistenceSchema.of(REPLIES)
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""Exercise the Teams example through a real Dex Worker and Client."""
|
|
4
|
+
|
|
5
|
+
import asyncio
|
|
6
|
+
import json
|
|
7
|
+
import os
|
|
8
|
+
import tempfile
|
|
9
|
+
from datetime import timedelta
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
from uuid import uuid4
|
|
12
|
+
|
|
13
|
+
import dex
|
|
14
|
+
import httpx
|
|
15
|
+
import pytest
|
|
16
|
+
from dex_connectors.sdk.projectconfig import load_from_environment
|
|
17
|
+
|
|
18
|
+
from dex_connectors.microsoft_teams import ListThreadRepliesOutput, new_project_connection
|
|
19
|
+
|
|
20
|
+
from .flow import CONNECTION_NAME, ThreadRepliesFlow, ThreadRequest
|
|
21
|
+
|
|
22
|
+
TEAM_ID = "fbe2bf47-16c8-47cf-b4a5-4b9b187c508b"
|
|
23
|
+
CHANNEL_ID = "19:4a95f7d8db4c4e7fae857bcebe0623e6@thread.tacv2"
|
|
24
|
+
ROOT_ID = "1616989510408"
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@pytest.mark.asyncio
|
|
28
|
+
async def test_thread_read_retries_and_unwired_rejection_through_real_dex(
|
|
29
|
+
monkeypatch: pytest.MonkeyPatch,
|
|
30
|
+
) -> None:
|
|
31
|
+
"""Verify worker registration, retry delivery, persistence, and optional rejection."""
|
|
32
|
+
server_address = os.environ["DEX_FLOW_SERVICE_ADDRESS"]
|
|
33
|
+
graph_requests: list[httpx.Request] = []
|
|
34
|
+
|
|
35
|
+
def answer(request: httpx.Request) -> httpx.Response:
|
|
36
|
+
if request.url.host == "login.microsoftonline.com":
|
|
37
|
+
return httpx.Response(
|
|
38
|
+
200,
|
|
39
|
+
json={
|
|
40
|
+
"access_token": "inert-refreshed-token",
|
|
41
|
+
"refresh_token": "inert-rotated-token",
|
|
42
|
+
"token_type": "Bearer",
|
|
43
|
+
"expires_in": 3600,
|
|
44
|
+
},
|
|
45
|
+
)
|
|
46
|
+
graph_requests.append(request)
|
|
47
|
+
if request.url.path.endswith("/1616989510412/replies"):
|
|
48
|
+
return httpx.Response(404, json={"error": {"code": "NotFound"}})
|
|
49
|
+
if len(graph_requests) == 1:
|
|
50
|
+
return httpx.Response(429, headers={"Retry-After": "1"})
|
|
51
|
+
return httpx.Response(200, json={"value": []})
|
|
52
|
+
|
|
53
|
+
with tempfile.TemporaryDirectory(prefix="teams-python-dex-") as directory:
|
|
54
|
+
connections_path = Path(directory) / "connections.json"
|
|
55
|
+
connections_path.write_text(
|
|
56
|
+
json.dumps(
|
|
57
|
+
{
|
|
58
|
+
"schemaVersion": "connectors.dex.dev/local-connections/v1alpha1",
|
|
59
|
+
"connections": [
|
|
60
|
+
{
|
|
61
|
+
"connectorId": "microsoft-teams",
|
|
62
|
+
"connectionName": CONNECTION_NAME,
|
|
63
|
+
"modulePath": (
|
|
64
|
+
"github.com/superdurable/dex-connectors-library/connectors/microsoft/teams"
|
|
65
|
+
),
|
|
66
|
+
"provider": "microsoft",
|
|
67
|
+
"configuration": {"endpoint": "http://localhost/v1.0"},
|
|
68
|
+
"credentials": {
|
|
69
|
+
"oauth_client_id": "inert-client-id",
|
|
70
|
+
"oauth_client_secret": "inert-client-secret",
|
|
71
|
+
"access_token": "inert-access-token",
|
|
72
|
+
"refresh_token": "inert-refresh-token",
|
|
73
|
+
},
|
|
74
|
+
}
|
|
75
|
+
],
|
|
76
|
+
"triggerBindings": [],
|
|
77
|
+
}
|
|
78
|
+
)
|
|
79
|
+
)
|
|
80
|
+
connections_path.chmod(0o600)
|
|
81
|
+
monkeypatch.setenv("DEX_CONNECTOR_CONFIG_FILE", str(connections_path))
|
|
82
|
+
project = await load_from_environment({"DEX_CONNECTOR_CONFIG_FILE": str(connections_path)})
|
|
83
|
+
async with httpx.AsyncClient(transport=httpx.MockTransport(answer)) as provider_http_client:
|
|
84
|
+
connection = new_project_connection(project, CONNECTION_NAME, provider_http_client)
|
|
85
|
+
flow = ThreadRepliesFlow(connection)
|
|
86
|
+
registry = dex.Registry([flow], allow_async_handlers=True)
|
|
87
|
+
cache = dex.open_blob_cache(dex.BlobCacheConfig(str(Path(directory) / "blobs"), 1 << 24))
|
|
88
|
+
try:
|
|
89
|
+
worker = dex.AsyncWorker(registry, cache, dex.WorkerOptions(server_address=server_address))
|
|
90
|
+
worker_task = asyncio.create_task(worker.start())
|
|
91
|
+
try:
|
|
92
|
+
await worker.wait_pull_registered(timeout=15)
|
|
93
|
+
async with dex.AsyncClient(
|
|
94
|
+
registry, cache, dex.ClientOptions(server_address=server_address)
|
|
95
|
+
) as dex_client:
|
|
96
|
+
flow_id = f"teams-python-list-{uuid4().hex}"
|
|
97
|
+
await dex_client.start_flow(
|
|
98
|
+
flow, flow_id, ThreadRequest(TEAM_ID, CHANNEL_ID, ROOT_ID)
|
|
99
|
+
)
|
|
100
|
+
success = await asyncio.wait_for(
|
|
101
|
+
dex_client.wait_for_flow(flow_id, timedelta(seconds=20)), 30
|
|
102
|
+
)
|
|
103
|
+
assert success.status == dex.FlowStatus.COMPLETED, success.error_message
|
|
104
|
+
assert success.single_output(ListThreadRepliesOutput).replies == ()
|
|
105
|
+
assert len(graph_requests) == 2
|
|
106
|
+
|
|
107
|
+
rejected_id = f"teams-python-list-{uuid4().hex}"
|
|
108
|
+
await dex_client.start_flow(
|
|
109
|
+
flow, rejected_id, ThreadRequest(TEAM_ID, CHANNEL_ID, "1616989510412")
|
|
110
|
+
)
|
|
111
|
+
rejected = await asyncio.wait_for(
|
|
112
|
+
dex_client.wait_for_flow(rejected_id, timedelta(seconds=20)), 30
|
|
113
|
+
)
|
|
114
|
+
assert rejected.status == dex.FlowStatus.FAILED
|
|
115
|
+
assert "notFound" in (rejected.error_message or "")
|
|
116
|
+
finally:
|
|
117
|
+
await worker.stop()
|
|
118
|
+
await worker_task
|
|
119
|
+
finally:
|
|
120
|
+
cache.close()
|
|
121
|
+
await connection.aclose()
|
|
122
|
+
await project.close()
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""Start one Teams thread reply Flow."""
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import asyncio
|
|
7
|
+
import os
|
|
8
|
+
import tempfile
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
import dex
|
|
12
|
+
from dex_connectors.sdk.projectconfig import load_from_environment
|
|
13
|
+
|
|
14
|
+
from dex_connectors.microsoft_teams import new_project_connection
|
|
15
|
+
|
|
16
|
+
from .flow import CONNECTION_NAME, ThreadRepliesFlow, ThreadRequest
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
async def start_thread_read(flow_id: str, input_file: Path) -> str:
|
|
20
|
+
"""Validate one bounded input and start the Flow."""
|
|
21
|
+
with input_file.open("rb") as source:
|
|
22
|
+
encoded = source.read(65_537)
|
|
23
|
+
if len(encoded) > 65_536:
|
|
24
|
+
raise ValueError("Teams input exceeds 65536 bytes")
|
|
25
|
+
input_value = (
|
|
26
|
+
dex.CodecRegistry()
|
|
27
|
+
.resolve(ThreadRequest)
|
|
28
|
+
.decode(dex.Value(dex.WireKind.JSON, encoded.decode("utf-8")))
|
|
29
|
+
)
|
|
30
|
+
project = await load_from_environment()
|
|
31
|
+
connection = new_project_connection(project, CONNECTION_NAME)
|
|
32
|
+
try:
|
|
33
|
+
flow = ThreadRepliesFlow(connection)
|
|
34
|
+
registry = dex.Registry([flow], allow_async_handlers=True)
|
|
35
|
+
with tempfile.TemporaryDirectory(prefix="teams-python-start-blobs-") as cache_directory:
|
|
36
|
+
cache = dex.open_blob_cache(dex.BlobCacheConfig(cache_directory, 1 << 24))
|
|
37
|
+
try:
|
|
38
|
+
async with dex.AsyncClient(
|
|
39
|
+
registry,
|
|
40
|
+
cache,
|
|
41
|
+
dex.ClientOptions(
|
|
42
|
+
server_address=os.environ.get("DEX_FLOW_SERVICE_ADDRESS", "localhost:8801")
|
|
43
|
+
),
|
|
44
|
+
) as client:
|
|
45
|
+
return await client.start_flow(flow, flow_id, input_value)
|
|
46
|
+
finally:
|
|
47
|
+
cache.close()
|
|
48
|
+
finally:
|
|
49
|
+
await connection.aclose()
|
|
50
|
+
await project.close()
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def main() -> None:
|
|
54
|
+
"""Accept a unique Flow ID and JSON input file."""
|
|
55
|
+
parser = argparse.ArgumentParser(description="Read a Microsoft Teams thread")
|
|
56
|
+
parser.add_argument("flow_id")
|
|
57
|
+
parser.add_argument("input_file", type=Path)
|
|
58
|
+
arguments = parser.parse_args()
|
|
59
|
+
print(asyncio.run(start_thread_read(arguments.flow_id, arguments.input_file)))
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
if __name__ == "__main__":
|
|
63
|
+
main()
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""Worker entrypoint for the Teams thread replies example."""
|
|
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.microsoft_teams import new_project_connection
|
|
14
|
+
|
|
15
|
+
from .flow import CONNECTION_NAME, ThreadRepliesFlow
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
async def run_worker() -> None:
|
|
19
|
+
"""Load the static connection and serve reply reads."""
|
|
20
|
+
project = await load_from_environment()
|
|
21
|
+
connection = None
|
|
22
|
+
cache = None
|
|
23
|
+
try:
|
|
24
|
+
connection = new_project_connection(project, CONNECTION_NAME)
|
|
25
|
+
registry = dex.Registry([ThreadRepliesFlow(connection)], allow_async_handlers=True)
|
|
26
|
+
cache_directory = os.environ.get(
|
|
27
|
+
"DEX_BLOB_CACHE_DIR", str(Path(tempfile.gettempdir()) / "dex-teams-replies-blobs")
|
|
28
|
+
)
|
|
29
|
+
cache = dex.open_blob_cache(dex.BlobCacheConfig(cache_directory, 1 << 30))
|
|
30
|
+
worker = dex.AsyncWorker(
|
|
31
|
+
registry,
|
|
32
|
+
cache,
|
|
33
|
+
dex.WorkerOptions(server_address=os.environ.get("DEX_FLOW_SERVICE_ADDRESS", "localhost:8801")),
|
|
34
|
+
)
|
|
35
|
+
async with worker:
|
|
36
|
+
await worker.start()
|
|
37
|
+
finally:
|
|
38
|
+
if connection is not None:
|
|
39
|
+
await connection.aclose()
|
|
40
|
+
if cache is not None:
|
|
41
|
+
cache.close()
|
|
42
|
+
await project.close()
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def main() -> None:
|
|
46
|
+
"""Run the Worker until stopped."""
|
|
47
|
+
asyncio.run(run_worker())
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
if __name__ == "__main__":
|
|
51
|
+
main()
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.27"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "dex-connector-microsoft-teams"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Microsoft Teams connector for Dex Flows"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE"]
|
|
13
|
+
dependencies = ["dex-connectors-sdk==0.7.0", "dex-python-sdk>=1.28.0", "httpx>=0.27"]
|
|
14
|
+
|
|
15
|
+
[dependency-groups]
|
|
16
|
+
dev = ["pytest>=8", "pytest-asyncio>=0.24", "mypy>=1.13", "ruff>=0.7", "pyyaml>=6"]
|
|
17
|
+
|
|
18
|
+
[tool.hatch.build.targets.wheel]
|
|
19
|
+
packages = ["src/dex_connectors"]
|
|
20
|
+
|
|
21
|
+
[tool.pytest.ini_options]
|
|
22
|
+
testpaths = ["tests"]
|
|
23
|
+
pythonpath = [".", "src"]
|
|
24
|
+
asyncio_mode = "auto"
|
|
25
|
+
asyncio_default_fixture_loop_scope = "function"
|
|
26
|
+
|
|
27
|
+
[tool.mypy]
|
|
28
|
+
python_version = "3.11"
|
|
29
|
+
strict = true
|
|
30
|
+
mypy_path = "src"
|
|
31
|
+
explicit_package_bases = true
|
|
32
|
+
|
|
33
|
+
[tool.ruff]
|
|
34
|
+
target-version = "py311"
|
|
35
|
+
line-length = 110
|
|
36
|
+
|
|
37
|
+
[tool.ruff.lint]
|
|
38
|
+
select = ["E", "F", "I", "UP", "B"]
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable
|
|
2
|
+
# SPDX-License-Identifier: MIT
|
|
3
|
+
"""Dex-native Microsoft Teams channel, thread, and chat operations."""
|
|
4
|
+
|
|
5
|
+
from .client import Client as Client
|
|
6
|
+
from .client import Config as Config
|
|
7
|
+
from .client import Credentials as Credentials
|
|
8
|
+
from .connection import Connection as Connection
|
|
9
|
+
from .connection import new_connection as new_connection
|
|
10
|
+
from .connection import new_connection_with_operations as new_connection_with_operations
|
|
11
|
+
from .connection import new_project_connection as new_project_connection
|
|
12
|
+
from .models import ListThreadRepliesInput as ListThreadRepliesInput
|
|
13
|
+
from .models import ListThreadRepliesOutput as ListThreadRepliesOutput
|
|
14
|
+
from .models import Message as Message
|
|
15
|
+
from .models import MessageSender as MessageSender
|
|
16
|
+
from .models import PostChannelMessageInput as PostChannelMessageInput
|
|
17
|
+
from .models import PostChatMessageInput as PostChatMessageInput
|
|
18
|
+
from .models import PostMessageOutput as PostMessageOutput
|
|
19
|
+
from .models import PostThreadReplyInput as PostThreadReplyInput
|
|
20
|
+
from .steps import new_list_thread_replies_step as new_list_thread_replies_step
|
|
21
|
+
from .steps import new_post_channel_message_step as new_post_channel_message_step
|
|
22
|
+
from .steps import new_post_chat_message_step as new_post_chat_message_step
|
|
23
|
+
from .steps import new_post_thread_reply_step as new_post_thread_reply_step
|
|
24
|
+
|
|
25
|
+
__all__ = [
|
|
26
|
+
"Client",
|
|
27
|
+
"Config",
|
|
28
|
+
"Credentials",
|
|
29
|
+
"Connection",
|
|
30
|
+
"ListThreadRepliesInput",
|
|
31
|
+
"ListThreadRepliesOutput",
|
|
32
|
+
"Message",
|
|
33
|
+
"MessageSender",
|
|
34
|
+
"PostChannelMessageInput",
|
|
35
|
+
"PostChatMessageInput",
|
|
36
|
+
"PostMessageOutput",
|
|
37
|
+
"PostThreadReplyInput",
|
|
38
|
+
"new_connection",
|
|
39
|
+
"new_connection_with_operations",
|
|
40
|
+
"new_project_connection",
|
|
41
|
+
"new_list_thread_replies_step",
|
|
42
|
+
"new_post_channel_message_step",
|
|
43
|
+
"new_post_chat_message_step",
|
|
44
|
+
"new_post_thread_reply_step",
|
|
45
|
+
]
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
endpoint: str = "https://graph.microsoft.com/v1.0"
|
|
14
|
+
max_response_bytes: int = 4194304
|
|
15
|
+
max_message_bytes: int = 81920
|
|
16
|
+
|
|
17
|
+
setattr(Config, '__module__', 'dex_connectors.microsoft_teams.client')
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@dataclass(frozen=True, slots=True)
|
|
21
|
+
class Credentials:
|
|
22
|
+
|
|
23
|
+
oauth_client_id: str
|
|
24
|
+
oauth_client_secret: SecretString
|
|
25
|
+
access_token: SecretString
|
|
26
|
+
refresh_token: SecretString
|
|
27
|
+
|
|
28
|
+
setattr(Credentials, '__module__', 'dex_connectors.microsoft_teams.client')
|