@grom.js/effect-tg 0.2.0

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 (54) hide show
  1. package/LICENSE +7 -0
  2. package/README.md +9 -0
  3. package/dist/BotApi.d.ts +27 -0
  4. package/dist/BotApi.d.ts.map +1 -0
  5. package/dist/BotApi.js +14 -0
  6. package/dist/BotApiTransport.d.ts +44 -0
  7. package/dist/BotApiTransport.d.ts.map +1 -0
  8. package/dist/BotApiTransport.js +17 -0
  9. package/dist/BotApiWebhook.d.ts +37 -0
  10. package/dist/BotApiWebhook.d.ts.map +1 -0
  11. package/dist/BotApiWebhook.js +50 -0
  12. package/dist/Chat.d.ts +96 -0
  13. package/dist/Chat.d.ts.map +1 -0
  14. package/dist/Chat.js +48 -0
  15. package/dist/Content.d.ts +43 -0
  16. package/dist/Content.d.ts.map +1 -0
  17. package/dist/Content.js +39 -0
  18. package/dist/InputFile.d.ts +4 -0
  19. package/dist/InputFile.d.ts.map +1 -0
  20. package/dist/InputFile.js +3 -0
  21. package/dist/LinkPreview.d.ts +11 -0
  22. package/dist/LinkPreview.d.ts.map +1 -0
  23. package/dist/LinkPreview.js +20 -0
  24. package/dist/Send.d.ts +25 -0
  25. package/dist/Send.d.ts.map +1 -0
  26. package/dist/Send.js +26 -0
  27. package/dist/Text.d.ts +25 -0
  28. package/dist/Text.d.ts.map +1 -0
  29. package/dist/Text.js +16 -0
  30. package/dist/index.d.ts +10 -0
  31. package/dist/index.d.ts.map +1 -0
  32. package/dist/index.js +9 -0
  33. package/dist/internal/botApi.d.ts +7 -0
  34. package/dist/internal/botApi.d.ts.map +1 -0
  35. package/dist/internal/botApi.js +24 -0
  36. package/dist/internal/botApiMethod.d.ts +8 -0
  37. package/dist/internal/botApiMethod.d.ts.map +1 -0
  38. package/dist/internal/botApiMethod.js +1 -0
  39. package/dist/internal/botApiMethods.gen.d.ts +2026 -0
  40. package/dist/internal/botApiMethods.gen.d.ts.map +1 -0
  41. package/dist/internal/botApiMethods.gen.js +1 -0
  42. package/dist/internal/botApiShape.gen.d.ts +398 -0
  43. package/dist/internal/botApiShape.gen.d.ts.map +1 -0
  44. package/dist/internal/botApiShape.gen.js +1 -0
  45. package/dist/internal/botApiTransport.d.ts +10 -0
  46. package/dist/internal/botApiTransport.d.ts.map +1 -0
  47. package/dist/internal/botApiTransport.js +21 -0
  48. package/dist/internal/botApiTypes.gen.d.ts +3903 -0
  49. package/dist/internal/botApiTypes.gen.d.ts.map +1 -0
  50. package/dist/internal/botApiTypes.gen.js +1 -0
  51. package/dist/internal/chat.d.ts +14 -0
  52. package/dist/internal/chat.d.ts.map +1 -0
  53. package/dist/internal/chat.js +20 -0
  54. package/package.json +57 -0
