@effect/chat-telegram 0.0.0-stage → 4.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (157) hide show
  1. package/AGENTS.md +434 -0
  2. package/CLAUDE.md +434 -0
  3. package/LICENSE +21 -0
  4. package/README.md +121 -2
  5. package/ai-docs/README.md +44 -0
  6. package/ai-docs/package.json +36 -0
  7. package/ai-docs/src/01_effect/01_basics/01_effect-gen.ts +30 -0
  8. package/ai-docs/src/01_effect/01_basics/02_effect-fn.ts +52 -0
  9. package/ai-docs/src/01_effect/01_basics/10_creating-effects.ts +74 -0
  10. package/ai-docs/src/01_effect/01_basics/index.md +7 -0
  11. package/ai-docs/src/01_effect/02_schema/10_schema-basics.ts +43 -0
  12. package/ai-docs/src/01_effect/02_schema/index.md +7 -0
  13. package/ai-docs/src/01_effect/03_services/01_service.ts +45 -0
  14. package/ai-docs/src/01_effect/03_services/10_reference.ts +10 -0
  15. package/ai-docs/src/01_effect/03_services/20_layer-composition.ts +70 -0
  16. package/ai-docs/src/01_effect/03_services/20_layer-unwrap.ts +66 -0
  17. package/ai-docs/src/01_effect/03_services/index.md +5 -0
  18. package/ai-docs/src/01_effect/04_errors/01_error-handling.ts +30 -0
  19. package/ai-docs/src/01_effect/04_errors/10_catch-tags.ts +24 -0
  20. package/ai-docs/src/01_effect/04_errors/20_reason-errors.ts +64 -0
  21. package/ai-docs/src/01_effect/04_errors/index.md +1 -0
  22. package/ai-docs/src/01_effect/05_resources/10_acquire-release.ts +105 -0
  23. package/ai-docs/src/01_effect/05_resources/20_layer-side-effects.ts +31 -0
  24. package/ai-docs/src/01_effect/05_resources/30_layer-map.ts +86 -0
  25. package/ai-docs/src/01_effect/05_resources/index.md +3 -0
  26. package/ai-docs/src/01_effect/06_running/10_run-main.ts +30 -0
  27. package/ai-docs/src/01_effect/06_running/20_layer-launch.ts +27 -0
  28. package/ai-docs/src/01_effect/06_running/index.md +1 -0
  29. package/ai-docs/src/01_effect/07_pubsub/10_pubsub.ts +56 -0
  30. package/ai-docs/src/01_effect/07_pubsub/index.md +3 -0
  31. package/ai-docs/src/03_stream/10_creating-streams.ts +103 -0
  32. package/ai-docs/src/03_stream/20_consuming-streams.ts +137 -0
  33. package/ai-docs/src/03_stream/30_encoding.ts +163 -0
  34. package/ai-docs/src/03_stream/index.md +4 -0
  35. package/ai-docs/src/04_integration/10_managed-runtime.ts +129 -0
  36. package/ai-docs/src/04_integration/index.md +5 -0
  37. package/ai-docs/src/05_batching/10_request-resolver.ts +89 -0
  38. package/ai-docs/src/05_batching/index.md +3 -0
  39. package/ai-docs/src/06_schedule/10_schedules.ts +111 -0
  40. package/ai-docs/src/06_schedule/index.md +3 -0
  41. package/ai-docs/src/07_datetime/10_creating-and-formatting.ts +30 -0
  42. package/ai-docs/src/07_datetime/20_time-zones.ts +44 -0
  43. package/ai-docs/src/07_datetime/index.md +5 -0
  44. package/ai-docs/src/08_observability/10_logging.ts +66 -0
  45. package/ai-docs/src/08_observability/20_otlp-tracing.ts +95 -0
  46. package/ai-docs/src/08_observability/index.md +7 -0
  47. package/ai-docs/src/09_testing/10_effect-tests.ts +55 -0
  48. package/ai-docs/src/09_testing/20_layer-tests.ts +138 -0
  49. package/ai-docs/src/09_testing/index.md +1 -0
  50. package/ai-docs/src/10_predicate/01_basics.ts +14 -0
  51. package/ai-docs/src/10_predicate/index.md +9 -0
  52. package/ai-docs/src/40_sql/10_basics.ts +175 -0
  53. package/ai-docs/src/40_sql/index.md +6 -0
  54. package/ai-docs/src/50_http-client/10_basics.ts +102 -0
  55. package/ai-docs/src/50_http-client/index.md +3 -0
  56. package/ai-docs/src/51_http-server/10_basics.ts +118 -0
  57. package/ai-docs/src/51_http-server/20_testing.ts +100 -0
  58. package/ai-docs/src/51_http-server/fixtures/api/Api.ts +14 -0
  59. package/ai-docs/src/51_http-server/fixtures/api/Authorization.ts +36 -0
  60. package/ai-docs/src/51_http-server/fixtures/api/System.ts +10 -0
  61. package/ai-docs/src/51_http-server/fixtures/api/Users.ts +107 -0
  62. package/ai-docs/src/51_http-server/fixtures/domain/User.ts +21 -0
  63. package/ai-docs/src/51_http-server/fixtures/domain/UserErrors.ts +22 -0
  64. package/ai-docs/src/51_http-server/fixtures/server/Authorization.ts +37 -0
  65. package/ai-docs/src/51_http-server/fixtures/server/Users/http.ts +80 -0
  66. package/ai-docs/src/51_http-server/fixtures/server/Users.ts +183 -0
  67. package/ai-docs/src/51_http-server/index.md +3 -0
  68. package/ai-docs/src/52_graphql/10_basics.ts +117 -0
  69. package/ai-docs/src/52_graphql/20_testing.ts +45 -0
  70. package/ai-docs/src/52_graphql/30_batching.ts +118 -0
  71. package/ai-docs/src/52_graphql/40_aliased-batching.ts +124 -0
  72. package/ai-docs/src/52_graphql/50_errors-and-retries.ts +74 -0
  73. package/ai-docs/src/52_graphql/index.md +6 -0
  74. package/ai-docs/src/60_child-process/10_working-with-child-processes.ts +117 -0
  75. package/ai-docs/src/60_child-process/index.md +3 -0
  76. package/ai-docs/src/70_cli/10_basics.ts +162 -0
  77. package/ai-docs/src/70_cli/index.md +5 -0
  78. package/ai-docs/src/71_ai/10_language-model.ts +156 -0
  79. package/ai-docs/src/71_ai/20_tools.ts +226 -0
  80. package/ai-docs/src/71_ai/30_chat.ts +158 -0
  81. package/ai-docs/src/71_ai/fixtures/domain/LaunchPlan.ts +9 -0
  82. package/ai-docs/src/71_ai/index.md +5 -0
  83. package/ai-docs/src/80_cluster/10_entities.ts +97 -0
  84. package/ai-docs/src/80_cluster/index.md +4 -0
  85. package/ai-docs/src/index.md +10 -0
  86. package/ai-docs/tsconfig.json +28 -0
  87. package/dist/TelegramBotApi.d.ts +153 -0
  88. package/dist/TelegramBotApi.d.ts.map +1 -0
  89. package/dist/TelegramBotApi.js +219 -0
  90. package/dist/TelegramBotApi.js.map +1 -0
  91. package/dist/TelegramChat.d.ts +390 -0
  92. package/dist/TelegramChat.d.ts.map +1 -0
  93. package/dist/TelegramChat.js +359 -0
  94. package/dist/TelegramChat.js.map +1 -0
  95. package/dist/index.d.ts +15 -0
  96. package/dist/index.d.ts.map +1 -0
  97. package/dist/index.js +16 -0
  98. package/dist/index.js.map +1 -0
  99. package/dist/internal/actions.d.ts +2 -0
  100. package/dist/internal/actions.d.ts.map +1 -0
  101. package/dist/internal/actions.js +88 -0
  102. package/dist/internal/actions.js.map +1 -0
  103. package/dist/internal/adapter.d.ts +2 -0
  104. package/dist/internal/adapter.d.ts.map +1 -0
  105. package/dist/internal/adapter.js +309 -0
  106. package/dist/internal/adapter.js.map +1 -0
  107. package/dist/internal/address.d.ts +2 -0
  108. package/dist/internal/address.d.ts.map +1 -0
  109. package/dist/internal/address.js +26 -0
  110. package/dist/internal/address.js.map +1 -0
  111. package/dist/internal/commands.d.ts +2 -0
  112. package/dist/internal/commands.d.ts.map +1 -0
  113. package/dist/internal/commands.js +30 -0
  114. package/dist/internal/commands.js.map +1 -0
  115. package/dist/internal/errors.d.ts +2 -0
  116. package/dist/internal/errors.d.ts.map +1 -0
  117. package/dist/internal/errors.js +136 -0
  118. package/dist/internal/errors.js.map +1 -0
  119. package/dist/internal/markdown.d.ts +9 -0
  120. package/dist/internal/markdown.d.ts.map +1 -0
  121. package/dist/internal/markdown.js +708 -0
  122. package/dist/internal/markdown.js.map +1 -0
  123. package/dist/internal/normalize.d.ts +2 -0
  124. package/dist/internal/normalize.d.ts.map +1 -0
  125. package/dist/internal/normalize.js +276 -0
  126. package/dist/internal/normalize.js.map +1 -0
  127. package/dist/internal/options.d.ts +2 -0
  128. package/dist/internal/options.d.ts.map +1 -0
  129. package/dist/internal/options.js +6 -0
  130. package/dist/internal/options.js.map +1 -0
  131. package/dist/internal/polling.d.ts +2 -0
  132. package/dist/internal/polling.d.ts.map +1 -0
  133. package/dist/internal/polling.js +68 -0
  134. package/dist/internal/polling.js.map +1 -0
  135. package/dist/internal/receive.d.ts +2 -0
  136. package/dist/internal/receive.d.ts.map +1 -0
  137. package/dist/internal/receive.js +183 -0
  138. package/dist/internal/receive.js.map +1 -0
  139. package/dist/internal/webhook.d.ts +2 -0
  140. package/dist/internal/webhook.d.ts.map +1 -0
  141. package/dist/internal/webhook.js +61 -0
  142. package/dist/internal/webhook.js.map +1 -0
  143. package/package.json +62 -3
  144. package/src/TelegramBotApi.ts +282 -0
  145. package/src/TelegramChat.ts +542 -0
  146. package/src/index.ts +18 -0
  147. package/src/internal/actions.ts +95 -0
  148. package/src/internal/adapter.ts +319 -0
  149. package/src/internal/address.ts +33 -0
  150. package/src/internal/commands.ts +37 -0
  151. package/src/internal/errors.ts +148 -0
  152. package/src/internal/markdown.ts +805 -0
  153. package/src/internal/normalize.ts +283 -0
  154. package/src/internal/options.ts +12 -0
  155. package/src/internal/polling.ts +86 -0
  156. package/src/internal/receive.ts +268 -0
  157. package/src/internal/webhook.ts +85 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"receive.js","names":[],"sources":["../../src/internal/receive.ts"],"sourcesContent":[null],"mappings":"AAGA,OAAO,KAAK,eAAe,MAAM,6BAA6B;AAC9D,OAAO,KAAK,QAAQ,MAAM,iBAAiB;AAC3C,OAAO,KAAK,MAAM,MAAM,eAAe;AACvC,OAAO,KAAK,MAAM,MAAM,eAAe;AAGvC,OAAO,KAAK,OAAO,MAAM,cAAc;AAEvC,SAAS,QAAQ,QAAQ,cAAc;AACvC,OAAO,KAAK,MAAM,MAAM,aAAa;AACrC,SACE,SAAS,EAET,OAAO,EACP,WAAW,EACX,UAAU,EACV,QAAQ,EAER,cAAc,EACd,WAAW,EACX,SAAS,EACT,MAAM,EACN,MAAM,EACN,QAAQ,QACH,gBAAgB;AAcvB;AACA,OAAO,MAAM,QAAQ,GAAG;EACtB,QAAQ,eAAE,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;EAC9B,aAAa,eAAE,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC;EACpC,eAAe,eAAE,QAAQ,CAAC,OAAO,CAAC,EAAE;CAC5B;AAEV;AACA,OAAO,MA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,MAAM,EAAE,OAAO,OAAO,SAAS;EAC7C,IAAI,KAAK,KAAK,SAAS,EAAE,OAAO,SAAS;EACzC,OAAO,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAC9B,MAAM,CAAC,aAAa,CAAC,QAAQ,CAAC,OAAO,CAAC,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC,EACnE,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC;IAAE,MAAM,EAAE,MAAM,aAAsB;IAAE,MAAM,EAAE,MAAM;EAAmB,CAAE,CAAC,CAAC,EACrG,MAAM,CAAC,QAAQ,CAAC,aAAa,EAAE,MAAM,MAAM,CAAC,OAAO,CAAC,aAAsB,CAAC,CAAC,CAC7E;AACH,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=webhook.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhook.d.ts","sourceRoot":"","sources":["../../src/internal/webhook.ts"],"names":[],"mappings":""}
