@elizaos/plugin-line 2.0.0-alpha.3 → 2.0.0-alpha.4

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 (61) hide show
  1. package/dist/accounts.d.ts +152 -0
  2. package/dist/accounts.d.ts.map +1 -0
  3. package/dist/accounts.js +258 -0
  4. package/dist/accounts.js.map +1 -0
  5. package/dist/actions/index.d.ts +7 -0
  6. package/dist/actions/index.d.ts.map +1 -0
  7. package/{src/actions/index.ts → dist/actions/index.js} +1 -1
  8. package/dist/actions/index.js.map +1 -0
  9. package/dist/actions/sendFlexMessage.d.ts +6 -0
  10. package/dist/actions/sendFlexMessage.d.ts.map +1 -0
  11. package/dist/actions/sendFlexMessage.js +178 -0
  12. package/dist/actions/sendFlexMessage.js.map +1 -0
  13. package/dist/actions/sendLocation.d.ts +6 -0
  14. package/dist/actions/sendLocation.d.ts.map +1 -0
  15. package/dist/actions/sendLocation.js +155 -0
  16. package/dist/actions/sendLocation.js.map +1 -0
  17. package/dist/actions/sendMessage.d.ts +6 -0
  18. package/dist/actions/sendMessage.d.ts.map +1 -0
  19. package/dist/actions/sendMessage.js +146 -0
  20. package/dist/actions/sendMessage.js.map +1 -0
  21. package/dist/index.d.ts +22 -0
  22. package/dist/index.d.ts.map +1 -0
  23. package/dist/index.js.map +1 -0
  24. package/dist/messaging.d.ts +142 -0
  25. package/dist/messaging.d.ts.map +1 -0
  26. package/dist/messaging.js +348 -0
  27. package/dist/messaging.js.map +1 -0
  28. package/dist/providers/chatContext.d.ts +6 -0
  29. package/dist/providers/chatContext.d.ts.map +1 -0
  30. package/dist/providers/chatContext.js +85 -0
  31. package/dist/providers/chatContext.js.map +1 -0
  32. package/dist/providers/index.d.ts +6 -0
  33. package/dist/providers/index.d.ts.map +1 -0
  34. package/{src/providers/index.ts → dist/providers/index.js} +1 -1
  35. package/dist/providers/index.js.map +1 -0
  36. package/dist/providers/userContext.d.ts +6 -0
  37. package/dist/providers/userContext.d.ts.map +1 -0
  38. package/dist/providers/userContext.js +70 -0
  39. package/dist/providers/userContext.js.map +1 -0
  40. package/dist/service.d.ts +102 -0
  41. package/dist/service.d.ts.map +1 -0
  42. package/dist/service.js +433 -0
  43. package/dist/service.js.map +1 -0
  44. package/dist/types.d.ts +279 -0
  45. package/dist/types.d.ts.map +1 -0
  46. package/dist/types.js +106 -0
  47. package/dist/types.js.map +1 -0
  48. package/package.json +21 -6
  49. package/__tests__/integration.test.ts +0 -782
  50. package/build.ts +0 -16
  51. package/src/accounts.ts +0 -462
  52. package/src/actions/sendFlexMessage.ts +0 -243
  53. package/src/actions/sendLocation.ts +0 -223
  54. package/src/actions/sendMessage.ts +0 -202
  55. package/src/index.ts +0 -123
  56. package/src/messaging.ts +0 -507
  57. package/src/providers/chatContext.ts +0 -110
  58. package/src/providers/userContext.ts +0 -99
  59. package/src/service.ts +0 -578
  60. package/src/types.ts +0 -417
  61. package/tsconfig.json +0 -22