package/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright 2025–PRESENT Vladislav Deryabkin
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,9 @@
1
+ Effectful library for crafting Telegram bots.
2
+
3
+ > [!WARNING]
4
+ > Work in progress.
5
+
6
+ ## Features
7
+
8
+ - Effectful and typesafe API.
9
+ - Up-to-date and documented Bot API methods and types.
@@ -0,0 +1,27 @@
1
+ import type { MethodParams, MethodResults } from './internal/botApiMethods.gen.ts';
2
+ import type { BotApiShape } from './internal/botApiShape.gen.ts';
3
+ import type * as Types from './internal/botApiTypes.gen.ts';
4
+ import * as Context from 'effect/Context';
5
+ export type { MethodParams, MethodResults, Types };
6
+ declare const BotApi_base: Context.TagClass<BotApi, "@grom.js/effect-tg/BotApi", BotApiShape>;
7
+ export declare class BotApi extends BotApi_base {
8
+ }
9
+ declare const BotApiError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
10
+ readonly _tag: "@grom.js/effect-tg/BotApiError";
11
+ } & Readonly<A>;
12
+ /**
13
+ * Error returned from the Bot API server in case of unsuccessful method call.
14
+ */
15
+ export declare class BotApiError extends BotApiError_base<{
16
+ code: number;
17
+ description: string;
18
+ parameters?: Types.ResponseParameters;
19
+ }> {
20
+ get message(): string;
21
+ }
22
+ export declare const make: (options: {
23
+ transport: {
24
+ sendRequest: (method: string, params: unknown) => import("effect/Effect").Effect<import("./BotApiTransport.ts").BotApiResponse, import("./BotApiTransport.ts").BotApiTransportError>;
25
+ };
26
+ }) => import("effect/Effect").Effect<BotApiShape, never, never>;
27
+ //# sourceMappingURL=BotApi.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BotApi.d.ts","sourceRoot":"","sources":["../src/BotApi.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAA;AAClF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAA;AAChE,OAAO,KAAK,KAAK,KAAK,MAAM,+BAA+B,CAAA;AAC3D,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AAIzC,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,KAAK,EAAE,CAAA;;AAElD,qBAAa,MAAO,SAAQ,WAGzB;CAAG;;;;AAEN;;GAEG;AACH,qBAAa,WAAY,SAAQ,iBAAmD;IAClF,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,UAAU,CAAC,EAAE,KAAK,CAAC,kBAAkB,CAAA;CACtC,CAAC;IACA,IAAa,OAAO,WAEnB;CACF;AAED,eAAO,MAAM,IAAI;;;;+DAAgB,CAAA"}
package/dist/BotApi.js ADDED
@@ -0,0 +1,14 @@
1
+ import * as Context from 'effect/Context';
2
+ import * as Data from 'effect/Data';
3
+ import * as internal from "./internal/botApi.js";
4
+ export class BotApi extends Context.Tag('@grom.js/effect-tg/BotApi')() {
5
+ }
6
+ /**
7
+ * Error returned from the Bot API server in case of unsuccessful method call.
8
+ */
9
+ export class BotApiError extends Data.TaggedError('@grom.js/effect-tg/BotApiError') {
10
+ get message() {
11
+ return `(${this.code}) ${this.description}`;
12
+ }
13
+ }
14
+ export const make = internal.make;
@@ -0,0 +1,44 @@
1
+ import type * as Effect from 'effect/Effect';
2
+ import type * as Types from './internal/botApiTypes.gen.ts';
3
+ import * as Context from 'effect/Context';
4
+ declare const BotApiTransport_base: Context.TagClass<BotApiTransport, "@grom.js/effect-tg/BotApiTransport", {
5
+ sendRequest: (method: string, params: unknown) => Effect.Effect<BotApiResponse, BotApiTransportError>;
6
+ }>;
7
+ export declare class BotApiTransport extends BotApiTransport_base {
8
+ }
9
+ /**
10
+ * @see https://core.telegram.org/bots/api#making-requests
11
+ */
12
+ export type BotApiResponse = {
13
+ ok: true;
14
+ result: unknown;
15
+ description?: string;
16
+ } | {
17
+ ok: false;
18
+ error_code: number;
19
+ description: string;
20
+ parameters?: Types.ResponseParameters;
21
+ };
22
+ declare const BotApiTransportError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
23
+ readonly _tag: "@grom.js/effect-tg/BotApiTransportError";
24
+ } & Readonly<A>;
25
+ /**
26
+ * Error caused by the transport when accessing Bot API.
27
+ */
28
+ export declare class BotApiTransportError extends BotApiTransportError_base<{
29
+ cause: unknown;
30
+ }> {
31
+ }
32
+ export declare const makeWith: (options: {
33
+ makeUrl: (method: string) => URL;
34
+ }) => Effect.Effect<{
35
+ sendRequest: (method: string, params: unknown) => Effect.Effect<BotApiResponse, BotApiTransportError>;
36
+ }, never, import("@effect/platform/HttpClient").HttpClient>;
37
+ export declare const makeProd: (token: string) => Effect.Effect<{
38
+ sendRequest: (method: string, params: unknown) => Effect.Effect<BotApiResponse, BotApiTransportError>;
39
+ }, never, import("@effect/platform/HttpClient").HttpClient>;
40
+ export declare const makeTest: (token: string) => Effect.Effect<{
41
+ sendRequest: (method: string, params: unknown) => Effect.Effect<BotApiResponse, BotApiTransportError>;
42
+ }, never, import("@effect/platform/HttpClient").HttpClient>;
43
+ export {};
44
+ //# sourceMappingURL=BotApiTransport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BotApiTransport.d.ts","sourceRoot":"","sources":["../src/BotApiTransport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAA;AAC5C,OAAO,KAAK,KAAK,KAAK,MAAM,+BAA+B,CAAA;AAC3D,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;;iBAOxB,CACX,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,OAAO,KACZ,MAAM,CAAC,MAAM,CAAC,cAAc,EAAE,oBAAoB,CAAC;;AAN5D,qBAAa,eAAgB,SAAQ,oBAQlC;CACF;AAED;;GAEG;AACH,MAAM,MAAM,cAAc,GACtB;IACA,EAAE,EAAE,IAAI,CAAA;IACR,MAAM,EAAE,OAAO,CAAA;IACf,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB,GAAG;IACF,EAAE,EAAE,KAAK,CAAA;IACT,UAAU,EAAE,MAAM,CAAA;IAClB,WAAW,EAAE,MAAM,CAAA;IACnB,UAAU,CAAC,EAAE,KAAK,CAAC,kBAAkB,CAAA;CACtC,CAAA;;;;AAEH;;GAEG;AACH,qBAAa,oBAAqB,SAAQ,0BAA4D;IACpG,KAAK,EAAE,OAAO,CAAA;CACf,CAAC;CAAG;AAEL,eAAO,MAAM,QAAQ;;;iBA9BJ,CACX,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,OAAO,KACZ,MAAM,CAAC,MAAM,CAAC,cAAc,EAAE,oBAAoB,CAAC;2DA2BnB,CAAA;AAEzC,eAAO,MAAM,QAAQ,GAAI,OAAO,MAAM;iBAhCrB,CACX,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,OAAO,KACZ,MAAM,CAAC,MAAM,CAAC,cAAc,EAAE,oBAAoB,CAAC;2DAiC3D,CAAA;AAED,eAAO,MAAM,QAAQ,GAAI,OAAO,MAAM;iBAtCrB,CACX,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,OAAO,KACZ,MAAM,CAAC,MAAM,CAAC,cAAc,EAAE,oBAAoB,CAAC;2DAuC3D,CAAA"}
@@ -0,0 +1,17 @@
1
+ import * as Context from 'effect/Context';
2
+ import * as Data from 'effect/Data';
3
+ import * as internal from "./internal/botApiTransport.js";
4
+ export class BotApiTransport extends Context.Tag('@grom.js/effect-tg/BotApiTransport')() {
5
+ }
6
+ /**
7
+ * Error caused by the transport when accessing Bot API.
8
+ */
9
+ export class BotApiTransportError extends Data.TaggedError('@grom.js/effect-tg/BotApiTransportError') {
10
+ }
11
+ export const makeWith = internal.makeWith;
12
+ export const makeProd = (token) => (makeWith({
13
+ makeUrl: method => new URL(`https://api.telegram.org/bot${token}/${method}`),
14
+ }));
15
+ export const makeTest = (token) => (makeWith({
16
+ makeUrl: method => new URL(`https://api.telegram.org/bot${token}/test/${method}`),
17
+ }));
@@ -0,0 +1,37 @@
1
+ /**
2
+ * This module implements Telegram Bot API webhook requests verification.
3
+ *
4
+ * @see https://core.telegram.org/bots/api#setwebhook
5
+ */
6
+ import type * as BotApi from './BotApi.ts';
7
+ import * as HttpApiMiddleware from '@effect/platform/HttpApiMiddleware';
8
+ import * as Context from 'effect/Context';
9
+ import * as Layer from 'effect/Layer';
10
+ import * as Redacted from 'effect/Redacted';
11
+ import * as Schema from 'effect/Schema';
12
+ export declare const SECRET_HEADER = "x-telegram-bot-api-secret-token";
13
+ declare const VerificationFailedError_base: Schema.TaggedErrorClass<VerificationFailedError, "@grom.js/effect-tg/BotApiWebhook/VerificationFailedError", {
14
+ readonly _tag: Schema.tag<"@grom.js/effect-tg/BotApiWebhook/VerificationFailedError">;
15
+ } & {
16
+ reason: Schema.Literal<["MISSING_HEADER", "INVALID_SECRET", "INVALID_REQUEST", "BROKEN_TRANSPORT"]>;
17
+ }>;
18
+ export declare class VerificationFailedError extends VerificationFailedError_base {
19
+ }
20
+ declare const Update_base: Context.TagClass<Update, "@grom.js/effect-tg/BotApiWebhook/Update", BotApi.Types.Update>;
21
+ export declare class Update extends Update_base {
22
+ }
23
+ declare const VerifyMiddleware_base: HttpApiMiddleware.TagClass.Base<VerifyMiddleware, "@grom.js/effect-tg/BotApiWebhook/VerifyMiddleware", {
24
+ readonly optional: false;
25
+ readonly failure: typeof VerificationFailedError;
26
+ readonly provides: typeof Update;
27
+ }, HttpApiMiddleware.HttpApiMiddleware<BotApi.Types.Update, VerificationFailedError>>;
28
+ export declare class VerifyMiddleware extends VerifyMiddleware_base {
29
+ static live(options: {
30
+ /**
31
+ * Telegram webhook secret token.
32
+ */
33
+ secret: Redacted.Redacted<string>;
34
+ }): Layer.Layer<VerifyMiddleware, never, never>;
35
+ }
36
+ export {};
37
+ //# sourceMappingURL=BotApiWebhook.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BotApiWebhook.d.ts","sourceRoot":"","sources":["../src/BotApiWebhook.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,KAAK,MAAM,MAAM,aAAa,CAAA;AAG1C,OAAO,KAAK,iBAAiB,MAAM,oCAAoC,CAAA;AAGvE,OAAO,KAAK,OAAO,MAAM,gBAAgB,CAAA;AAEzC,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAErC,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAC3C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,eAAO,MAAM,aAAa,oCAAoC,CAAA;;;;;;AAG9D,qBAAa,uBAAwB,SAAQ,4BAc5C;CAAG;;AAEJ,qBAAa,MAAO,SAAQ,WAGzB;CAAG;;;;;;AAEN,qBAAa,gBAAiB,SAAQ,qBAOrC;WACe,IAAI,CAAC,OAAO,EAAE;QAC1B;;WAEG;QACH,MAAM,EAAE,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;KAClC;CA+BF"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * This module implements Telegram Bot API webhook requests verification.
3
+ *
4
+ * @see https://core.telegram.org/bots/api#setwebhook
5
+ */
6
+ import { Buffer } from 'node:buffer';
7
+ import * as crypto from 'node:crypto';
8
+ import * as HttpApiMiddleware from '@effect/platform/HttpApiMiddleware';
9
+ import * as HttpApiSchema from '@effect/platform/HttpApiSchema';
10
+ import * as HttpServerRequest from '@effect/platform/HttpServerRequest';
11
+ import * as Context from 'effect/Context';
12
+ import * as Effect from 'effect/Effect';
13
+ import * as Layer from 'effect/Layer';
14
+ import * as Match from 'effect/Match';
15
+ import * as Redacted from 'effect/Redacted';
16
+ import * as Schema from 'effect/Schema';
17
+ export const SECRET_HEADER = 'x-telegram-bot-api-secret-token';
18
+ // eslint-disable-next-line unicorn/throw-new-error
19
+ export class VerificationFailedError extends Schema.TaggedError()('@grom.js/effect-tg/BotApiWebhook/VerificationFailedError', Schema.Struct({
20
+ reason: Schema.Literal('MISSING_HEADER', 'INVALID_SECRET', 'INVALID_REQUEST', 'BROKEN_TRANSPORT'),
21
+ }), HttpApiSchema.annotations({
22
+ status: 401,
23
+ description: 'Webhook verification failed.',
24
+ })) {
25
+ }
26
+ export class Update extends Context.Tag('@grom.js/effect-tg/BotApiWebhook/Update')() {
27
+ }
28
+ export class VerifyMiddleware extends HttpApiMiddleware.Tag()('@grom.js/effect-tg/BotApiWebhook/VerifyMiddleware', {
29
+ optional: false,
30
+ failure: VerificationFailedError,
31
+ provides: Update,
32
+ }) {
33
+ static live(options) {
34
+ return Layer.succeed(VerifyMiddleware, Effect.gen(function* () {
35
+ const req = yield* HttpServerRequest.HttpServerRequest;
36
+ const actual = req.headers[SECRET_HEADER];
37
+ if (actual == null) {
38
+ return yield* new VerificationFailedError({ reason: 'MISSING_HEADER' });
39
+ }
40
+ const equal = crypto.timingSafeEqual(Buffer.from(Redacted.value(options.secret)), Buffer.from(actual));
41
+ if (!equal) {
42
+ return yield* new VerificationFailedError({ reason: 'INVALID_SECRET' });
43
+ }
44
+ const update = yield* req.json.pipe(Effect.catchTag('RequestError', error => (new VerificationFailedError({
45
+ reason: Match.value(error.reason).pipe(Match.when('Decode', () => 'INVALID_REQUEST'), Match.when('Transport', () => 'BROKEN_TRANSPORT'), Match.exhaustive),
46
+ }))));
47
+ return update;
48
+ }));
49
+ }
50
+ }
package/dist/Chat.d.ts ADDED
@@ -0,0 +1,96 @@
1
+ import * as Data from 'effect/Data';
2
+ export type Chat = PeerUser | PeerGroup | PeerChannel | PeerSupergroup | PublicChannel | PublicSupergroup | ForumTopic | ChannelDm;
3
+ declare const PeerUser_base: new (options: {
4
+ id: number;
5
+ }) => {
6
+ readonly id: number;
7
+ readonly dialogId: number;
8
+ sendParams: () => {
9
+ chat_id: number | string;
10
+ message_thread_id?: number | undefined;
11
+ direct_messages_topic_id?: number | undefined;
12
+ };
13
+ };
14
+ export declare class PeerUser extends PeerUser_base {
15
+ }
16
+ declare const PeerGroup_base: new (options: {
17
+ id: number;
18
+ }) => {
19
+ readonly id: number;
20
+ readonly dialogId: number;
21
+ sendParams: () => {
22
+ chat_id: number | string;
23
+ message_thread_id?: number | undefined;
24
+ direct_messages_topic_id?: number | undefined;
25
+ };
26
+ };
27
+ export declare class PeerGroup extends PeerGroup_base {
28
+ }
29
+ declare const PeerChannel_base: new (options: {
30
+ id: number;
31
+ }) => {
32
+ readonly id: number;
33
+ readonly dialogId: number;
34
+ sendParams: () => {
35
+ chat_id: number | string;
36
+ message_thread_id?: number | undefined;
37
+ direct_messages_topic_id?: number | undefined;
38
+ };
39
+ };
40
+ export declare class PeerChannel extends PeerChannel_base {
41
+ }
42
+ declare const PeerSupergroup_base: new (options: {
43
+ id: number;
44
+ }) => {
45
+ readonly id: number;
46
+ readonly dialogId: number;
47
+ sendParams: () => {
48
+ chat_id: number | string;
49
+ message_thread_id?: number | undefined;
50
+ direct_messages_topic_id?: number | undefined;
51
+ };
52
+ };
53
+ export declare class PeerSupergroup extends PeerSupergroup_base {
54
+ }
55
+ export declare class PublicChannel extends Data.Class<{
56
+ username: string;
57
+ }> {
58
+ sendParams(): {
59
+ chat_id: string;
60
+ };
61
+ }
62
+ export declare class PublicSupergroup extends Data.Class<{
63
+ username: string;
64
+ }> {
65
+ sendParams(): {
66
+ chat_id: string;
67
+ };
68
+ }
69
+ export declare class ForumTopic extends Data.Class<{
70
+ forum: PeerSupergroup | PublicSupergroup;
71
+ topicId: number;
72
+ }> {
73
+ sendParams(): {
74
+ message_thread_id: number;
75
+ chat_id: number | string;
76
+ direct_messages_topic_id?: number | undefined;
77
+ } | {
78
+ message_thread_id: number;
79
+ chat_id: string;
80
+ };
81
+ }
82
+ export declare class ChannelDm extends Data.Class<{
83
+ channel: PeerChannel | PublicChannel;
84
+ userId: number;
85
+ }> {
86
+ sendParams(): {
87
+ direct_messages_topic_id: number;
88
+ chat_id: number | string;
89
+ message_thread_id?: number | undefined;
90
+ } | {
91
+ direct_messages_topic_id: number;
92
+ chat_id: string;
93
+ };
94
+ }
95
+ export {};
96
+ //# sourceMappingURL=Chat.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Chat.d.ts","sourceRoot":"","sources":["../src/Chat.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,aAAa,CAAA;AAGnC,MAAM,MAAM,IAAI,GACV,QAAQ,GACR,SAAS,GACT,WAAW,GACX,cAAc,GACd,aAAa,GACb,gBAAgB,GAChB,UAAU,GACV,SAAS,CAAA;;;;;;;;;;;;AAEf,qBAAa,QAAS,SAAQ,aAG5B;CAAG;;;;;;;;;;;;AAEL,qBAAa,SAAU,SAAQ,cAG7B;CAAG;;;;;;;;;;;;AAEL,qBAAa,WAAY,SAAQ,gBAG/B;CAAG;;;;;;;;;;;;AAEL,qBAAa,cAAe,SAAQ,mBAGlC;CAAG;AAEL,qBAAa,aAAc,SAAQ,IAAI,CAAC,KAAK,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;IACjE,UAAU;;;CAGX;AAED,qBAAa,gBAAiB,SAAQ,IAAI,CAAC,KAAK,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;IACpE,UAAU;;;CAGX;AAED,qBAAa,UAAW,SAAQ,IAAI,CAAC,KAAK,CAAC;IACzC,KAAK,EAAE,cAAc,GAAG,gBAAgB,CAAA;IACxC,OAAO,EAAE,MAAM,CAAA;CAChB,CAAC;IACA,UAAU;;;;;;;;CAMX;AAED,qBAAa,SAAU,SAAQ,IAAI,CAAC,KAAK,CAAC;IACxC,OAAO,EAAE,WAAW,GAAG,aAAa,CAAA;IACpC,MAAM,EAAE,MAAM,CAAA;CACf,CAAC;IACA,UAAU;;;;;;;;CAMX"}
package/dist/Chat.js ADDED
@@ -0,0 +1,48 @@
1
+ import * as Data from 'effect/Data';
2
+ import * as internal from "./internal/chat.js";
3
+ export class PeerUser extends internal.Peer({
4
+ validatePeerId: id => (id >= 1 && id <= 0xFFFFFFFFFF),
5
+ peerIdToDialogId: id => id,
6
+ }) {
7
+ }
8
+ export class PeerGroup extends internal.Peer({
9
+ validatePeerId: id => (id >= 1 && id <= 999999999999),
10
+ peerIdToDialogId: id => -id,
11
+ }) {
12
+ }
13
+ export class PeerChannel extends internal.Peer({
14
+ validatePeerId: id => (id >= 1 && id <= 997852516352),
15
+ peerIdToDialogId: id => -(1000000000000 + id),
16
+ }) {
17
+ }
18
+ export class PeerSupergroup extends internal.Peer({
19
+ validatePeerId: id => (id >= 1 && id <= 997852516352),
20
+ peerIdToDialogId: id => -(1000000000000 + id),
21
+ }) {
22
+ }
23
+ export class PublicChannel extends Data.Class {
24
+ sendParams() {
25
+ return { chat_id: this.username };
26
+ }
27
+ }
28
+ export class PublicSupergroup extends Data.Class {
29
+ sendParams() {
30
+ return { chat_id: this.username };
31
+ }
32
+ }
33
+ export class ForumTopic extends Data.Class {
34
+ sendParams() {
35
+ return {
36
+ ...this.forum.sendParams(),
37
+ message_thread_id: this.topicId,
38
+ };
39
+ }
40
+ }
41
+ export class ChannelDm extends Data.Class {
42
+ sendParams() {
43
+ return {
44
+ ...this.channel.sendParams(),
45
+ direct_messages_topic_id: this.userId,
46
+ };
47
+ }
48
+ }
@@ -0,0 +1,43 @@
1
+ import type { MethodParams } from './BotApi.ts';
2
+ import type { InputFile } from './InputFile.ts';
3
+ import type { LinkPreview } from './LinkPreview.ts';
4
+ import type { Text as Text$ } from './Text.ts';
5
+ import * as Option from 'effect/Option';
6
+ /**
7
+ * Content of a message to be sent.
8
+ *
9
+ * @see {@link https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1_input_message_content.html td.td_api.InputMessageContent}
10
+ */
11
+ export type Content = Text | Photo;
12
+ declare const Text_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => Readonly<A> & {
13
+ readonly _tag: "text";
14
+ };
15
+ /**
16
+ * Content of a text message.
17
+ *
18
+ * @see {@link https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1input_message_text.html td.td_api.inputMessageText}
19
+ */
20
+ export declare class Text extends Text_base<{
21
+ text: Text$;
22
+ linkPreview: Option.Option<LinkPreview>;
23
+ }> {
24
+ sendParams(): Pick<MethodParams['sendMessage'], 'text' | 'entities' | 'parse_mode' | 'link_preview_options'>;
25
+ }
26
+ declare const Photo_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => Readonly<A> & {
27
+ readonly _tag: "photo";
28
+ };
29
+ /**
30
+ * Content of a photo message.
31
+ *
32
+ * @see {@link https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1input_message_photo.html td.td_api.inputMessagePhoto}
33
+ */
34
+ export declare class Photo extends Photo_base<{
35
+ file: InputFile;
36
+ caption: Option.Option<Text>;
37
+ layout: 'caption-above' | 'caption-below';
38
+ spoiler: boolean;
39
+ }> {
40
+ sendParams(): Pick<MethodParams['sendPhoto'], 'photo' | 'caption' | 'caption_entities' | 'parse_mode' | 'show_caption_above_media' | 'has_spoiler'>;
41
+ }
42
+ export {};
43
+ //# sourceMappingURL=Content.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Content.d.ts","sourceRoot":"","sources":["../src/Content.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,KAAK,EAAE,IAAI,IAAI,KAAK,EAAE,MAAM,WAAW,CAAA;AAE9C,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC;;;;GAIG;AACH,MAAM,MAAM,OAAO,GACb,IAAI,GACJ,KAAK,CAAA;;;;AAEX;;;;GAIG;AACH,qBAAa,IAAK,SAAQ,UAAyB;IACjD,IAAI,EAAE,KAAK,CAAA;IACX,WAAW,EAAE,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,CAAA;CACxC,CAAC;IACA,UAAU,IAAI,IAAI,CAAC,YAAY,CAAC,aAAa,CAAC,EAAE,MAAM,GAAG,UAAU,GAAG,YAAY,GAAG,sBAAsB,CAAC;CAS7G;;;;AAED;;;;GAIG;AACH,qBAAa,KAAM,SAAQ,WAA0B;IACnD,IAAI,EAAE,SAAS,CAAA;IACf,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IAC5B,MAAM,EAAE,eAAe,GAAG,eAAe,CAAA;IACzC,OAAO,EAAE,OAAO,CAAA;CACjB,CAAC;IACA,UAAU,IAAI,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,EAAE,OAAO,GAAG,SAAS,GAAG,kBAAkB,GAAG,YAAY,GAAG,0BAA0B,GAAG,aAAa,CAAC;CAkBpJ"}
@@ -0,0 +1,39 @@
1
+ import * as Data from 'effect/Data';
2
+ import * as Option from 'effect/Option';
3
+ /**
4
+ * Content of a text message.
5
+ *
6
+ * @see {@link https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1input_message_text.html td.td_api.inputMessageText}
7
+ */
8
+ export class Text extends Data.TaggedClass('text') {
9
+ sendParams() {
10
+ return {
11
+ ...this.text.sendParams(),
12
+ link_preview_options: Option.match(this.linkPreview, {
13
+ onNone: () => ({ is_disabled: true }),
14
+ onSome: lp => lp.options(),
15
+ }),
16
+ };
17
+ }
18
+ }
19
+ /**
20
+ * Content of a photo message.
21
+ *
22
+ * @see {@link https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1input_message_photo.html td.td_api.inputMessagePhoto}
23
+ */
24
+ export class Photo extends Data.TaggedClass('photo') {
25
+ sendParams() {
26
+ const { text: caption, entities: caption_entities, parse_mode, } = Option.match(this.caption, {
27
+ onNone: () => ({}),
28
+ onSome: caption => caption.sendParams(),
29
+ });
30
+ return {
31
+ photo: this.file,
32
+ caption,
33
+ caption_entities,
34
+ parse_mode,
35
+ show_caption_above_media: this.layout === 'caption-above',
36
+ has_spoiler: this.spoiler,
37
+ };
38
+ }
39
+ }
@@ -0,0 +1,4 @@
1
+ /** @todo */
2
+ export declare class InputFile {
3
+ }
4
+ //# sourceMappingURL=InputFile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InputFile.d.ts","sourceRoot":"","sources":["../src/InputFile.ts"],"names":[],"mappings":"AAAA,YAAY;AACZ,qBAAa,SAAS;CAAG"}
@@ -0,0 +1,3 @@
1
+ /** @todo */
2
+ export class InputFile {
3
+ }
@@ -0,0 +1,11 @@
1
+ import type { Types } from './BotApi.ts';
2
+ import * as Data from 'effect/Data';
3
+ import * as Option from 'effect/Option';
4
+ export declare class LinkPreview extends Data.Class<{
5
+ url: Option.Option<string>;
6
+ position: 'above' | 'below';
7
+ mediaSize: 'large' | 'small';
8
+ }> {
9
+ options(): Types.LinkPreviewOptions;
10
+ }
11
+ //# sourceMappingURL=LinkPreview.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LinkPreview.d.ts","sourceRoot":"","sources":["../src/LinkPreview.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,KAAK,IAAI,MAAM,aAAa,CAAA;AACnC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,qBAAa,WAAY,SAAQ,IAAI,CAAC,KAAK,CAAC;IAC1C,GAAG,EAAE,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;IAC1B,QAAQ,EAAE,OAAO,GAAG,OAAO,CAAA;IAC3B,SAAS,EAAE,OAAO,GAAG,OAAO,CAAA;CAC7B,CAAC;IACA,OAAO,IAAI,KAAK,CAAC,kBAAkB;CAgBpC"}
@@ -0,0 +1,20 @@
1
+ import * as Data from 'effect/Data';
2
+ import * as Option from 'effect/Option';
3
+ export class LinkPreview extends Data.Class {
4
+ options() {
5
+ const opts = { is_disabled: false };
6
+ if (Option.isSome(this.url)) {
7
+ opts.url = this.url.value;
8
+ }
9
+ if (this.position === 'above') {
10
+ opts.show_above_text = true;
11
+ }
12
+ if (this.mediaSize === 'large') {
13
+ opts.prefer_large_media = true;
14
+ }
15
+ else if (this.mediaSize === 'small') {
16
+ opts.prefer_small_media = true;
17
+ }
18
+ return opts;
19
+ }
20
+ }
package/dist/Send.d.ts ADDED
@@ -0,0 +1,25 @@
1
+ import type { MethodParams } from './BotApi.ts';
2
+ import type { Chat } from './Chat.ts';
3
+ import type { Content } from './Content.ts';
4
+ import * as Data from 'effect/Data';
5
+ import * as Effect from 'effect/Effect';
6
+ import * as BotApi from './BotApi.ts';
7
+ /**
8
+ * Creates an effect that sends a message.
9
+ *
10
+ * @todo Reply options are not supported.
11
+ * @todo Reply markup is not supported.
12
+ */
13
+ export declare const message: (args: {
14
+ chat: Chat;
15
+ content: Content;
16
+ options?: Options;
17
+ }) => Effect.Effect<BotApi.Types.Message, import("./BotApiTransport.ts").BotApiTransportError | BotApi.BotApiError, BotApi.BotApi>;
18
+ export declare class Options extends Data.Class<{
19
+ disableNotification?: boolean;
20
+ protectContent?: boolean;
21
+ allowPaidBroadcast?: boolean;
22
+ }> {
23
+ sendParams(): Pick<MethodParams['sendMessage'], 'disable_notification' | 'protect_content' | 'allow_paid_broadcast'>;
24
+ }
25
+ //# sourceMappingURL=Send.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Send.d.ts","sourceRoot":"","sources":["../src/Send.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC/C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACrC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,KAAK,IAAI,MAAM,aAAa,CAAA;AACnC,OAAO,KAAK,MAAM,MAAM,eAAe,CAAA;AAEvC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAErC;;;;;GAKG;AACH,eAAO,MAAM,OAAO,GAAI,MAAM;IAC5B,IAAI,EAAE,IAAI,CAAA;IACV,OAAO,EAAE,OAAO,CAAA;IAChB,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB,iIAcA,CAAA;AAED,qBAAa,OAAQ,SAAQ,IAAI,CAAC,KAAK,CAAC;IACtC,mBAAmB,CAAC,EAAE,OAAO,CAAA;IAC7B,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB,kBAAkB,CAAC,EAAE,OAAO,CAAA;CAC7B,CAAC;IACA,UAAU,IAAI,IAAI,CAAC,YAAY,CAAC,aAAa,CAAC,EAAE,sBAAsB,GAAG,iBAAiB,GAAG,sBAAsB,CAAC;CAOrH"}
package/dist/Send.js ADDED
@@ -0,0 +1,26 @@
1
+ import * as Data from 'effect/Data';
2
+ import * as Effect from 'effect/Effect';
3
+ import * as Match from 'effect/Match';
4
+ import * as BotApi from "./BotApi.js";
5
+ /**
6
+ * Creates an effect that sends a message.
7
+ *
8
+ * @todo Reply options are not supported.
9
+ * @todo Reply markup is not supported.
10
+ */
11
+ export const message = (args) => {
12
+ const rest = {
13
+ ...args.chat.sendParams(),
14
+ ...args.options?.sendParams(),
15
+ };
16
+ return BotApi.BotApi.pipe(Effect.andThen(api => Match.value(args.content).pipe(Match.tag('text', content => api.sendMessage({ ...rest, ...content.sendParams() })), Match.tag('photo', content => api.sendPhoto({ ...rest, ...content.sendParams() })), Match.exhaustive)));
17
+ };
18
+ export class Options extends Data.Class {
19
+ sendParams() {
20
+ return {
21
+ disable_notification: this.disableNotification || undefined,
22
+ protect_content: this.protectContent || undefined,
23
+ allow_paid_broadcast: this.allowPaidBroadcast || undefined,
24
+ };
25
+ }
26
+ }
package/dist/Text.d.ts ADDED
@@ -0,0 +1,25 @@
1
+ import type { MethodParams, Types } from './BotApi.ts';
2
+ import * as Data from 'effect/Data';
3
+ /**
4
+ * Formatted text.
5
+ */
6
+ export type Text = Plain | Html | Markdown;
7
+ export declare class Plain extends Data.Class<{
8
+ text: string;
9
+ entities?: Array<Types.MessageEntity>;
10
+ }> {
11
+ sendParams(): SendParams;
12
+ }
13
+ export declare class Html extends Data.Class<{
14
+ html: string;
15
+ }> {
16
+ sendParams(): SendParams;
17
+ }
18
+ export declare class Markdown extends Data.Class<{
19
+ markdown: string;
20
+ }> {
21
+ sendParams(): SendParams;
22
+ }
23
+ type SendParams = Pick<MethodParams['sendMessage'], 'text' | 'entities' | 'parse_mode'>;
24
+ export {};
25
+ //# sourceMappingURL=Text.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Text.d.ts","sourceRoot":"","sources":["../src/Text.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AACtD,OAAO,KAAK,IAAI,MAAM,aAAa,CAAA;AAEnC;;GAEG;AACH,MAAM,MAAM,IAAI,GACV,KAAK,GACL,IAAI,GACJ,QAAQ,CAAA;AAEd,qBAAa,KAAM,SAAQ,IAAI,CAAC,KAAK,CAAC;IACpC,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,aAAa,CAAC,CAAA;CACtC,CAAC;IACA,UAAU,IAAI,UAAU;CAGzB;AAED,qBAAa,IAAK,SAAQ,IAAI,CAAC,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;IACpD,UAAU,IAAI,UAAU;CAGzB;AAED,qBAAa,QAAS,SAAQ,IAAI,CAAC,KAAK,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;IAC5D,UAAU,IAAI,UAAU;CAGzB;AAED,KAAK,UAAU,GAAG,IAAI,CAAC,YAAY,CAAC,aAAa,CAAC,EAAE,MAAM,GAAG,UAAU,GAAG,YAAY,CAAC,CAAA"}
package/dist/Text.js ADDED
@@ -0,0 +1,16 @@
1
+ import * as Data from 'effect/Data';
2
+ export class Plain extends Data.Class {
3
+ sendParams() {
4
+ return { text: this.text, entities: this.entities };
5
+ }
6
+ }
7
+ export class Html extends Data.Class {
8
+ sendParams() {
9
+ return { text: this.html, parse_mode: 'HTML' };
10
+ }
11
+ }
12
+ export class Markdown extends Data.Class {
13
+ sendParams() {
14
+ return { text: this.markdown, parse_mode: 'MarkdownV2' };
15
+ }
16
+ }
@@ -0,0 +1,10 @@
1
+ export * as BotApi from './BotApi.ts';
2
+ export * as BotApiTransport from './BotApiTransport.ts';
3
+ export * as BotApiWebhook from './BotApiWebhook.ts';
4
+ export * as Chat from './Chat.ts';
5
+ export * as Content from './Content.ts';
6
+ export * as InputFile from './InputFile.ts';
7
+ export * as LinkPreview from './LinkPreview.ts';
8
+ export * as Send from './Send.ts';
9
+ export * as Text from './Text.ts';
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AACrC,OAAO,KAAK,eAAe,MAAM,sBAAsB,CAAA;AACvD,OAAO,KAAK,aAAa,MAAM,oBAAoB,CAAA;AACnD,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AACjC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC,OAAO,KAAK,SAAS,MAAM,gBAAgB,CAAA;AAC3C,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAA;AAC/C,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AACjC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ export * as BotApi from "./BotApi.js";
2
+ export * as BotApiTransport from "./BotApiTransport.js";
3
+ export * as BotApiWebhook from "./BotApiWebhook.js";
4
+ export * as Chat from "./Chat.js";
5
+ export * as Content from "./Content.js";
6
+ export * as InputFile from "./InputFile.js";
7
+ export * as LinkPreview from "./LinkPreview.js";
8
+ export * as Send from "./Send.js";
9
+ export * as Text from "./Text.js";