@zhin.js/adapter-telegram 7.0.8 → 7.0.10

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,39 @@
1
1
  # Changelog
2
2
 
3
+ ## 7.0.10
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [e4757a8]
8
+ - Updated dependencies [c3c0ebf]
9
+ - @zhin.js/command@1.0.13
10
+ - @zhin.js/host-http@1.0.10
11
+ - @zhin.js/agent@1.1.10
12
+ - @zhin.js/core@1.5.9
13
+ - @zhin.js/adapter@1.1.9
14
+ - zhin.js@6.0.9
15
+
16
+ ## 7.0.9
17
+
18
+ ### Patch Changes
19
+
20
+ - Updated dependencies [63253bb]
21
+ - Updated dependencies [6fb24dd]
22
+ - Updated dependencies [d162216]
23
+ - Updated dependencies [7427818]
24
+ - Updated dependencies [90da255]
25
+ - Updated dependencies [8e973dc]
26
+ - Updated dependencies [953cfe1]
27
+ - Updated dependencies [0e73866]
28
+ - @zhin.js/plugin-runtime@1.1.6
29
+ - @zhin.js/core@1.5.8
30
+ - @zhin.js/adapter@1.1.8
31
+ - @zhin.js/host-http@1.0.9
32
+ - @zhin.js/agent@1.1.9
33
+ - zhin.js@6.0.8
34
+ - @zhin.js/command@1.0.12
35
+ - @zhin.js/permission@1.0.2
36
+
3
37
  ## 7.0.8
4
38
 
5
39
  ### Patch Changes
package/lib/endpoint.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { EndpointControl, EndpointInstance, EndpointSendRequest } from '@zhin.js/adapter';
2
2
  import type { MessageGateway } from '@zhin.js/core/runtime';
3
3
  import type { HttpHost } from '@zhin.js/host-http';
4
+ import { type MessageRef } from '@zhin.js/im-contract';
4
5
  import type { CapabilityId } from '@zhin.js/plugin-runtime';
5
6
  import { type ResolvedTelegramConfig, type TelegramCallbackQuery, type TelegramChatMember, type TelegramMessage, type TelegramUpdate } from './protocol.js';