@@ -0,0 +1,61 @@
1
+ import * as ByteSize from "effect/ByteSize";
2
+ import { timingSafeEqual } from "effect/crypto/Mac";
3
+ import * as Effect from "effect/Effect";
4
+ import * as HttpIncomingMessage from "effect/http/HttpIncomingMessage";
5
+ import * as HttpServerResponse from "effect/http/HttpServerResponse";
6
+ import * as Predicate from "effect/Predicate";
7
+ import * as Redacted from "effect/Redacted";
8
+ import * as Errors from "./errors.js";
9
+ /** The header Telegram sends the webhook secret in. @internal */
10
+ export const secretHeader = "x-telegram-bot-api-secret-token";
11
+ /** A secret token's value, if it keeps Telegram's rule with the adapter's floor of 32 characters. @internal */
12
+ export const secretToken = (op, token) => {
13
+ const secret = Redacted.value(token);
14
+ return /^[A-Za-z0-9_-]{32,256}$/.test(secret) ? Effect.succeed(secret) : Errors.fail(op, Errors.invalidRequest("invalid_secret_token"));
15
+ };
16
+ const encoder = /*#__PURE__*/new TextEncoder();
17
+ const decoder = /*#__PURE__*/new TextDecoder();
18
+ const parseJson = text => {
19
+ try {
20
+ return JSON.parse(text);
21
+ } catch {
22
+ return undefined;
23
+ }
24
+ };
25
+ const status = code => HttpServerResponse.empty({
26
+ status: code
27
+ });
28
+ /**
29
+ * One webhook request.
30
+ *
31
+ * - 401 without the secret, before the body is read. 413 past
32
+ * `maxBodySize`, 400 for a body that can't be read or is not an update.
33
+ * - 200 once the update was accepted, answered or sent to `onUnhandled`.
34
+ * - 503 when its event was not accepted in time, or could not be read.
35
+ *
36
+ * @internal
37
+ */
38
+ export const handleRequest = (request, options) => Effect.gen(function* () {
39
+ const header = request.headers[secretHeader];
40
+ // Compared in constant time.
41
+ if (header === undefined || !timingSafeEqual(encoder.encode(header), options.secret)) return status(401);
42
+ const body = yield* Effect.result(Effect.provideService(request.arrayBuffer, HttpIncomingMessage.MaxBodySize, options.maxBodySize));
43
+ if (body._tag === "Failure") {
44
+ const reason = body.failure.reason;
45
+ return status(reason._tag === "RequestParseError" && reason.reason === "BodyTooLarge" ? 413 : 400);
46
+ }
47
+ // Measured again: the request caches its body, so one read earlier under a larger limit comes back whole.
48
+ if (body.success.byteLength > ByteSize.toNumberUnsafe(options.maxBodySize)) return status(413);
49
+ const update = parseJson(decoder.decode(body.success));
50
+ if (!Predicate.isObject(update) || typeof update.update_id !== "number") return status(400);
51
+ switch (yield* options.receive(update)) {
52
+ case "accepted":
53
+ case "unhandled":
54
+ return status(200);
55
+ case "invalid":
56
+ return yield* Effect.as(Effect.logWarning("telegram webhook: the update could not be read, answered 503"), status(503));
57
+ case "notAccepted":
58
+ return yield* Effect.as(Effect.logWarning("telegram webhook: the handler refused the event or passed the deadline, answered 503"), status(503));
59
+ }
60
+ });
61
+ //# sourceMappingURL=webhook.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhook.js","names":[],"sources":["../../src/internal/webhook.ts"],"sourcesContent":[null],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,iBAAiB;AAE3C,SAAS,e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","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,65 @@
1
1
  {
2
2
  "name": "@effect/chat-telegram",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "4.1.5",
4
+ "type": "module",
5
+ "license": "MIT",
6
+ "description": "The Telegram Bot API adapter for effect/chat",
7
+ "homepage": "https://effect.website",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/Effect-TS/effect.git",
11
+ "directory": "packages/chat/telegram"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/Effect-TS/effect/issues"
15
+ },
16
+ "tags": [
17
+ "typescript",
18
+ "chat",
19
+ "telegram"
20
+ ],
21
+ "keywords": [
22
+ "typescript",
23
+ "chat",
24
+ "telegram"
25
+ ],
26
+ "sideEffects": [],
27
+ "exports": {
28
+ "./package.json": "./package.json",
29
+ ".": "./dist/index.js",
30
+ "./*": "./dist/*.js",
31
+ "./internal/*": null,
32
+ "./index": null,
33
+ "./*/index": null
34
+ },
35
+ "files": [
36
+ "src/**/*.ts",
37
+ "dist/**/*.js",
38
+ "dist/**/*.js.map",
39
+ "dist/**/*.d.ts",
40
+ "dist/**/*.d.ts.map",
41
+ "AGENTS.md",
42
+ "CLAUDE.md",
43
+ "ai-docs/**/*"
44
+ ],
45
+ "publishConfig": {
46
+ "access": "public",
47
+ "provenance": true
48
+ },
49
+ "devDependencies": {
50
+ "@types/mdast": "^4.0.4",
51
+ "mdast-util-from-markdown": "^2.0.2",
52
+ "mdast-util-gfm": "^3.1.0",
53
+ "micromark-extension-gfm": "^3.0.0",
54
+ "effect": "^4.1.5"
55
+ },
56
+ "peerDependencies": {
57
+ "effect": "^4.1.5"
58
+ },
59
+ "scripts": {
60
+ "codegen": "effect-utils codegen",
61
+ "build": "tsc -b tsconfig.json && pnpm babel",
62
+ "babel": "babel dist --plugins annotate-pure-calls --out-dir dist --source-maps",
63
+ "check": "tsc -b tsconfig.json"
64
+ }
6
65
  }