package/src/types.ts DELETED
@@ -1,417 +0,0 @@
1
- /**
2
- * LINE Channel Types
3
- *
4
- * Type definitions for LINE messaging channel data structures.
5
- *
6
- * @module line/types
7
- */
8
-
9
- // Constants
10
- export const LINE_SERVICE_NAME = "line" as const;
11
- export const MAX_LINE_BATCH_SIZE = 5;
12
-
13
- // Event types
14
- export const LineEventTypes = {
15
- CONNECTION_READY: "line:connection_ready",
16
- MESSAGE_RECEIVED: "line:message_received",
17
- MESSAGE_SENT: "line:message_sent",
18
- FOLLOW: "line:follow",
19
- UNFOLLOW: "line:unfollow",
20
- JOIN_GROUP: "line:join_group",
21
- LEAVE_GROUP: "line:leave_group",
22
- POSTBACK: "line:postback",
23
- } as const;
24
-
25
- // Error classes
26
- export class LineConfigurationError extends Error {
27
- constructor(
28
- message: string,
29
- public field?: string,
30
- ) {
31
- super(message);
32
- this.name = "LineConfigurationError";
33
- }
34
- }
35
-
36
- export class LineApiError extends Error {
37
- constructor(
38
- message: string,
39
- public statusCode?: number,
40
- ) {
41
- super(message);
42
- this.name = "LineApiError";
43
- }
44
- }
45
-
46
- // Configuration types
47
- export interface LineSettings {
48
- channelAccessToken: string;
49
- channelSecret: string;
50
- webhookPath: string;
51
- dmPolicy: "open" | "pairing" | "allowlist" | "disabled";
52
- groupPolicy: "open" | "allowlist" | "disabled";
53
- allowFrom: string[];
54
- enabled: boolean;
55
- }
56
-
57
- // User/Group types
58
- export interface LineUser {
59
- userId: string;
60
- displayName: string;
61
- pictureUrl?: string;
62
- statusMessage?: string;
63
- language?: string;
64
- }
65
-
66
- export interface LineGroup {
67
- groupId: string;
68
- groupName?: string;
69
- pictureUrl?: string;
70
- memberCount?: number;
71
- type: "group" | "room";
72
- }
73
-
74
- // Send result type
75
- export interface LineSendResult {
76
- success: boolean;
77
- messageId?: string;
78
- chatId?: string;
79
- error?: string;
80
- }
81
-
82
- // Message send options
83
- export interface LineMessageSendOptions {
84
- quickReplyItems?: LineQuickReplyItem[];
85
- notificationDisabled?: boolean;
86
- }
87
-
88
- // Service interface
89
- export interface ILineService {
90
- isConnected(): boolean;
91
- sendMessage(
92
- to: string,
93
- text: string,
94
- options?: LineMessageSendOptions,
95
- ): Promise<LineSendResult>;
96
- sendFlexMessage(to: string, flex: LineFlexMessage): Promise<LineSendResult>;
97
- sendTemplateMessage(
98
- to: string,
99
- template: LineTemplateMessage,
100
- ): Promise<LineSendResult>;
101
- sendLocationMessage(
102
- to: string,
103
- location: LineLocationMessage,
104
- ): Promise<LineSendResult>;
105
- replyMessage(
106
- replyToken: string,
107
- messages: Array<{ type: string; [key: string]: unknown }>,
108
- ): Promise<LineSendResult>;
109
- getUserProfile(userId: string): Promise<LineUser | null>;
110
- getGroupInfo(groupId: string): Promise<LineGroup | null>;
111
- getBotInfo(): Promise<LineUser | null>;
112
- }
113
-
114
- // Validation helpers
115
- export function isValidLineId(id: string): boolean {
116
- if (!id || typeof id !== "string") {
117
- return false;
118
- }
119
- // LINE user IDs start with U, group IDs with C, room IDs with R
120
- const prefixes = ["U", "u", "C", "c", "R", "r"];
121
- return prefixes.some((p) => id.startsWith(p)) && id.length >= 30;
122
- }
123
-
124
- export function normalizeLineTarget(target: string): string | null {
125
- if (!target || typeof target !== "string") {
126
- return null;
127
- }
128
- const trimmed = target.trim();
129
- if (isValidLineId(trimmed)) {
130
- return trimmed;
131
- }
132
- return null;
133
- }
134
-
135
- /**
136
- * LINE location message data.
137
- */
138
- export interface LineLocationData {
139
- title: string;
140
- address: string;
141
- latitude: number;
142
- longitude: number;
143
- }
144
-
145
- /**
146
- * LINE template action types.
147
- */
148
- export type LineActionType = "message" | "postback" | "uri";
149
-
150
- /**
151
- * LINE template action.
152
- */
153
- export interface LineTemplateAction {
154
- type: LineActionType;
155
- label: string;
156
- data?: string;
157
- uri?: string;
158
- }
159
-
160
- /**
161
- * LINE template message base.
162
- */
163
- export interface LineTemplateMessageBase {
164
- altText: string;
165
- }
166
-
167
- /**
168
- * LINE confirm template content.
169
- */
170
- export interface LineConfirmTemplateContent {
171
- type: "confirm";
172
- text: string;
173
- actions: LineTemplateAction[];
174
- }
175
-
176
- /**
177
- * LINE buttons template content.
178
- */
179
- export interface LineButtonsTemplateContent {
180
- type: "buttons";
181
- title?: string;
182
- text: string;
183
- thumbnailImageUrl?: string;
184
- actions: LineTemplateAction[];
185
- }
186
-
187
- /**
188
- * LINE template content union type.
189
- */
190
- export type LineTemplateContent =
191
- | LineConfirmTemplateContent
192
- | LineButtonsTemplateContent;
193
-
194
- /**
195
- * LINE template message (wrapper for sending).
196
- */
197
- export interface LineTemplateMessage extends LineTemplateMessageBase {
198
- /** The template content */
199
- template: LineTemplateContent;
200
- }
201
-
202
- /**
203
- * LINE Flex Message content (simplified).
204
- */
205
- export interface LineFlexContents {
206
- type: string;
207
- [key: string]: unknown;
208
- }
209
-
210
- /**
211
- * LINE Flex Message data.
212
- */
213
- export interface LineFlexMessage {
214
- altText: string;
215
- contents: LineFlexContents;
216
- }
217
-
218
- /**
219
- * LINE quick reply item.
220
- */
221
- export interface LineQuickReplyItem {
222
- type: "action";
223
- action: {
224
- type: "message" | "postback";
225
- label: string;
226
- text?: string;
227
- data?: string;
228
- };
229
- }
230
-
231
- /**
232
- * LINE channel-specific data embedded in reply payloads.
233
- */
234
- export interface LineChannelData {
235
- /** Quick reply options (text strings converted to quick reply items) */
236
- quickReplies?: string[];
237
- /** Location message */
238
- location?: LineLocationData;
239
- /** Template message (confirm, buttons, etc.) */
240
- templateMessage?: LineTemplateMessage;
241
- /** Flex message for rich content */
242
- flexMessage?: LineFlexMessage;
243
- /** Raw sticker data */
244
- sticker?: { packageId: string; stickerId: string };
245
- /** Image map message */
246
- imagemap?: unknown;
247
- }
248
-
249
- /**
250
- * LINE message common properties.
251
- */
252
- export interface LineMessageBase {
253
- /** Message type */
254
- type: string;
255
- /** Quick reply */
256
- quickReply?: { items: LineQuickReplyItem[] };
257
- }
258
-
259
- /**
260
- * LINE text message.
261
- */
262
- export interface LineTextMessage extends LineMessageBase {
263
- type: "text";
264
- text: string;
265
- }
266
-
267
- /**
268
- * LINE image message.
269
- */
270
- export interface LineImageMessage extends LineMessageBase {
271
- type: "image";
272
- originalContentUrl: string;
273
- previewImageUrl: string;
274
- }
275
-
276
- /**
277
- * LINE sticker message.
278
- */
279
- export interface LineStickerMessage extends LineMessageBase {
280
- type: "sticker";
281
- packageId: string;
282
- stickerId: string;
283
- }
284
-
285
- /**
286
- * LINE location message.
287
- */
288
- export interface LineLocationMessage extends LineMessageBase {
289
- type: "location";
290
- title: string;
291
- address: string;
292
- latitude: number;
293
- longitude: number;
294
- }
295
-
296
- /**
297
- * LINE Flex message for sending.
298
- */
299
- export interface LineFlexMessageSend extends LineMessageBase {
300
- type: "flex";
301
- altText: string;
302
- contents: LineFlexContents;
303
- }
304
-
305
- /**
306
- * LINE template message for sending.
307
- */
308
- export interface LineTemplateMessageSend extends LineMessageBase {
309
- type: "template";
310
- altText: string;
311
- template: unknown;
312
- }
313
-
314
- /**
315
- * Union type of all LINE message types for sending.
316
- */
317
- export type LineSendMessage =
318
- | LineTextMessage
319
- | LineImageMessage
320
- | LineStickerMessage
321
- | LineLocationMessage
322
- | LineFlexMessageSend
323
- | LineTemplateMessageSend;
324
-
325
- /**
326
- * LINE received message type (from webhook events).
327
- */
328
- export interface LineMessage {
329
- /** Unique message ID */
330
- id: string;
331
- /** Message type */
332
- type:
333
- | "text"
334
- | "image"
335
- | "sticker"
336
- | "location"
337
- | "flex"
338
- | "template"
339
- | "video"
340
- | "audio"
341
- | "file";
342
- /** User ID of the sender */
343
- userId: string;
344
- /** Message timestamp */
345
- timestamp: number;
346
- /** Reply token for responding to this message */
347
- replyToken?: string;
348
- /** Text content (for text messages) */
349
- text?: string;
350
- /** Mention data (for text messages) */
351
- mention?: unknown;
352
- /** Group ID (if message is from a group) */
353
- groupId?: string;
354
- /** Room ID (if message is from a room) */
355
- roomId?: string;
356
- }
357
-
358
- /**
359
- * LINE chat type: user, group, or room.
360
- */
361
- export type LineChatType = "user" | "group" | "room";
362
-
363
- /**
364
- * Determines the chat type from a LINE ID.
365
- */
366
- export function getChatTypeFromId(id: string): LineChatType {
367
- if (id.startsWith("C") || id.startsWith("c")) {
368
- return "group";
369
- } else if (id.startsWith("R") || id.startsWith("r")) {
370
- return "room";
371
- }
372
- return "user";
373
- }
374
-
375
- /**
376
- * LINE message character limit (5000 characters per message).
377
- */
378
- const LINE_MAX_MESSAGE_LENGTH = 5000;
379
-
380
- /**
381
- * Splits text into chunks that fit within LINE's message limit.
382
- */
383
- export function splitMessageForLine(text: string): string[] {
384
- if (!text || text.length === 0) {
385
- return [];
386
- }
387
-
388
- if (text.length <= LINE_MAX_MESSAGE_LENGTH) {
389
- return [text];
390
- }
391
-
392
- const chunks: string[] = [];
393
- let remaining = text;
394
-
395
- while (remaining.length > 0) {
396
- if (remaining.length <= LINE_MAX_MESSAGE_LENGTH) {
397
- chunks.push(remaining);
398
- break;
399
- }
400
-
401
- // Try to split at the last newline or space before the limit
402
- let splitIndex = LINE_MAX_MESSAGE_LENGTH;
403
- const lastNewline = remaining.lastIndexOf("\n", LINE_MAX_MESSAGE_LENGTH);
404
- const lastSpace = remaining.lastIndexOf(" ", LINE_MAX_MESSAGE_LENGTH);
405
-
406
- if (lastNewline > LINE_MAX_MESSAGE_LENGTH / 2) {
407
- splitIndex = lastNewline + 1;
408
- } else if (lastSpace > LINE_MAX_MESSAGE_LENGTH / 2) {
409
- splitIndex = lastSpace + 1;
410
- }
411
-
412
- chunks.push(remaining.substring(0, splitIndex).trim());
413
- remaining = remaining.substring(splitIndex);
414
- }
415
-
416
- return chunks.filter(Boolean);
417
- }
package/tsconfig.json DELETED
@@ -1,22 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "outDir": "./dist",
4
- "rootDir": "./src",
5
- "declaration": true,
6
- "declarationMap": true,
7
- "sourceMap": true,
8
- "target": "ES2022",
9
- "module": "ESNext",
10
- "moduleResolution": "Bundler",
11
- "lib": ["ES2022"],
12
- "types": ["node", "bun"],
13
- "strict": true,
14
- "esModuleInterop": true,
15
- "skipLibCheck": true,
16
- "forceConsistentCasingInFileNames": true,
17
- "resolveJsonModule": true,
18
- "isolatedModules": true
19
- },
20
- "include": ["src/**/*"],
21
- "exclude": ["node_modules", "dist", "**/*.test.ts"]
22
- }