6
7
  export type TelegramFetch = (url: string, init?: {
@@ -41,7 +42,7 @@ export declare class TelegramEndpoint implements EndpointInstance {
41
42
  close(): void;
42
43
  stop(): Promise<void>;
43
44
  send({ conversation, payload }: EndpointSendRequest): Promise<string>;
44
- recallMessage(messageId: string): Promise<void>;
45
+ recallMessage(message: MessageRef): Promise<void>;
45
46
  /** Test / internal: admit a message when open. */
46
47
  admit(msg: TelegramMessage): void;
47
48
  /** Test / internal: admit a callback query when open. */
package/lib/endpoint.js CHANGED
@@ -2,7 +2,6 @@
2
2
  * TelegramEndpoint — lifecycle, outbound, admit, Bot API helpers for agent tools.
3
3
  */
4
4
  import { readFile } from 'node:fs/promises';
5
- import { formatLegacyMessageRef, nativeConversationId, parseLegacyMessageReference, } from '@zhin.js/im-contract';
6
5
  import { formatCompact, getAdapterLogger } from '@zhin.js/logger';
7
6
  import { runTelegramPollLoop } from './polling.js';
8
7
  import { normalizeTelegramChatMember } from './platform-permit.js';
@@ -31,7 +30,7 @@ export class TelegramEndpoint {
31
30
  #botUsername;
32
31
  #chatMemberCache = new Map();
33
32
  control = Object.freeze({
34
- recall: (messageId) => this.recallMessage(messageId),
33
+ recall: (message) => this.recallMessage(message),
35
34
  });
36
35
  constructor(options) {
37
36
  this.#logger = getAdapterLogger('telegram', options.config.id);
@@ -143,19 +142,15 @@ export class TelegramEndpoint {
143
142
  if (result.message_id != null)
144
143
  lastId = String(result.message_id);
145
144
  }
146
- if (!lastId)
147
- return `telegram-${Date.now()}`;
148
- return formatLegacyMessageRef({ conversation, id: lastId });
145
+ return lastId || `telegram-${Date.now()}`;
149
146
  }
150
- async recallMessage(messageId) {
151
- if (!messageId || messageId.startsWith('telegram-'))
147
+ async recallMessage(message) {
148
+ if (!message.id || message.id.startsWith('telegram-'))
152
149
  return;
153
- const reference = parseLegacyMessageReference(messageId);
154
- if (!reference)
155
- return;
156
- const chatId = nativeConversationId(reference.target);
157
- const msgId = reference.messageId;
158
- await this.callApi('deleteMessage', { chat_id: chatId, message_id: Number(msgId) });
150
+ await this.callApi('deleteMessage', {
151
+ chat_id: message.conversation.id,
152
+ message_id: Number(message.id),
153
+ });
159
154
  }
160
155
  /**
161
156
  * 含 `attach://` 占位的媒体参数 → multipart/form-data:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhin.js/adapter-telegram",
3
- "version": "7.0.8",
3
+ "version": "7.0.10",
4
4
  "description": "Zhin.js Telegram Bot API adapter for Plugin Runtime (long-poll getUpdates)",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",
@@ -32,22 +32,22 @@
32
32
  "directory": "plugins/adapters/telegram"
33
33
  },
34
34
  "dependencies": {
35
- "@zhin.js/adapter": "1.1.7",
36
- "@zhin.js/command": "1.0.11",
37
- "@zhin.js/core": "1.5.7",
38
- "@zhin.js/host-http": "1.0.8",
35
+ "@zhin.js/adapter": "1.1.9",
36
+ "@zhin.js/command": "1.0.13",
37
+ "@zhin.js/core": "1.5.9",
38
+ "@zhin.js/host-http": "1.0.10",
39
39
  "@zhin.js/im-contract": "1.0.3",
40
40
  "@zhin.js/logger": "1.0.76",
41
- "@zhin.js/plugin-runtime": "1.1.5"
41
+ "@zhin.js/plugin-runtime": "1.1.6"
42
42
  },
43
43
  "peerDependencies": {
44
44
  "zod": "^4.0.0",
45
- "@zhin.js/adapter": "1.1.7",
46
- "@zhin.js/agent": "1.1.8",
47
- "@zhin.js/core": "1.5.7",
48
- "@zhin.js/permission": "1.0.1",
49
- "@zhin.js/plugin-runtime": "1.1.5",
50
- "zhin.js": "6.0.7"
45
+ "@zhin.js/adapter": "1.1.9",
46
+ "@zhin.js/agent": "1.1.10",
47
+ "@zhin.js/core": "1.5.9",
48
+ "@zhin.js/permission": "1.0.2",
49
+ "@zhin.js/plugin-runtime": "1.1.6",
50
+ "zhin.js": "6.0.9"
51
51
  },
52
52
  "peerDependenciesMeta": {
53
53
  "zhin.js": {
@@ -65,9 +65,9 @@
65
65
  "typescript": "^6.0.3",
66
66
  "vitest": "^4.1.10",
67
67
  "zod": "^4.4.3",
68
- "@zhin.js/agent": "1.1.8",
69
- "@zhin.js/host-http": "1.0.8",
70
- "zhin.js": "6.0.7"
68
+ "@zhin.js/agent": "1.1.10",
69
+ "@zhin.js/host-http": "1.0.10",
70
+ "zhin.js": "6.0.9"
71
71
  },
72
72
  "files": [
73
73
  "adapters",
package/src/endpoint.ts CHANGED
@@ -6,10 +6,8 @@ import type { EndpointControl, EndpointInstance, EndpointSendRequest } from '@zh
6
6
  import type { MessageGateway } from '@zhin.js/core/runtime';
7
7
  import type { HttpHost, HttpRouteRegistration } from '@zhin.js/host-http';
8
8
  import {
9
- formatLegacyMessageRef,
10
- nativeConversationId,
11
- parseLegacyMessageReference,
12
9
  type ConversationRef,
10
+ type MessageRef,
13
11
  } from '@zhin.js/im-contract';
14
12
  import { formatCompact, getAdapterLogger } from '@zhin.js/logger';
15
13
  import type { CapabilityId } from '@zhin.js/plugin-runtime';
@@ -100,7 +98,7 @@ export class TelegramEndpoint implements EndpointInstance {
100
98
  #botUsername?: string;
101
99
  readonly #chatMemberCache = new Map<string, ChatMemberPermit>();
102
100
  readonly control: EndpointControl = Object.freeze({
103
- recall: (messageId: string) => this.recallMessage(messageId),
101
+ recall: (message: MessageRef) => this.recallMessage(message),
104
102
  });
105
103
 
106
104
  constructor(options: TelegramEndpointOptions) {
@@ -220,17 +218,15 @@ export class TelegramEndpoint implements EndpointInstance {
220
218
  : await this.callApi<{ message_id?: number }>(action.method, action.params);
221
219
  if (result.message_id != null) lastId = String(result.message_id);
222
220
  }
223
- if (!lastId) return `telegram-${Date.now()}`;
224
- return formatLegacyMessageRef({ conversation, id: lastId });
221
+ return lastId || `telegram-${Date.now()}`;
225
222
  }
226
223
 
227
- async recallMessage(messageId: string): Promise<void> {
228
- if (!messageId || messageId.startsWith('telegram-')) return;
229
- const reference = parseLegacyMessageReference(messageId);
230
- if (!reference) return;
231
- const chatId = nativeConversationId(reference.target);
232
- const msgId = reference.messageId;
233
- await this.callApi('deleteMessage', { chat_id: chatId, message_id: Number(msgId) });
224
+ async recallMessage(message: MessageRef): Promise<void> {
225
+ if (!message.id || message.id.startsWith('telegram-')) return;
226
+ await this.callApi('deleteMessage', {
227
+ chat_id: message.conversation.id,
228
+ message_id: Number(message.id),
229
+ });
234
230
  }
235
231
 
236
232
  /**