delegate-connector-telegram 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.
- delegate_connector_telegram-0.1.0/.env.example +20 -0
- delegate_connector_telegram-0.1.0/.gitignore +74 -0
- delegate_connector_telegram-0.1.0/LICENSE +201 -0
- delegate_connector_telegram-0.1.0/PKG-INFO +120 -0
- delegate_connector_telegram-0.1.0/README.md +91 -0
- delegate_connector_telegram-0.1.0/docker-compose.yml +30 -0
- delegate_connector_telegram-0.1.0/pyproject.toml +66 -0
- delegate_connector_telegram-0.1.0/src/delegate_connectors/telegram/__init__.py +52 -0
- delegate_connector_telegram-0.1.0/src/delegate_connectors/telegram/compose.py +249 -0
- delegate_connector_telegram-0.1.0/src/delegate_connectors/telegram/connector.py +504 -0
- delegate_connector_telegram-0.1.0/src/delegate_connectors/telegram/directory.py +194 -0
- delegate_connector_telegram-0.1.0/src/delegate_connectors/telegram/transport.py +512 -0
- delegate_connector_telegram-0.1.0/src/delegate_connectors/telegram/validation.py +169 -0
- delegate_connector_telegram-0.1.0/tests/conformance/conftest.py +6 -0
- delegate_connector_telegram-0.1.0/tests/conformance/loader.py +105 -0
- delegate_connector_telegram-0.1.0/tests/conformance/test_canonical_set.py +212 -0
- delegate_connector_telegram-0.1.0/tests/conformance/vector_driver.py +447 -0
- delegate_connector_telegram-0.1.0/tests/conftest.py +58 -0
- delegate_connector_telegram-0.1.0/tests/integration/__init__.py +2 -0
- delegate_connector_telegram-0.1.0/tests/integration/_botapi_double.py +210 -0
- delegate_connector_telegram-0.1.0/tests/integration/_live_telegram.py +65 -0
- delegate_connector_telegram-0.1.0/tests/integration/_telegram_compose.py +84 -0
- delegate_connector_telegram-0.1.0/tests/integration/conftest.py +65 -0
- delegate_connector_telegram-0.1.0/tests/integration/test_e2e.py +149 -0
- delegate_connector_telegram-0.1.0/tests/integration/test_send_roundtrip.py +219 -0
- delegate_connector_telegram-0.1.0/tests/regression/__init__.py +2 -0
- delegate_connector_telegram-0.1.0/tests/regression/conftest.py +52 -0
- delegate_connector_telegram-0.1.0/tests/regression/test_invoke_authenticates.py +67 -0
- delegate_connector_telegram-0.1.0/tests/regression/test_outbound_validation.py +136 -0
- delegate_connector_telegram-0.1.0/tests/regression/test_receipt_identity_binding.py +173 -0
- delegate_connector_telegram-0.1.0/tests/unit/test_compose.py +193 -0
- delegate_connector_telegram-0.1.0/tests/unit/test_connector.py +387 -0
- delegate_connector_telegram-0.1.0/tests/unit/test_directory.py +129 -0
- delegate_connector_telegram-0.1.0/tests/unit/test_transport.py +305 -0
- delegate_connector_telegram-0.1.0/tests/unit/test_validation.py +133 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# Copyright 2026 Terrene Foundation
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
#
|
|
4
|
+
# Telegram connector configuration. Copy to .env and fill in real values.
|
|
5
|
+
# NEVER commit a populated .env (root .gitignore excludes .env).
|
|
6
|
+
# All credentials are read from the environment — never hardcoded.
|
|
7
|
+
|
|
8
|
+
# --- Bot API (outbound sendMessage + inbound getUpdates) ---
|
|
9
|
+
# TELEGRAM_BOT_TOKEN is the single auth credential. It is part of the request
|
|
10
|
+
# URL (.../bot${TELEGRAM_BOT_TOKEN}/sendMessage), so the transport logs the
|
|
11
|
+
# method + chat, NEVER the URL or token. Leave blank in the template.
|
|
12
|
+
TELEGRAM_BOT_TOKEN=
|
|
13
|
+
|
|
14
|
+
# Bot API base URL. Public Telegram is https://api.telegram.org. For local
|
|
15
|
+
# Tier-2/3 tests, point at the hermetic local Bot API service (see
|
|
16
|
+
# docker-compose.yml), e.g. http://localhost:8081.
|
|
17
|
+
TELEGRAM_API_BASE=https://api.telegram.org
|
|
18
|
+
|
|
19
|
+
# Integer chat_id the integration tests send to. Leave blank in the template.
|
|
20
|
+
TELEGRAM_TEST_CHAT_ID=
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
*.so
|
|
6
|
+
.Python
|
|
7
|
+
build/
|
|
8
|
+
develop-eggs/
|
|
9
|
+
dist/
|
|
10
|
+
downloads/
|
|
11
|
+
eggs/
|
|
12
|
+
.eggs/
|
|
13
|
+
lib/
|
|
14
|
+
!.claude/hooks/lib/
|
|
15
|
+
lib64/
|
|
16
|
+
parts/
|
|
17
|
+
sdist/
|
|
18
|
+
var/
|
|
19
|
+
wheels/
|
|
20
|
+
*.egg-info/
|
|
21
|
+
.installed.cfg
|
|
22
|
+
*.egg
|
|
23
|
+
MANIFEST
|
|
24
|
+
|
|
25
|
+
# Virtual environments
|
|
26
|
+
.env
|
|
27
|
+
.venv
|
|
28
|
+
env/
|
|
29
|
+
venv/
|
|
30
|
+
ENV/
|
|
31
|
+
env.bak/
|
|
32
|
+
venv.bak/
|
|
33
|
+
.python-version
|
|
34
|
+
|
|
35
|
+
# IDE specific files
|
|
36
|
+
.idea/
|
|
37
|
+
.vscode/
|
|
38
|
+
*.swp
|
|
39
|
+
*.swo
|
|
40
|
+
.DS_Store
|
|
41
|
+
.jbeval/
|
|
42
|
+
output.txt
|
|
43
|
+
|
|
44
|
+
# Testing
|
|
45
|
+
.coverage
|
|
46
|
+
htmlcov/
|
|
47
|
+
.pytest_cache/
|
|
48
|
+
.mypy_cache/
|
|
49
|
+
|
|
50
|
+
# Secrets
|
|
51
|
+
*.pem
|
|
52
|
+
*.key
|
|
53
|
+
secrets/
|
|
54
|
+
|
|
55
|
+
# Workspace session notes (per-session, not versioned)
|
|
56
|
+
**/.session-notes
|
|
57
|
+
|
|
58
|
+
# Per-project learning data (generated at runtime)
|
|
59
|
+
.claude/learning/
|
|
60
|
+
.claude/rules/learned-instincts.md
|
|
61
|
+
|
|
62
|
+
# Runtime telemetry logs (generated by hooks at runtime)
|
|
63
|
+
.claude/logs/
|
|
64
|
+
|
|
65
|
+
# Internal docs (not for distribution)
|
|
66
|
+
/docs/01-kailash-vibe-cc-internals/
|
|
67
|
+
|
|
68
|
+
# Generated script outputs (sdk-users examples)
|
|
69
|
+
**/scripts/data/
|
|
70
|
+
**/scripts/outputs/
|
|
71
|
+
**/scripts/*.log
|
|
72
|
+
|
|
73
|
+
# Journal-hook runtime bookkeeping (per-clone skip log; not source)
|
|
74
|
+
**/.journal-skipped.log
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Support. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or support.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 Terrene Foundation
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: delegate-connector-telegram
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: OSS Telegram connector for the Terrene Delegate substrate (kailash.delegate).
|
|
5
|
+
Project-URL: Homepage, https://github.com/terrene-foundation/delegate-connectors
|
|
6
|
+
Project-URL: Changelog, https://github.com/terrene-foundation/delegate-connectors/blob/main/CHANGELOG.md
|
|
7
|
+
Author: Terrene Foundation
|
|
8
|
+
License-Expression: Apache-2.0
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: bot-api,connector,delegate,kailash,telegram
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Topic :: Communications :: Chat
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Requires-Dist: cryptography>=42.0
|
|
22
|
+
Requires-Dist: httpx>=0.27
|
|
23
|
+
Requires-Dist: kailash>=2.28.0
|
|
24
|
+
Provides-Extra: test
|
|
25
|
+
Requires-Dist: pytest-asyncio>=0.23; extra == 'test'
|
|
26
|
+
Requires-Dist: pytest>=8.0; extra == 'test'
|
|
27
|
+
Requires-Dist: python-dotenv>=1.0; extra == 'test'
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
|
|
30
|
+
<!--
|
|
31
|
+
Copyright 2026 Terrene Foundation
|
|
32
|
+
SPDX-License-Identifier: Apache-2.0
|
|
33
|
+
-->
|
|
34
|
+
|
|
35
|
+
# delegate-connector-telegram
|
|
36
|
+
|
|
37
|
+
An OSS Python connector for the Terrene Delegate substrate. Implements the
|
|
38
|
+
shipped `kailash.delegate.Connector` ABC (kailash 2.26.2) for Telegram via the
|
|
39
|
+
Bot API. It mirrors the email connector's shape and differs only in transport
|
|
40
|
+
(HTTP-only Bot API) and identity model (integer `user_id` / `chat_id`).
|
|
41
|
+
|
|
42
|
+
The connector contract (the shipped ABC — `authenticate / read / write / invoke`
|
|
43
|
+
plus the `auth_verifier / ledger / revocation` trust properties) is:
|
|
44
|
+
|
|
45
|
+
- **`write`** — `action` is a thunk wrapping a Bot API `sendMessage` POST,
|
|
46
|
+
executed under audit, returning a real `SignedActionEnvelope`. The send is the
|
|
47
|
+
auditable external side-effect.
|
|
48
|
+
- **`read`** — `query` is a thunk wrapping a Bot API `getUpdates` long-poll fetch,
|
|
49
|
+
executed under audit, returning `(updates, AttestedReadReceipt)`.
|
|
50
|
+
- **`authenticate`** — resolves the dispatch identity's `delegate_id` to a
|
|
51
|
+
`Principal` against a dual-keyed resolver (by stringified integer `user_id`
|
|
52
|
+
and `chat_id`). An unknown identity resolves to `Reject` (fail-closed); a
|
|
53
|
+
`@username` handle is never a resolution key (ref-unsafe and mutable).
|
|
54
|
+
- **`invoke`** — single-method dispatch entry: authenticate FIRST (fail-closed,
|
|
55
|
+
before any Bot API call), then dispatch a send, returning a
|
|
56
|
+
`ConnectorInvocationResult(external_side_effect=True)`.
|
|
57
|
+
- Trust properties — `auth_verifier` returns the wired `Ed25519Verifier`;
|
|
58
|
+
`ledger` / `revocation` return shipped concretes (framework-first; no custom
|
|
59
|
+
trust primitives).
|
|
60
|
+
|
|
61
|
+
It subclasses `Connector` **directly** (ADR-1) — NOT `LegacyInvokeConnector`,
|
|
62
|
+
whose proxied `read` / `write` emit empty, unverifiable receipts. There is no
|
|
63
|
+
stale `connect() / identify() / normalize()` surface; those methods do not exist
|
|
64
|
+
in the shipped ABC.
|
|
65
|
+
|
|
66
|
+
## Components
|
|
67
|
+
|
|
68
|
+
- **`transport.py`** — the `httpx`-backed Bot API transport (`sendMessage`
|
|
69
|
+
outbound + `getUpdates` inbound long-poll). A Bot API `429` raises a typed
|
|
70
|
+
`RateLimitedError` carrying `retry_after`; the caller decides backoff.
|
|
71
|
+
- **`connector.py`** — the `TelegramConnector` itself (the four ABC members + the
|
|
72
|
+
three trust properties) plus the `verify_action_envelope` /
|
|
73
|
+
`verify_read_receipt` helpers that re-derive identity-bound signing bytes.
|
|
74
|
+
- **`directory.py`** — the dual-keyed principal resolver + the closed-enum
|
|
75
|
+
`UnknownSenderDisposition` (unknown sender → `Reject`).
|
|
76
|
+
- **`validation.py`** — pure message-content validation (control-character
|
|
77
|
+
reject, `text` ≤ 4096 UTF-16 code units, `chat_id` shape), invoked at the
|
|
78
|
+
`OutboundMessage` construction boundary so every send route is covered.
|
|
79
|
+
- **`compose.py`** — `build_telegram_runtime`, which composes a real
|
|
80
|
+
`DelegateRuntime` around the connector with the shipped trust / audit /
|
|
81
|
+
verifier concretes (no mocks).
|
|
82
|
+
|
|
83
|
+
## Install
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
pip install -e connectors/telegram
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Configure
|
|
90
|
+
|
|
91
|
+
All credentials come from the environment (see `.env.example`):
|
|
92
|
+
`TELEGRAM_BOT_TOKEN` and `TELEGRAM_API_BASE`. Nothing is hardcoded; nothing is
|
|
93
|
+
logged. The token is part of the request URL, so the transport logs the method +
|
|
94
|
+
chat, never the URL.
|
|
95
|
+
|
|
96
|
+
## Test
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
pip install -e "connectors/telegram[test]"
|
|
100
|
+
# Tier 1 (unit)
|
|
101
|
+
python -m pytest connectors/telegram/tests/unit -q
|
|
102
|
+
# Tier 2/3 (integration — REAL TelegramTransport over a REAL httpx.AsyncClient
|
|
103
|
+
# whose byte stream terminates at an in-process protocol-faithful Bot API
|
|
104
|
+
# double; NO mock at the connector boundary, so these RUN in CI)
|
|
105
|
+
python -m pytest connectors/telegram/tests/integration -q
|
|
106
|
+
# Conformance (canonical conformance vector set)
|
|
107
|
+
python -m pytest connectors/telegram/tests/conformance -q
|
|
108
|
+
# Regression (behavioral security-property guards; NEVER deleted)
|
|
109
|
+
python -m pytest connectors/telegram/tests/regression -q
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
The opt-in Tier-3 live test (`test_live_telegram`) skips with a clear "cannot
|
|
113
|
+
execute" reason unless real `TELEGRAM_*` credentials are present — it never falls
|
|
114
|
+
back to a mock. The end-to-end `runtime.execute()` outcome assertions are
|
|
115
|
+
strict-`xfail` gated on an SDK fix (kailash-py#1182); the connector's own
|
|
116
|
+
read / write receipts verify today.
|
|
117
|
+
|
|
118
|
+
## License
|
|
119
|
+
|
|
120
|
+
Apache 2.0. All open-source IP is owned by the Terrene Foundation.
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Copyright 2026 Terrene Foundation
|
|
3
|
+
SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
-->
|
|
5
|
+
|
|
6
|
+
# delegate-connector-telegram
|
|
7
|
+
|
|
8
|
+
An OSS Python connector for the Terrene Delegate substrate. Implements the
|
|
9
|
+
shipped `kailash.delegate.Connector` ABC (kailash 2.26.2) for Telegram via the
|
|
10
|
+
Bot API. It mirrors the email connector's shape and differs only in transport
|
|
11
|
+
(HTTP-only Bot API) and identity model (integer `user_id` / `chat_id`).
|
|
12
|
+
|
|
13
|
+
The connector contract (the shipped ABC — `authenticate / read / write / invoke`
|
|
14
|
+
plus the `auth_verifier / ledger / revocation` trust properties) is:
|
|
15
|
+
|
|
16
|
+
- **`write`** — `action` is a thunk wrapping a Bot API `sendMessage` POST,
|
|
17
|
+
executed under audit, returning a real `SignedActionEnvelope`. The send is the
|
|
18
|
+
auditable external side-effect.
|
|
19
|
+
- **`read`** — `query` is a thunk wrapping a Bot API `getUpdates` long-poll fetch,
|
|
20
|
+
executed under audit, returning `(updates, AttestedReadReceipt)`.
|
|
21
|
+
- **`authenticate`** — resolves the dispatch identity's `delegate_id` to a
|
|
22
|
+
`Principal` against a dual-keyed resolver (by stringified integer `user_id`
|
|
23
|
+
and `chat_id`). An unknown identity resolves to `Reject` (fail-closed); a
|
|
24
|
+
`@username` handle is never a resolution key (ref-unsafe and mutable).
|
|
25
|
+
- **`invoke`** — single-method dispatch entry: authenticate FIRST (fail-closed,
|
|
26
|
+
before any Bot API call), then dispatch a send, returning a
|
|
27
|
+
`ConnectorInvocationResult(external_side_effect=True)`.
|
|
28
|
+
- Trust properties — `auth_verifier` returns the wired `Ed25519Verifier`;
|
|
29
|
+
`ledger` / `revocation` return shipped concretes (framework-first; no custom
|
|
30
|
+
trust primitives).
|
|
31
|
+
|
|
32
|
+
It subclasses `Connector` **directly** (ADR-1) — NOT `LegacyInvokeConnector`,
|
|
33
|
+
whose proxied `read` / `write` emit empty, unverifiable receipts. There is no
|
|
34
|
+
stale `connect() / identify() / normalize()` surface; those methods do not exist
|
|
35
|
+
in the shipped ABC.
|
|
36
|
+
|
|
37
|
+
## Components
|
|
38
|
+
|
|
39
|
+
- **`transport.py`** — the `httpx`-backed Bot API transport (`sendMessage`
|
|
40
|
+
outbound + `getUpdates` inbound long-poll). A Bot API `429` raises a typed
|
|
41
|
+
`RateLimitedError` carrying `retry_after`; the caller decides backoff.
|
|
42
|
+
- **`connector.py`** — the `TelegramConnector` itself (the four ABC members + the
|
|
43
|
+
three trust properties) plus the `verify_action_envelope` /
|
|
44
|
+
`verify_read_receipt` helpers that re-derive identity-bound signing bytes.
|
|
45
|
+
- **`directory.py`** — the dual-keyed principal resolver + the closed-enum
|
|
46
|
+
`UnknownSenderDisposition` (unknown sender → `Reject`).
|
|
47
|
+
- **`validation.py`** — pure message-content validation (control-character
|
|
48
|
+
reject, `text` ≤ 4096 UTF-16 code units, `chat_id` shape), invoked at the
|
|
49
|
+
`OutboundMessage` construction boundary so every send route is covered.
|
|
50
|
+
- **`compose.py`** — `build_telegram_runtime`, which composes a real
|
|
51
|
+
`DelegateRuntime` around the connector with the shipped trust / audit /
|
|
52
|
+
verifier concretes (no mocks).
|
|
53
|
+
|
|
54
|
+
## Install
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
pip install -e connectors/telegram
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Configure
|
|
61
|
+
|
|
62
|
+
All credentials come from the environment (see `.env.example`):
|
|
63
|
+
`TELEGRAM_BOT_TOKEN` and `TELEGRAM_API_BASE`. Nothing is hardcoded; nothing is
|
|
64
|
+
logged. The token is part of the request URL, so the transport logs the method +
|
|
65
|
+
chat, never the URL.
|
|
66
|
+
|
|
67
|
+
## Test
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
pip install -e "connectors/telegram[test]"
|
|
71
|
+
# Tier 1 (unit)
|
|
72
|
+
python -m pytest connectors/telegram/tests/unit -q
|
|
73
|
+
# Tier 2/3 (integration — REAL TelegramTransport over a REAL httpx.AsyncClient
|
|
74
|
+
# whose byte stream terminates at an in-process protocol-faithful Bot API
|
|
75
|
+
# double; NO mock at the connector boundary, so these RUN in CI)
|
|
76
|
+
python -m pytest connectors/telegram/tests/integration -q
|
|
77
|
+
# Conformance (canonical conformance vector set)
|
|
78
|
+
python -m pytest connectors/telegram/tests/conformance -q
|
|
79
|
+
# Regression (behavioral security-property guards; NEVER deleted)
|
|
80
|
+
python -m pytest connectors/telegram/tests/regression -q
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
The opt-in Tier-3 live test (`test_live_telegram`) skips with a clear "cannot
|
|
84
|
+
execute" reason unless real `TELEGRAM_*` credentials are present — it never falls
|
|
85
|
+
back to a mock. The end-to-end `runtime.execute()` outcome assertions are
|
|
86
|
+
strict-`xfail` gated on an SDK fix (kailash-py#1182); the connector's own
|
|
87
|
+
read / write receipts verify today.
|
|
88
|
+
|
|
89
|
+
## License
|
|
90
|
+
|
|
91
|
+
Apache 2.0. All open-source IP is owned by the Terrene Foundation.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Copyright 2026 Terrene Foundation
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
#
|
|
4
|
+
# One service, real infrastructure (no mock at the boundary):
|
|
5
|
+
#
|
|
6
|
+
# * botapi — a local Bot API HTTP server (the OSS telegram-bot-api daemon).
|
|
7
|
+
# Speaks the real Bot API protocol over a real socket + JSON cycle,
|
|
8
|
+
# so the connector's httpx sendMessage/getUpdates paths exercise the
|
|
9
|
+
# same request-response shape they hit against api.telegram.org.
|
|
10
|
+
# Backs the Tier-2/3 outbound-arrival + inbound round-trip tests
|
|
11
|
+
# (wired in todo 07). TELEGRAM_API_BASE points at this service.
|
|
12
|
+
#
|
|
13
|
+
# TELEGRAM_API_ID / TELEGRAM_API_HASH come from the environment (the local Bot
|
|
14
|
+
# API daemon requires Telegram app credentials to start). They are read from the
|
|
15
|
+
# shell / .env — never hardcoded here (rules/security.md). No Postgres, no PACT
|
|
16
|
+
# (the shipped kailash.delegate runtime audit is in-memory).
|
|
17
|
+
services:
|
|
18
|
+
botapi:
|
|
19
|
+
image: aiogram/telegram-bot-api:latest
|
|
20
|
+
container_name: delegate-telegram-botapi
|
|
21
|
+
restart: unless-stopped
|
|
22
|
+
environment:
|
|
23
|
+
# Telegram app credentials (https://my.telegram.org). Supplied via the
|
|
24
|
+
# environment; the template .env leaves them blank. The daemon refuses to
|
|
25
|
+
# start without them — that is the intended fail-closed behavior.
|
|
26
|
+
TELEGRAM_API_ID: ${TELEGRAM_API_ID:-}
|
|
27
|
+
TELEGRAM_API_HASH: ${TELEGRAM_API_HASH:-}
|
|
28
|
+
TELEGRAM_LOCAL: "true"
|
|
29
|
+
ports:
|
|
30
|
+
- "8081:8081" # Bot API HTTP
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# Copyright 2026 Terrene Foundation
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
[build-system]
|
|
4
|
+
requires = ["hatchling"]
|
|
5
|
+
build-backend = "hatchling.build"
|
|
6
|
+
|
|
7
|
+
[project]
|
|
8
|
+
name = "delegate-connector-telegram"
|
|
9
|
+
dynamic = ["version"]
|
|
10
|
+
description = "OSS Telegram connector for the Terrene Delegate substrate (kailash.delegate)."
|
|
11
|
+
readme = "README.md"
|
|
12
|
+
requires-python = ">=3.10"
|
|
13
|
+
license = "Apache-2.0"
|
|
14
|
+
license-files = ["LICENSE"]
|
|
15
|
+
authors = [{ name = "Terrene Foundation" }]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 4 - Beta",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"Operating System :: OS Independent",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3.10",
|
|
22
|
+
"Programming Language :: Python :: 3.11",
|
|
23
|
+
"Programming Language :: Python :: 3.12",
|
|
24
|
+
"Topic :: Communications :: Chat",
|
|
25
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
26
|
+
]
|
|
27
|
+
keywords = ["kailash", "delegate", "connector", "telegram", "bot-api"]
|
|
28
|
+
dependencies = [
|
|
29
|
+
# Connector ABC (write/read/authenticate) + Principal/SignedActionEnvelope
|
|
30
|
+
# landed in kailash 2.26.1; 2.24.0-2.25.2 ImportError on Principal. Floor 2.28.0:
|
|
31
|
+
# kailash-py#1182 (runtime audit-emit signature bug) fixed at <=2.28.1; dev/CI pin 2.28.1.
|
|
32
|
+
"kailash>=2.28.0",
|
|
33
|
+
# Ed25519Verifier requires the cryptography lib (kailash [trust] extra
|
|
34
|
+
# ships it; declared here because this connector composes a real
|
|
35
|
+
# Ed25519Verifier directly).
|
|
36
|
+
"cryptography>=42.0",
|
|
37
|
+
# async HTTP transport for the Bot API (sendMessage + getUpdates).
|
|
38
|
+
"httpx>=0.27",
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
[project.optional-dependencies]
|
|
42
|
+
test = [
|
|
43
|
+
"pytest>=8.0",
|
|
44
|
+
"pytest-asyncio>=0.23",
|
|
45
|
+
"python-dotenv>=1.0",
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
[project.urls]
|
|
49
|
+
Homepage = "https://github.com/terrene-foundation/delegate-connectors"
|
|
50
|
+
Changelog = "https://github.com/terrene-foundation/delegate-connectors/blob/main/CHANGELOG.md"
|
|
51
|
+
|
|
52
|
+
[tool.hatch.version]
|
|
53
|
+
path = "src/delegate_connectors/telegram/__init__.py"
|
|
54
|
+
|
|
55
|
+
[tool.hatch.build.targets.wheel]
|
|
56
|
+
packages = ["src/delegate_connectors"]
|
|
57
|
+
|
|
58
|
+
[tool.pytest.ini_options]
|
|
59
|
+
asyncio_mode = "auto"
|
|
60
|
+
asyncio_default_fixture_loop_scope = "function"
|
|
61
|
+
testpaths = ["tests"]
|
|
62
|
+
markers = [
|
|
63
|
+
"integration: real-infra Tier-2/3 tests (require a running local Bot API service)",
|
|
64
|
+
"regression: regression tests guarding a specific fixed bug (NEVER deleted)",
|
|
65
|
+
"conformance: canonical conformance vector tests",
|
|
66
|
+
]
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# Copyright 2026 Terrene Foundation
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
"""Telegram connector for the Terrene Delegate substrate.
|
|
4
|
+
|
|
5
|
+
Implements the shipped ``kailash.delegate.Connector`` ABC (kailash 2.26.2) for
|
|
6
|
+
Telegram via the Bot API: ``sendMessage`` outbound (``write``) and ``getUpdates``
|
|
7
|
+
long-poll inbound (``read``), authenticated against a dual-keyed principal
|
|
8
|
+
resolver. See the package README + ``specs/`` in the monorepo root for the full
|
|
9
|
+
contract.
|
|
10
|
+
|
|
11
|
+
The full surface has shipped: the pure-logic foundation — principal resolution
|
|
12
|
+
(:mod:`delegate_connectors.telegram.directory`) and message-content validation
|
|
13
|
+
(:mod:`delegate_connectors.telegram.validation`) — alongside the ``httpx``-backed
|
|
14
|
+
Bot API transport (:mod:`delegate_connectors.telegram.transport`), the
|
|
15
|
+
``TelegramConnector`` itself (:mod:`delegate_connectors.telegram.connector`), and
|
|
16
|
+
the runtime composition (:mod:`delegate_connectors.telegram.compose`).
|
|
17
|
+
|
|
18
|
+
``__all__`` re-exports only the pure, always-importable primitives (directory +
|
|
19
|
+
validation) so importing the package root never forces an ``httpx`` import for
|
|
20
|
+
callers that only need the resolver / validators. The ``httpx``-dependent
|
|
21
|
+
modules are imported from their own submodules directly (e.g.
|
|
22
|
+
``from delegate_connectors.telegram.transport import TelegramTransport``).
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
__version__ = "0.1.0"
|
|
26
|
+
|
|
27
|
+
from delegate_connectors.telegram.directory import (
|
|
28
|
+
ResolutionOutcome,
|
|
29
|
+
TelegramPrincipalResolver,
|
|
30
|
+
UnknownSenderDisposition,
|
|
31
|
+
)
|
|
32
|
+
from delegate_connectors.telegram.validation import (
|
|
33
|
+
MAX_TEXT_UTF16_UNITS,
|
|
34
|
+
MessageValidationError,
|
|
35
|
+
text_utf16_units,
|
|
36
|
+
validate_chat_id,
|
|
37
|
+
validate_text,
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
__all__ = [
|
|
41
|
+
"__version__",
|
|
42
|
+
# Principal resolution (directory.py).
|
|
43
|
+
"TelegramPrincipalResolver",
|
|
44
|
+
"UnknownSenderDisposition",
|
|
45
|
+
"ResolutionOutcome",
|
|
46
|
+
# Message-content validation (validation.py — pure, no transport).
|
|
47
|
+
"MessageValidationError",
|
|
48
|
+
"validate_text",
|
|
49
|
+
"validate_chat_id",
|
|
50
|
+
"text_utf16_units",
|
|
51
|
+
"MAX_TEXT_UTF16_UNITS",
|
|
52
|
+
]
|