@im-more/dsh-telegram 0.0.0-stage → 0.1.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 (122) hide show
  1. package/LICENSE +21 -0
  2. package/cordis.patch.yml +10 -0
  3. package/lib/index.js +2067 -0
  4. package/lib/index.js.map +1 -0
  5. package/lib/types/bot.d.ts +70 -0
  6. package/lib/types/bot.d.ts.map +1 -0
  7. package/lib/types/bot.js +231 -0
  8. package/lib/types/bot.js.map +1 -0
  9. package/lib/types/config.d.ts +34 -0
  10. package/lib/types/config.d.ts.map +1 -0
  11. package/lib/types/config.js +41 -0
  12. package/lib/types/config.js.map +1 -0
  13. package/lib/types/decode.d.ts +39 -0
  14. package/lib/types/decode.d.ts.map +1 -0
  15. package/lib/types/decode.js +382 -0
  16. package/lib/types/decode.js.map +1 -0
  17. package/lib/types/errors.d.ts +33 -0
  18. package/lib/types/errors.d.ts.map +1 -0
  19. package/lib/types/errors.js +89 -0
  20. package/lib/types/errors.js.map +1 -0
  21. package/lib/types/identity.d.ts +19 -0
  22. package/lib/types/identity.d.ts.map +1 -0
  23. package/lib/types/identity.js +34 -0
  24. package/lib/types/identity.js.map +1 -0
  25. package/lib/types/index.d.ts +10 -0
  26. package/lib/types/index.d.ts.map +1 -0
  27. package/lib/types/index.js +8 -0
  28. package/lib/types/index.js.map +1 -0
  29. package/lib/types/media.d.ts +38 -0
  30. package/lib/types/media.d.ts.map +1 -0
  31. package/lib/types/media.js +65 -0
  32. package/lib/types/media.js.map +1 -0
  33. package/lib/types/modes/html.d.ts +16 -0
  34. package/lib/types/modes/html.d.ts.map +1 -0
  35. package/lib/types/modes/html.js +155 -0
  36. package/lib/types/modes/html.js.map +1 -0
  37. package/lib/types/modes/plain.d.ts +14 -0
  38. package/lib/types/modes/plain.d.ts.map +1 -0
  39. package/lib/types/modes/plain.js +56 -0
  40. package/lib/types/modes/plain.js.map +1 -0
  41. package/lib/types/modes/shared.d.ts +140 -0
  42. package/lib/types/modes/shared.d.ts.map +1 -0
  43. package/lib/types/modes/shared.js +405 -0
  44. package/lib/types/modes/shared.js.map +1 -0
  45. package/lib/types/polling.d.ts +26 -0
  46. package/lib/types/polling.d.ts.map +1 -0
  47. package/lib/types/polling.js +149 -0
  48. package/lib/types/polling.js.map +1 -0
  49. package/lib/types/request.d.ts +67 -0
  50. package/lib/types/request.d.ts.map +1 -0
  51. package/lib/types/request.js +158 -0
  52. package/lib/types/request.js.map +1 -0
  53. package/lib/types/secret.d.ts +27 -0
  54. package/lib/types/secret.d.ts.map +1 -0
  55. package/lib/types/secret.js +39 -0
  56. package/lib/types/secret.js.map +1 -0
  57. package/lib/types/send.d.ts +48 -0
  58. package/lib/types/send.d.ts.map +1 -0
  59. package/lib/types/send.js +326 -0
  60. package/lib/types/send.js.map +1 -0
  61. package/lib/types/types/game.d.ts +102 -0
  62. package/lib/types/types/game.d.ts.map +1 -0
  63. package/lib/types/types/game.js +5 -0
  64. package/lib/types/types/game.js.map +1 -0
  65. package/lib/types/types/index.d.ts +2751 -0
  66. package/lib/types/types/index.d.ts.map +1 -0
  67. package/lib/types/types/index.js +88 -0
  68. package/lib/types/types/index.js.map +1 -0
  69. package/lib/types/types/inline.d.ts +796 -0
  70. package/lib/types/types/inline.d.ts.map +1 -0
  71. package/lib/types/types/inline.js +4 -0
  72. package/lib/types/types/inline.js.map +1 -0
  73. package/lib/types/types/internal.d.ts +32 -0
  74. package/lib/types/types/internal.d.ts.map +1 -0
  75. package/lib/types/types/internal.js +30 -0
  76. package/lib/types/types/internal.js.map +1 -0
  77. package/lib/types/types/passport.d.ts +229 -0
  78. package/lib/types/types/passport.d.ts.map +1 -0
  79. package/lib/types/types/passport.js +3 -0
  80. package/lib/types/types/passport.js.map +1 -0
  81. package/lib/types/types/payment.d.ts +285 -0
  82. package/lib/types/types/payment.d.ts.map +1 -0
  83. package/lib/types/types/payment.js +6 -0
  84. package/lib/types/types/payment.js.map +1 -0
  85. package/lib/types/types/sticker.d.ts +221 -0
  86. package/lib/types/types/sticker.d.ts.map +1 -0
  87. package/lib/types/types/sticker.js +11 -0
  88. package/lib/types/types/sticker.js.map +1 -0
  89. package/lib/types/types/update.d.ts +97 -0
  90. package/lib/types/types/update.d.ts.map +1 -0
  91. package/lib/types/types/update.js +6 -0
  92. package/lib/types/types/update.js.map +1 -0
  93. package/lib/types/webhook.d.ts +29 -0
  94. package/lib/types/webhook.d.ts.map +1 -0
  95. package/lib/types/webhook.js +129 -0
  96. package/lib/types/webhook.js.map +1 -0
  97. package/package.json +61 -3
  98. package/src/bot.ts +349 -0
  99. package/src/config.ts +73 -0
  100. package/src/decode.ts +472 -0
  101. package/src/errors.ts +103 -0
  102. package/src/identity.ts +41 -0
  103. package/src/index.ts +14 -0
  104. package/src/media.ts +79 -0
  105. package/src/modes/html.ts +193 -0
  106. package/src/modes/plain.ts +75 -0
  107. package/src/modes/shared.ts +505 -0
  108. package/src/polling.ts +176 -0
  109. package/src/request.ts +224 -0
  110. package/src/secret.ts +46 -0
  111. package/src/send.ts +454 -0
  112. package/src/types/.eslintrc.yml +2 -0
  113. package/src/types/game.ts +112 -0
  114. package/src/types/index.ts +3028 -0
  115. package/src/types/inline.ts +857 -0
  116. package/src/types/internal.ts +64 -0
  117. package/src/types/passport.ts +256 -0
  118. package/src/types/payment.ts +304 -0
  119. package/src/types/sticker.ts +244 -0
  120. package/src/types/update.ts +107 -0
  121. package/src/webhook.ts +168 -0
  122. package/README.md +0 -3