@@ -0,0 +1,282 @@
1
+ /**
2
+ * The minimal Bot API client the Telegram adapter is built on. It is public,
3
+ * so a consumer can call a method the adapter has no op for, with the same
4
+ * error mapping, the same rule for writes and the same care for the token.
5
+ *
6
+ * **Details**
7
+ *
8
+ * The bot token is part of every request's path, and `HttpClient` records
9
+ * the path of a request in its span and in its errors. So the client's own
10
+ * span is turned off for every request made here, and each call gets a span
11
+ * `TelegramBotApi.{method}` whose `url.path` is `/bot<redacted>/{method}`.
12
+ * Every failure becomes a `ChatError` whose `cause` holds no request,
13
+ * response or URL.
14
+ *
15
+ * @stability unstable
16
+ * @since 4.1.5
17
+ */
18
+ import { type File, retrySafe } from "effect/chat/ChatAdapter"
19
+ import type { ChatError } from "effect/chat/ChatError"
20
+ import { ChatThread } from "effect/chat/ChatThread"
21
+ import * as Context from "effect/Context"
22
+ import * as Effect from "effect/Effect"
23
+ import * as FetchHttpClient from "effect/http/FetchHttpClient"
24
+ import * as HttpClient from "effect/http/HttpClient"
25
+ import * as HttpClientRequest from "effect/http/HttpClientRequest"
26
+ import type * as HttpClientResponse from "effect/http/HttpClientResponse"
27
+ import * as Layer from "effect/Layer"
28
+ import { isObject } from "effect/Predicate"
29
+ import * as Redacted from "effect/Redacted"
30
+ import * as Schema from "effect/Schema"
31
+ import * as Stream from "effect/Stream"
32
+ import * as Address from "./internal/address.ts"
33
+ import * as Errors from "./internal/errors.ts"
34
+
35
+ /**
36
+ * Which Telegram environment a bot lives in. The test environment has its
37
+ * own accounts and bots, and its methods sit under `/bot<token>/test/`.
38
+ *
39
+ * @stability unstable
40
+ * @category models
41
+ * @since 4.1.5
42
+ */
43
+ export type Environment = "production" | "test"
44
+
45
+ /**
46
+ * The cause of a `NotFound` with detail `chat_migrated`: the group became
47
+ * a supergroup, which has a new chat id. The adapter does not follow it,
48
+ * since the consumer is the one that stores the old address.
49
+ *
50
+ * @stability unstable
51
+ * @category errors
52
+ * @since 4.1.5
53
+ */
54
+ export class TelegramChatMigrated extends Schema.TaggedError<TelegramChatMigrated>(
55
+ "@effect/chat-telegram/TelegramBotApi/TelegramChatMigrated"
56
+ )("TelegramChatMigrated", {
57
+ thread: ChatThread
58
+ }) {
59
+ override get message(): string {
60
+ return "The Telegram group became a supergroup with a new address"
61
+ }
62
+ }
63
+
64
+ /**
65
+ * Options for one Bot API call.
66
+ *
67
+ * @stability unstable
68
+ * @category models
69
+ * @since 4.1.5
70
+ */
71
+ export interface CallOptions {
72
+ /**
73
+ * The call changes something. It is never repeated once the request left,
74
+ * and a failure that may have landed is `uncertain`.
75
+ */
76
+ readonly write?: boolean | undefined
77
+ /** Files sent as parts of a `multipart/form-data` body, each under its `field`. */
78
+ readonly files?: ReadonlyArray<{ readonly field: string; readonly file: File }> | undefined
79
+ /** Retry `retry` failures, as `ChatAdapter.retrySafe` does. Default true. */
80
+ readonly retry?: boolean | undefined
81
+ }
82
+
83
+ /**
84
+ * The Bot API client, with the bot's token.
85
+ *
86
+ * **Details**
87
+ *
88
+ * - `call` posts `params` to a method and succeeds with its `result`.
89
+ * Objects in `params` are sent as JSON; with `files` the body is
90
+ * multipart and each object is a JSON string part.
91
+ * - An answer with `ok: false` fails with the reason for its `error_code`
92
+ * and `parameters`. Its `detail` is a fixed string, never Telegram's
93
+ * description, which can quote the message. A `migrate_to_chat_id` gives
94
+ * `NotFound` with detail `chat_migrated` and a `TelegramChatMigrated`
95
+ * cause.
96
+ * - `file` streams a file by its `file_path` from `getFile`, failing
97
+ * `TooLarge` once more than `maxBytes` arrive. Redirects are refused.
98
+ * - `botId` is the numeric id in front of the token's colon.
99
+ * - The error's `op` is the method.
100
+ *
101
+ * @stability unstable
102
+ * @category services
103
+ * @since 4.1.5
104
+ */
105
+ export class TelegramBotApi extends Context.Service<TelegramBotApi, {
106
+ readonly botId: string
107
+ readonly environment: Environment
108
+ readonly call: (
109
+ method: string,
110
+ params?: Readonly<Record<string, unknown>> | undefined,
111
+ options?: CallOptions | undefined
112
+ ) => Effect.Effect<Schema.Json, ChatError>
113
+ readonly file: (filePath: string, options: { readonly maxBytes: number }) => Stream.Stream<Uint8Array, ChatError>
114
+ }>()("@effect/chat-telegram/TelegramBotApi") {}
115
+
116
+ /**
117
+ * The cloud Bot API server.
118
+ *
119
+ * @stability unstable
120
+ * @category constants
121
+ * @since 4.1.5
122
+ */
123
+ export const defaultApiUrl = "https://api.telegram.org"
124
+
125
+ const methodName = /^[A-Za-z]{1,64}$/
126
+ const filePath = /^[A-Za-z0-9_.-]+(?:\/[A-Za-z0-9_.-]+)*$/
127
+
128
+ const formValue = (value: unknown): string => typeof value === "string" ? value : JSON.stringify(value)
129
+
130
+ /**
131
+ * Builds the client from an `HttpClient` and a bot token.
132
+ *
133
+ * **Details**
134
+ *
135
+ * Fails `Unauthenticated` with detail `invalid_token` when the token has
136
+ * no numeric bot id in front of a colon. `apiUrl` is for a local Bot API
137
+ * server and is privileged configuration.
138
+ *
139
+ * @stability unstable
140
+ * @category constructors
141
+ * @since 4.1.5
142
+ */
143
+ export const make = Effect.fnUntraced(function*(options: {
144
+ readonly token: Redacted.Redacted<string>
145
+ readonly environment?: Environment | undefined
146
+ readonly apiUrl?: string | undefined
147
+ }) {
148
+ const http = yield* HttpClient.HttpClient
149
+ const environment = options.environment ?? "production"
150
+ const apiUrl = (options.apiUrl ?? defaultApiUrl).replace(/\/+$/, "")
151
+ const botId = /^(\d{1,20}):[A-Za-z0-9_-]+$/.exec(Redacted.value(options.token))?.[1]
152
+ if (botId === undefined) {
153
+ return yield* Errors.fail("layer", Errors.unauthenticatedToken)
154
+ }
155
+ const suffix = environment === "test" ? "/test" : ""
156
+ const methodUrl = (method: string) => `${apiUrl}/bot${Redacted.value(options.token)}${suffix}/${method}`
157
+ const fileUrl = (path: string) => `${apiUrl}/file/bot${Redacted.value(options.token)}${suffix}/${path}`
158
+
159
+ // Redirects are never followed: the next hop would see the token in the path.
160
+ const send = (request: HttpClientRequest.HttpClientRequest, op: string, write: boolean) =>
161
+ Effect.flatMap(Effect.serviceOption(FetchHttpClient.RequestInit), (init) =>
162
+ http.execute(request).pipe(
163
+ Effect.provideService(HttpClient.TracerDisabledWhen, () => true),
164
+ Effect.provideService(FetchHttpClient.RequestInit, {
165
+ ...(init._tag === "Some" ? init.value : {}),
166
+ redirect: "manual"
167
+ }),
168
+ Effect.mapError((error) => Errors.chatError(op, Errors.transport(write, error.reason._tag)))
169
+ ))
170
+
171
+ const decode = (op: string, write: boolean, response: HttpClientResponse.HttpClientResponse) => {
172
+ const success = response.status >= 200 && response.status < 300
173
+ const statusError: Errors.ApiError = { code: response.status, description: "" }
174
+ return response.json.pipe(
175
+ Effect.matchEffect({
176
+ onFailure: () =>
177
+ Errors.fail(
178
+ op,
179
+ success ? Errors.invalidResponse(write, "invalid_json") : Errors.reasonForApiError(statusError, { write })
180
+ ),
181
+ onSuccess: (body): Effect.Effect<Schema.Json, ChatError> => {
182
+ if (isObject(body) && body.ok === true && "result" in body) return Effect.succeed(body.result as Schema.Json)
183
+ const error = Errors.apiError(body, response.status) ?? (success ? undefined : statusError)
184
+ if (error === undefined) return Errors.fail(op, Errors.invalidResponse(write, "invalid_answer"))
185
+ const cause = error.migrateTo === undefined
186
+ ? undefined
187
+ : new TelegramChatMigrated({ thread: Address.thread(error.migrateTo) })
188
+ return Errors.fail(op, Errors.reasonForApiError(error, { write, cause }))
189
+ }
190
+ })
191
+ )
192
+ }
193
+
194
+ const once = (method: string, params: Readonly<Record<string, unknown>>, callOptions: CallOptions) => {
195
+ const write = callOptions.write === true
196
+ let request = HttpClientRequest.post(methodUrl(method))
197
+ if (callOptions.files !== undefined && callOptions.files.length > 0) {
198
+ const form = new FormData()
199
+ for (const [key, value] of Object.entries(params)) {
200
+ if (value !== undefined) form.append(key, formValue(value))
201
+ }
202
+ for (const { field, file } of callOptions.files) {
203
+ form.append(
204
+ field,
205
+ new Blob([file.content as Uint8Array<ArrayBuffer>], { type: file.contentType }),
206
+ file.name
207
+ )
208
+ }
209
+ request = HttpClientRequest.bodyFormData(request, form)
210
+ } else {
211
+ request = HttpClientRequest.bodyJsonUnsafe(request, params)
212
+ }
213
+ return Effect.flatMap(send(request, method, write), (response) => decode(method, write, response)).pipe(
214
+ Effect.withSpan(`TelegramBotApi.${method}`, {
215
+ kind: "client",
216
+ attributes: {
217
+ "http.request.method": "POST",
218
+ "url.path": `/bot<redacted>${suffix}/${method}`,
219
+ "telegram.method": method
220
+ }
221
+ })
222
+ )
223
+ }
224
+
225
+ const call: TelegramBotApi["Service"]["call"] = (method, params = {}, callOptions = {}) => {
226
+ if (!methodName.test(method)) return Errors.fail(method, Errors.invalidRequest("invalid_method"))
227
+ const effect = once(method, params, callOptions)
228
+ return callOptions.retry === false ? effect : retrySafe(effect)
229
+ }
230
+
231
+ const file: TelegramBotApi["Service"]["file"] = (path, { maxBytes }) =>
232
+ Stream.unwrap(
233
+ Effect.gen(function*() {
234
+ const op = "download"
235
+ if (!filePath.test(path) || path.split("/").some((segment) => segment === "." || segment === "..")) {
236
+ return yield* Errors.fail(op, Errors.invalidResponse(false, "untrusted_file_path"))
237
+ }
238
+ const url = fileUrl(path)
239
+ const response = yield* send(HttpClientRequest.get(url), op, false)
240
+ if ((response.status >= 300 && response.status < 400) || response.url !== url) {
241
+ return yield* Errors.fail(op, Errors.invalidResponse(false, "redirect"))
242
+ }
243
+ if (response.status < 200 || response.status >= 300) {
244
+ return yield* Errors.fail(
245
+ op,
246
+ Errors.reasonForApiError({ code: response.status, description: "" }, { write: false })
247
+ )
248
+ }
249
+ const tooLarge = Errors.chatError(op, Errors.tooLarge("files", "max_bytes"))
250
+ const length = Number(response.headers["content-length"])
251
+ if (Number.isFinite(length) && length > maxBytes) return yield* Effect.fail(tooLarge)
252
+ let received = 0
253
+ return response.stream.pipe(
254
+ Stream.mapError((error) => Errors.chatError(op, Errors.transport(false, error.reason._tag))),
255
+ Stream.mapEffect((chunk) => {
256
+ received += chunk.length
257
+ return received > maxBytes ? Effect.fail(tooLarge) : Effect.succeed(chunk)
258
+ })
259
+ )
260
+ }).pipe(
261
+ Effect.withSpan("TelegramBotApi.file", {
262
+ kind: "client",
263
+ attributes: { "http.request.method": "GET", "url.path": "/file/bot<redacted>" }
264
+ })
265
+ )
266
+ )
267
+
268
+ return TelegramBotApi.of({ botId, environment, call, file })
269
+ })
270
+
271
+ /**
272
+ * The client as a layer.
273
+ *
274
+ * @stability unstable
275
+ * @category layers
276
+ * @since 4.1.5
277
+ */
278
+ export const layer = (options: {
279
+ readonly token: Redacted.Redacted<string>
280
+ readonly environment?: Environment | undefined
281
+ readonly apiUrl?: string | undefined
282
+ }): Layer.Layer<TelegramBotApi, ChatError, HttpClient.HttpClient> => Layer.effect(TelegramBotApi, make(options))