@@ -0,0 +1,97 @@
1
+ import { InputFile, Integer } from './index.ts';
2
+ /**
3
+ * This object represents an incoming update. At most one of the optional parameters can be present in any given update.
4
+ * @see https://core.telegram.org/bots/api#update
5
+ */
6
+ export interface Update {
7
+ /** The update's unique identifier. Update identifiers start from a certain positive number and increase sequentially. This ID becomes especially handy if you're using Webhooks, since it allows you to ignore repeated updates or to restore the correct update sequence, should they get out of order. If there are no new updates for at least a week, then identifier of the next update will be chosen randomly instead of sequentially. */
8
+ update_id?: Integer;
9
+ }
10
+ export interface GetUpdatesPayload {
11
+ /** Identifier of the first update to be returned. Must be greater by one than the highest among the identifiers of previously received updates. By default, updates starting with the earliest unconfirmed update are returned. An update is considered confirmed as soon as getUpdates is called with an offset higher than its update_id. The negative offset can be specified to retrieve updates starting from -offset update from the end of the updates queue. All previous updates will forgotten. */
12
+ offset?: Integer;
13
+ /** Limits the number of updates to be retrieved. Values between 1-100 are accepted. Defaults to 100. */
14
+ limit?: Integer;
15
+ /** Timeout in seconds for long polling. Defaults to 0, i.e. usual short polling. Should be positive, short polling should be used for testing purposes only. */
16
+ timeout?: Integer;
17
+ /**
18
+ * A JSON-serialized list of the update types you want your bot to receive. For example, specify ["message", "edited_channel_post", "callback_query"] to only receive updates of these types. See Update for a complete list of available update types. Specify an empty list to receive all update types except chat_member (default). If not specified, the previous setting will be used.
19
+ * Please note that this parameter doesn't affect updates created before the call to the getUpdates, so unwanted updates may be received for a short period of time.
20
+ */
21
+ allowed_updates?: string[];
22
+ }
23
+ export interface SetWebhookPayload {
24
+ /** HTTPS url to send updates to. Use an empty string to remove webhook integration */
25
+ url?: string;
26
+ /** Upload your public key certificate so that the root certificate in use can be checked. See our self-signed guide for details. */
27
+ certificate?: InputFile;
28
+ /** The fixed IP address which will be used to send webhook requests instead of the IP address resolved through DNS */
29
+ ip_address?: string;
30
+ /** Maximum allowed number of simultaneous HTTPS connections to the webhook for update delivery, 1-100. Defaults to 40. Use lower values to limit the load on your bot's server, and higher values to increase your bot's throughput. */
31
+ max_connections?: Integer;
32
+ /**
33
+ * A JSON-serialized list of the update types you want your bot to receive. For example, specify ["message", "edited_channel_post", "callback_query"] to only receive updates of these types. See Update for a complete list of available update types. Specify an empty list to receive all update types except chat_member (default). If not specified, the previous setting will be used.
34
+ *
35
+ * Please note that this parameter doesn't affect updates created before the call to the setWebhook, so unwanted updates may be received for a short period of time.
36
+ */
37
+ allowed_updates?: string[];
38
+ /** Pass True to drop all pending updates */
39
+ drop_pending_updates?: boolean;
40
+ /** A secret token to be sent in a header “X-Telegram-Bot-Api-Secret-Token” in every webhook request, 1-256 characters. Only characters A-Z, a-z, 0-9, _ and - are allowed. The header is useful to ensure that the request comes from a webhook set by you. */
41
+ secret_token?: string;
42
+ }
43
+ export interface DeleteWebhookPayload {
44
+ /** Pass True to drop all pending updates */
45
+ drop_pending_updates?: boolean;
46
+ }
47
+ /**
48
+ * Contains information about the current status of a webhook.
49
+ * @see https://core.telegram.org/bots/api#webhookinfo
50
+ */
51
+ export interface WebhookInfo {
52
+ /** Webhook URL, may be empty if webhook is not set up */
53
+ url?: string;
54
+ /** True, if a custom certificate was provided for webhook certificate checks */
55
+ has_custom_certificate?: boolean;
56
+ /** Number of updates awaiting delivery */
57
+ pending_update_count?: Integer;
58
+ /** Optional. Currently used webhook IP address */
59
+ ip_address?: string;
60
+ /** Optional. Unix time for the most recent error that happened when trying to deliver an update via webhook */
61
+ last_error_date?: Integer;
62
+ /** Optional. Error message in human-readable format for the most recent error that happened when trying to deliver an update via webhook */
63
+ last_error_message?: string;
64
+ /** Optional. Unix time of the most recent error that happened when trying to synchronize available updates with Telegram datacenters */
65
+ last_synchronization_error_date?: number;
66
+ /** Optional. Maximum allowed number of simultaneous HTTPS connections to the webhook for update delivery */
67
+ max_connections?: Integer;
68
+ /** Optional. A list of update types the bot is subscribed to. Defaults to all update types except chat_member */
69
+ allowed_updates?: string[];
70
+ }
71
+ declare module './internal.ts' {
72
+ interface Internal {
73
+ /**
74
+ * Use this method to receive incoming updates using long polling (wiki). An Array of Update objects is returned.
75
+ * @see https://core.telegram.org/bots/api#getupdates
76
+ */
77
+ getUpdates(payload: GetUpdatesPayload): Promise<Update[]>;
78
+ /**
79
+ * Use this method to specify a url and receive incoming updates via an outgoing webhook. Whenever there is an update for the bot, we will send an HTTPS POST request to the specified url, containing a JSON-serialized Update. In case of an unsuccessful request, we will give up after a reasonable amount of attempts. Returns True on success.
80
+ *
81
+ * If you'd like to make sure that the Webhook request comes from Telegram, we recommend using a secret path in the URL, e.g. https://www.example.com/<token>. Since nobody else knows your bot's token, you can be pretty sure it's us.
82
+ * @see https://core.telegram.org/bots/api#setwebhook
83
+ */
84
+ setWebhook(payload: SetWebhookPayload): Promise<boolean>;
85
+ /**
86
+ * Use this method to remove webhook integration if you decide to switch back to getUpdates. Returns True on success.
87
+ * @see https://core.telegram.org/bots/api#deletewebhook
88
+ */
89
+ deleteWebhook(payload: DeleteWebhookPayload): Promise<boolean>;
90
+ /**
91
+ * Use this method to get current webhook status. Requires no parameters. On success, returns a WebhookInfo object. If the bot is using getUpdates, will return an object with the url field empty.
92
+ * @see https://core.telegram.org/bots/api#getwebhookinfo
93
+ */
94
+ getWebhookInfo(): Promise<WebhookInfo>;
95
+ }
96
+ }
97
+ //# sourceMappingURL=update.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../../src/types/update.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAY,MAAM,YAAY,CAAA;AAEzD;;;GAGG;AACH,MAAM,WAAW,MAAM;IACrB,ibAAib;IACjb,SAAS,CAAC,EAAE,OAAO,CAAA;CACpB;AAED,MAAM,WAAW,iBAAiB;IAChC,6eAA6e;IAC7e,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,wGAAwG;IACxG,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,gKAAgK;IAChK,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,EAAE,CAAA;CAC3B;AAED,MAAM,WAAW,iBAAiB;IAChC,sFAAsF;IACtF,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,oIAAoI;IACpI,WAAW,CAAC,EAAE,SAAS,CAAA;IACvB,sHAAsH;IACtH,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,wOAAwO;IACxO,eAAe,CAAC,EAAE,OAAO,CAAA;IACzB;;;;OAIG;IACH,eAAe,CAAC,EAAE,MA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leteWebhook');
5
+ Internal.define('getWebhookInfo');
6
+ //# sourceMappingURL=update.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update.js","sourceRoot":"","sources":["../../../src/types/update.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,QAAQ,EAAE,MAAM,YAAY,CAAA;AAuGzD,QAAQ,CAAC,MAAM,CAAC,YAAY,CAAC,CAAA;AAC7B,QAAQ,CAAC,MAAM,CAAC,YAAY,CAAC,CAAA;AAC7B,QAAQ,CAAC,MAAM,CAAC,eAAe,CAAC,CAAA;AAChC,QAAQ,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAA"}
@@ -0,0 +1,29 @@
1
+ import type { TelegramBot } from './bot.ts';
2
+ /**
3
+ * Webhook transport over the profile's `ctx.webServer`.
4
+ *
5
+ * The route is anonymous at the Web server layer and authenticated by
6
+ * Telegram's secret-token header, whose value the adapter derives from the
7
+ * Bot API token. `connect` registers the route and calls `setWebhook`, so a
8
+ * profile without `webServer` fails with an actionable message instead of
9
+ * silently receiving nothing.
10
+ */
11
+ export declare class TelegramWebhook {
12
+ private readonly bot;
13
+ private dispose;
14
+ constructor(bot: TelegramBot);
15
+ /** Register the route and point Telegram at it. */
16
+ start(): Promise<void>;
17
+ /** Release the route. The webhook itself stays registered so Telegram keeps retrying. */
18
+ stop(): Promise<void>;
19
+ /**
20
+ * Log a fatal start failure before the caller throws it, because `Bot.start`
21
+ * only stores a connect failure on `bot.error`.
22
+ *
23
+ * @param message - error text that also names the corrective action.
24
+ * @returns the error for the caller to throw.
25
+ */
26
+ private failStart;
27
+ private handle;
28
+ }
29
+ //# sourceMappingURL=webhook.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhook.d.ts","sourceRoot":"","sources":["../../src/webhook.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AA8C3C;;;;;;;;GAQG;AACH,qBAAa,eAAe;IAGd,OAAO,CAAC,QAAQ,CAAC,GAAG;IAFhC,OAAO,CAAC,OAAO,CAA0B;gBAEZ,GAAG,EAAE,WAAW;IAE7C,mDAAmD;IAC7C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IA6C5B,yFAAyF;IACnF,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAK3B;;;;;;OAMG;IACH,OAAO,CAAC,SAAS;YAKH,MAAM;CA0CrB"}
@@ -0,0 +1,129 @@
1
+ import { decodeUpdate } from "./decode.js";
2
+ import { ALLOWED_UPDATES } from "./polling.js";
3
+ import { deriveWebhookSecret, matchesWebhookSecret } from "./secret.js";
4
+ /** Header Telegram echoes the configured secret token in. */
5
+ const SECRET_HEADER = 'x-telegram-bot-api-secret-token';
6
+ /** Route path Telegram posts to: leading slash, no trailing slash. */
7
+ function routePath(path) {
8
+ const withSlash = path.startsWith('/') ? path : `/${path}`;
9
+ return withSlash.length > 1 ? withSlash.replace(/\/+$/, '') : withSlash;
10
+ }
11
+ /** One request's bounded body. */
12
+ async function readBody(request, limit) {
13
+ const chunks = [];
14
+ let size = 0;
15
+ for await (const chunk of request) {
16
+ const buffer = Buffer.isBuffer(chunk)
17
+ ? chunk
18
+ : Buffer.from(chunk);
19
+ size += buffer.byteLength;
20
+ if (size > limit)
21
+ return undefined;
22
+ chunks.push(buffer);
23
+ }
24
+ return Buffer.concat(chunks).toString('utf8');
25
+ }
26
+ /**
27
+ * Webhook transport over the profile's `ctx.webServer`.
28
+ *
29
+ * The route is anonymous at the Web server layer and authenticated by
30
+ * Telegram's secret-token header, whose value the adapter derives from the
31
+ * Bot API token. `connect` registers the route and calls `setWebhook`, so a
32
+ * profile without `webServer` fails with an actionable message instead of
33
+ * silently receiving nothing.
34
+ */
35
+ export class TelegramWebhook {
36
+ bot;
37
+ dispose;
38
+ constructor(bot) {
39
+ this.bot = bot;
40
+ }
41
+ /** Register the route and point Telegram at it. */
42
+ async start() {
43
+ const webServer = this.bot.ctx.get('webServer');
44
+ if (webServer === undefined) {
45
+ throw this.failStart('telegram: the webhook transport needs a profile-provided webServer; use transport "polling" instead');
46
+ }
47
+ const publicUrl = this.bot.config.webhook.publicUrl;
48
+ if (publicUrl === undefined || publicUrl === null || publicUrl === '') {
49
+ throw this.failStart('telegram: webhook.publicUrl is required for the webhook transport');
50
+ }
51
+ const url = new URL(publicUrl);
52
+ if (url.protocol !== 'https:') {
53
+ throw this.failStart('telegram: webhook.publicUrl must be an https URL (Telegram refuses plain HTTP webhooks)');
54
+ }
55
+ const path = routePath(this.bot.config.webhook.path);
56
+ this.dispose = webServer.register({
57
+ kind: 'exact',
58
+ path,
59
+ auth: 'anonymous',
60
+ handler: (request, response) => this.handle(request, response),
61
+ });
62
+ try {
63
+ await this.bot.internal.setWebhook({
64
+ url: `${publicUrl.replace(/\/+$/, '')}${path}`,
65
+ secret_token: deriveWebhookSecret(this.bot.config.token),
66
+ drop_pending_updates: this.bot.config.dropPendingUpdates,
67
+ allowed_updates: [...ALLOWED_UPDATES],
68
+ });
69
+ }
70
+ catch (error) {
71
+ this.dispose();
72
+ this.dispose = undefined;
73
+ this.bot.ctx.logger.error('telegram: setWebhook failed: %s', error instanceof Error ? error.message : String(error));
74
+ throw error;
75
+ }
76
+ this.bot.online();
77
+ }
78
+ /** Release the route. The webhook itself stays registered so Telegram keeps retrying. */
79
+ async stop() {
80
+ this.dispose?.();
81
+ this.dispose = undefined;
82
+ }
83
+ /**
84
+ * Log a fatal start failure before the caller throws it, because `Bot.start`
85
+ * only stores a connect failure on `bot.error`.
86
+ *
87
+ * @param message - error text that also names the corrective action.
88
+ * @returns the error for the caller to throw.
89
+ */
90
+ failStart(message) {
91
+ this.bot.ctx.logger.error(message);
92
+ return new Error(message);
93
+ }
94
+ async handle(request, response) {
95
+ try {
96
+ if (request.method !== 'POST') {
97
+ response.writeHead(405, { allow: 'POST' });
98
+ response.end();
99
+ return;
100
+ }
101
+ const expected = deriveWebhookSecret(this.bot.config.token);
102
+ const received = request.headers[SECRET_HEADER];
103
+ if (!matchesWebhookSecret(expected, typeof received === 'string' ? received : undefined)) {
104
+ response.writeHead(401);
105
+ response.end();
106
+ return;
107
+ }
108
+ const body = await readBody(request, this.bot.config.webhook.maxBodyBytes);
109
+ if (body === undefined) {
110
+ response.writeHead(413);
111
+ response.end();
112
+ return;
113
+ }
114
+ const update = JSON.parse(body);
115
+ const session = decodeUpdate(this.bot, update);
116
+ if (session !== undefined)
117
+ await this.bot.receive(session);
118
+ response.writeHead(200, { 'content-type': 'text/plain' });
119
+ response.end('OK');
120
+ }
121
+ catch (error) {
122
+ this.bot.ctx.logger.warn('telegram: webhook delivery failed: %s', error instanceof Error ? error.message : String(error));
123
+ if (!response.headersSent)
124
+ response.writeHead(500);
125
+ response.end();
126
+ }
127
+ }
128
+ }
129
+ //# sourceMappingURL=webhook.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webhook.js","sourceRoot":"","sources":["../../src/webhook.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAgBvE,6DAA6D;AAC7D,MAAM,aAAa,GAAG,iCAAiC,CAAA;AAEvD,sEAAsE;AACtE,SAAS,SAAS,CAAC,IAAY;IAC7B,MAAM,SAAS,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAA;IAC1D,OAAO,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;AACzE,CAAC;AAED,kCAAkC;AAClC,KAAK,UAAU,QAAQ,CACrB,OAAwB,EACxB,KAAa;IAEb,MAAM,MAAM,GAAa,EAAE,CAAA;IAC3B,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,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAW,CAAA;YACzC,MAAM,OAAO,GAAG,YAAY,CAAC,IAAI,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;YAC9C,IAAI,OAAO,KAAK,SAAS;gBAAE,MAAM,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;YAC1D,QAAQ,CAAC,SAAS,CAAC,GAAG,EAAE,EAAE,cAAc,EAAE,YAAY,EAAE,CAAC,CAAA;YACzD,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;QACpB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CACtB,uCAAuC,EACvC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CACvD,CAAA;YACD,IAAI,CAAC,QAAQ,CAAC,WAAW;gBAAE,QAAQ,CAAC,SAAS,CAAC,GAAG,CAAC,CAAA;YAClD,QAAQ,CAAC,GAAG,EAAE,CAAA;QAChB,CAAC;IACH,CAAC;CACF"}
package/package.json CHANGED
@@ -1,6 +1,64 @@
1
1
  {
2
2
  "name": "@im-more/dsh-telegram",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "Telegram adapter for official dsh-im of DeepSeek Harness",
5
+ "homepage": "https://github.com/ilharp/dsh-im-more",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/ilharp/dsh-im-more.git",
9
+ "directory": "packages/telegram"
10
+ },
11
+ "author": {
12
+ "name": "Il Harper",
13
+ "email": "hi@ilharper.com",
14
+ "url": "https://ilharper.com"
15
+ },
16
+ "license": "MIT",
17
+ "type": "module",
18
+ "main": "lib/index.js",
19
+ "types": "lib/types/index.d.ts",
20
+ "exports": {
21
+ ".": {
22
+ "types": "./lib/types/index.d.ts",
23
+ "default": "./lib/index.js"
24
+ },
25
+ "./package.json": "./package.json",
26
+ "./cordis.patch.yml": "./cordis.patch.yml"
27
+ },
28
+ "files": [
29
+ "lib",
30
+ "src",
31
+ "cordis.patch.yml"
32
+ ],
33
+ "engines": {
34
+ "dsh": ">=0.2.3-alpha.3"
35
+ },
36
+ "peerDependencies": {
37
+ "@deepseek-ai/cordis": ">=4.2.0-alpha.2",
38
+ "@deepseek-ai/cordis-plugin-http": ">=1.6.1-alpha.2",
39
+ "@deepseek-ai/cordis-plugin-im-core": ">=5.0.1-alpha.2",
40
+ "@deepseek-ai/satori-element": ">=4.0.1-alpha.2",
41
+ "@deepseek-ai/schemastery": ">=3.20.0-alpha.2"
42
+ },
43
+ "devDependencies": {
44
+ "@deepseek-ai/cordis": ">=4.2.0-alpha.2",
45
+ "@deepseek-ai/cordis-plugin-http": ">=1.6.1-alpha.2",
46
+ "@deepseek-ai/cordis-plugin-im-core": ">=5.0.1-alpha.2",
47
+ "@deepseek-ai/satori-element": ">=4.0.1-alpha.2",
48
+ "@deepseek-ai/schemastery": ">=3.20.0-alpha.2",
49
+ "@types/node": "^22.20.1",
50
+ "tsdown": "^0.22.2",
51
+ "typescript": "^6.0.3",
52
+ "vitest": "^4.1.11"
53
+ },
54
+ "dsh": {
55
+ "bundle": {
56
+ "patch": "./cordis.patch.yml"
57
+ }
58
+ },
59
+ "scripts": {
60
+ "build": "tsc -p tsconfig.json && tsdown",
61
+ "typecheck": "tsc -p tsconfig.test.json",
62
+ "test": "vitest run"
63
+ }
6
64
  }