@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.
- package/dist/accounts.d.ts +152 -0
- package/dist/accounts.d.ts.map +1 -0
- package/dist/accounts.js +258 -0
- package/dist/accounts.js.map +1 -0
- package/dist/actions/index.d.ts +7 -0
- package/dist/actions/index.d.ts.map +1 -0
- package/{src/actions/index.ts → dist/actions/index.js} +1 -1
- package/dist/actions/index.js.map +1 -0
- package/dist/actions/sendFlexMessage.d.ts +6 -0
- package/dist/actions/sendFlexMessage.d.ts.map +1 -0
- package/dist/actions/sendFlexMessage.js +178 -0
- package/dist/actions/sendFlexMessage.js.map +1 -0
- package/dist/actions/sendLocation.d.ts +6 -0
- package/dist/actions/sendLocation.d.ts.map +1 -0
- package/dist/actions/sendLocation.js +155 -0
- package/dist/actions/sendLocation.js.map +1 -0
- package/dist/actions/sendMessage.d.ts +6 -0
- package/dist/actions/sendMessage.d.ts.map +1 -0
- package/dist/actions/sendMessage.js +146 -0
- package/dist/actions/sendMessage.js.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js.map +1 -0
- package/dist/messaging.d.ts +142 -0
- package/dist/messaging.d.ts.map +1 -0
- package/dist/messaging.js +348 -0
- package/dist/messaging.js.map +1 -0
- package/dist/providers/chatContext.d.ts +6 -0
- package/dist/providers/chatContext.d.ts.map +1 -0
- package/dist/providers/chatContext.js +85 -0
- package/dist/providers/chatContext.js.map +1 -0
- package/dist/providers/index.d.ts +6 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/{src/providers/index.ts → dist/providers/index.js} +1 -1
- package/dist/providers/index.js.map +1 -0
- package/dist/providers/userContext.d.ts +6 -0
- package/dist/providers/userContext.d.ts.map +1 -0
- package/dist/providers/userContext.js +70 -0
- package/dist/providers/userContext.js.map +1 -0
- package/dist/service.d.ts +102 -0
- package/dist/service.d.ts.map +1 -0
- package/dist/service.js +433 -0
- package/dist/service.js.map +1 -0
- package/dist/types.d.ts +279 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +106 -0
- package/dist/types.js.map +1 -0
- package/package.json +21 -6
- package/__tests__/integration.test.ts +0 -782
- package/build.ts +0 -16
- package/src/accounts.ts +0 -462
- package/src/actions/sendFlexMessage.ts +0 -243
- package/src/actions/sendLocation.ts +0 -223
- package/src/actions/sendMessage.ts +0 -202
- package/src/index.ts +0 -123
- package/src/messaging.ts +0 -507
- package/src/providers/chatContext.ts +0 -110
- package/src/providers/userContext.ts +0 -99
- package/src/service.ts +0 -578
- package/src/types.ts +0 -417
- package/tsconfig.json +0 -22
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Send location action for the LINE plugin.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import type {
|
|
6
|
-
Action,
|
|
7
|
-
ActionResult,
|
|
8
|
-
HandlerCallback,
|
|
9
|
-
IAgentRuntime,
|
|
10
|
-
Memory,
|
|
11
|
-
State,
|
|
12
|
-
} from "@elizaos/core";
|
|
13
|
-
import {
|
|
14
|
-
composePromptFromState,
|
|
15
|
-
logger,
|
|
16
|
-
ModelType,
|
|
17
|
-
parseJSONObjectFromText,
|
|
18
|
-
} from "@elizaos/core";
|
|
19
|
-
import type { LineService } from "../service.js";
|
|
20
|
-
import {
|
|
21
|
-
isValidLineId,
|
|
22
|
-
LINE_SERVICE_NAME,
|
|
23
|
-
type LineLocationMessage,
|
|
24
|
-
normalizeLineTarget,
|
|
25
|
-
} from "../types.js";
|
|
26
|
-
|
|
27
|
-
const SEND_LOCATION_TEMPLATE = `# Task: Extract LINE location message parameters
|
|
28
|
-
|
|
29
|
-
Based on the conversation, determine the location to send.
|
|
30
|
-
|
|
31
|
-
Recent conversation:
|
|
32
|
-
{{recentMessages}}
|
|
33
|
-
|
|
34
|
-
Extract the following:
|
|
35
|
-
1. title: Place name
|
|
36
|
-
2. address: Full address
|
|
37
|
-
3. latitude: Latitude coordinate (number)
|
|
38
|
-
4. longitude: Longitude coordinate (number)
|
|
39
|
-
5. to: The target user/group/room ID (or "current" to reply to the current chat)
|
|
40
|
-
|
|
41
|
-
Respond with a JSON object:
|
|
42
|
-
\`\`\`json
|
|
43
|
-
{
|
|
44
|
-
"title": "Place Name",
|
|
45
|
-
"address": "123 Main St, City",
|
|
46
|
-
"latitude": 35.6762,
|
|
47
|
-
"longitude": 139.6503,
|
|
48
|
-
"to": "target ID or 'current'"
|
|
49
|
-
}
|
|
50
|
-
\`\`\`
|
|
51
|
-
`;
|
|
52
|
-
|
|
53
|
-
interface LocationParams {
|
|
54
|
-
title: string;
|
|
55
|
-
address: string;
|
|
56
|
-
latitude: number;
|
|
57
|
-
longitude: number;
|
|
58
|
-
to: string;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export const sendLocation: Action = {
|
|
62
|
-
name: "LINE_SEND_LOCATION",
|
|
63
|
-
similes: [
|
|
64
|
-
"SEND_LINE_LOCATION",
|
|
65
|
-
"LINE_LOCATION",
|
|
66
|
-
"LINE_MAP",
|
|
67
|
-
"SHARE_LOCATION_LINE",
|
|
68
|
-
],
|
|
69
|
-
description: "Send a location message via LINE",
|
|
70
|
-
|
|
71
|
-
validate: async (
|
|
72
|
-
_runtime: IAgentRuntime,
|
|
73
|
-
message: Memory,
|
|
74
|
-
_state?: State,
|
|
75
|
-
): Promise<boolean> => {
|
|
76
|
-
return message.content.source === "line";
|
|
77
|
-
},
|
|
78
|
-
|
|
79
|
-
handler: async (
|
|
80
|
-
runtime: IAgentRuntime,
|
|
81
|
-
message: Memory,
|
|
82
|
-
state: State | undefined,
|
|
83
|
-
_options?: Record<string, unknown>,
|
|
84
|
-
callback?: HandlerCallback,
|
|
85
|
-
): Promise<ActionResult> => {
|
|
86
|
-
const lineService = runtime.getService(LINE_SERVICE_NAME) as unknown as
|
|
87
|
-
| LineService
|
|
88
|
-
| undefined;
|
|
89
|
-
|
|
90
|
-
if (!lineService || !lineService.isConnected()) {
|
|
91
|
-
if (callback) {
|
|
92
|
-
callback({ text: "LINE service is not available.", source: "line" });
|
|
93
|
-
}
|
|
94
|
-
return { success: false, error: "LINE service not available" };
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const currentState = state ?? (await runtime.composeState(message));
|
|
98
|
-
|
|
99
|
-
// Extract parameters using LLM
|
|
100
|
-
const prompt = composePromptFromState({
|
|
101
|
-
template: SEND_LOCATION_TEMPLATE,
|
|
102
|
-
state: currentState,
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
let locationInfo: LocationParams | null = null;
|
|
106
|
-
|
|
107
|
-
for (let attempt = 0; attempt < 3; attempt++) {
|
|
108
|
-
const response = await runtime.useModel(ModelType.TEXT_SMALL, {
|
|
109
|
-
prompt,
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
const parsed = parseJSONObjectFromText(response);
|
|
113
|
-
if (
|
|
114
|
-
parsed?.title &&
|
|
115
|
-
parsed?.address &&
|
|
116
|
-
typeof parsed?.latitude === "number" &&
|
|
117
|
-
typeof parsed?.longitude === "number"
|
|
118
|
-
) {
|
|
119
|
-
locationInfo = {
|
|
120
|
-
title: String(parsed.title),
|
|
121
|
-
address: String(parsed.address),
|
|
122
|
-
latitude: Number(parsed.latitude),
|
|
123
|
-
longitude: Number(parsed.longitude),
|
|
124
|
-
to: String(parsed.to || "current"),
|
|
125
|
-
};
|
|
126
|
-
break;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
if (!locationInfo) {
|
|
131
|
-
if (callback) {
|
|
132
|
-
callback({
|
|
133
|
-
text: "I couldn't understand the location information. Please provide title, address, and coordinates.",
|
|
134
|
-
source: "line",
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
return { success: false, error: "Could not extract location parameters" };
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
// Determine target
|
|
141
|
-
let targetId: string | undefined;
|
|
142
|
-
|
|
143
|
-
if (locationInfo.to && locationInfo.to !== "current") {
|
|
144
|
-
const normalized = normalizeLineTarget(locationInfo.to);
|
|
145
|
-
if (normalized && isValidLineId(normalized)) {
|
|
146
|
-
targetId = normalized;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// Fall back to current chat
|
|
151
|
-
if (!targetId) {
|
|
152
|
-
const stateData = (currentState.data || {}) as Record<string, unknown>;
|
|
153
|
-
targetId =
|
|
154
|
-
(stateData.groupId as string) ||
|
|
155
|
-
(stateData.roomId as string) ||
|
|
156
|
-
(stateData.userId as string);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
if (!targetId) {
|
|
160
|
-
if (callback) {
|
|
161
|
-
callback({
|
|
162
|
-
text: "I couldn't determine where to send the location. Please specify a target.",
|
|
163
|
-
source: "line",
|
|
164
|
-
});
|
|
165
|
-
}
|
|
166
|
-
return { success: false, error: "Could not determine target" };
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// Create location message
|
|
170
|
-
const location: LineLocationMessage = {
|
|
171
|
-
type: "location",
|
|
172
|
-
title: locationInfo.title,
|
|
173
|
-
address: locationInfo.address,
|
|
174
|
-
latitude: locationInfo.latitude,
|
|
175
|
-
longitude: locationInfo.longitude,
|
|
176
|
-
};
|
|
177
|
-
|
|
178
|
-
// Send message
|
|
179
|
-
const result = await lineService.sendLocationMessage(targetId, location);
|
|
180
|
-
|
|
181
|
-
if (!result.success) {
|
|
182
|
-
if (callback) {
|
|
183
|
-
callback({
|
|
184
|
-
text: `Failed to send location: ${result.error}`,
|
|
185
|
-
source: "line",
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
return { success: false, error: result.error };
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
logger.debug(`Sent LINE location to ${targetId}`);
|
|
192
|
-
|
|
193
|
-
if (callback) {
|
|
194
|
-
callback({
|
|
195
|
-
text: "Location sent successfully.",
|
|
196
|
-
source: message.content.source as string,
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
return {
|
|
201
|
-
success: true,
|
|
202
|
-
text: "Location sent successfully",
|
|
203
|
-
};
|
|
204
|
-
},
|
|
205
|
-
|
|
206
|
-
examples: [
|
|
207
|
-
[
|
|
208
|
-
{
|
|
209
|
-
name: "{{user1}}",
|
|
210
|
-
content: {
|
|
211
|
-
text: "Send them the location of Tokyo Tower",
|
|
212
|
-
},
|
|
213
|
-
},
|
|
214
|
-
{
|
|
215
|
-
name: "{{agent}}",
|
|
216
|
-
content: {
|
|
217
|
-
text: "I'll send the location.",
|
|
218
|
-
actions: ["LINE_SEND_LOCATION"],
|
|
219
|
-
},
|
|
220
|
-
},
|
|
221
|
-
],
|
|
222
|
-
],
|
|
223
|
-
};
|
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Send message action for the LINE plugin.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import type {
|
|
6
|
-
Action,
|
|
7
|
-
ActionResult,
|
|
8
|
-
HandlerCallback,
|
|
9
|
-
IAgentRuntime,
|
|
10
|
-
Memory,
|
|
11
|
-
State,
|
|
12
|
-
} from "@elizaos/core";
|
|
13
|
-
import {
|
|
14
|
-
composePromptFromState,
|
|
15
|
-
logger,
|
|
16
|
-
ModelType,
|
|
17
|
-
parseJSONObjectFromText,
|
|
18
|
-
} from "@elizaos/core";
|
|
19
|
-
import type { LineService } from "../service.js";
|
|
20
|
-
import {
|
|
21
|
-
isValidLineId,
|
|
22
|
-
LINE_SERVICE_NAME,
|
|
23
|
-
normalizeLineTarget,
|
|
24
|
-
} from "../types.js";
|
|
25
|
-
|
|
26
|
-
const SEND_MESSAGE_TEMPLATE = `# Task: Extract LINE message parameters
|
|
27
|
-
|
|
28
|
-
Based on the conversation, determine what message to send and to whom.
|
|
29
|
-
|
|
30
|
-
Recent conversation:
|
|
31
|
-
{{recentMessages}}
|
|
32
|
-
|
|
33
|
-
Extract the following:
|
|
34
|
-
1. text: The message content to send
|
|
35
|
-
2. to: The target user/group/room ID (or "current" to reply to the current chat)
|
|
36
|
-
|
|
37
|
-
Respond with a JSON object:
|
|
38
|
-
\`\`\`json
|
|
39
|
-
{
|
|
40
|
-
"text": "message to send",
|
|
41
|
-
"to": "target ID or 'current'"
|
|
42
|
-
}
|
|
43
|
-
\`\`\`
|
|
44
|
-
`;
|
|
45
|
-
|
|
46
|
-
interface SendMessageParams {
|
|
47
|
-
text: string;
|
|
48
|
-
to: string;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export const sendMessage: Action = {
|
|
52
|
-
name: "LINE_SEND_MESSAGE",
|
|
53
|
-
similes: ["SEND_LINE_MESSAGE", "LINE_MESSAGE", "LINE_TEXT", "MESSAGE_LINE"],
|
|
54
|
-
description: "Send a text message via LINE",
|
|
55
|
-
|
|
56
|
-
validate: async (
|
|
57
|
-
_runtime: IAgentRuntime,
|
|
58
|
-
message: Memory,
|
|
59
|
-
_state?: State,
|
|
60
|
-
): Promise<boolean> => {
|
|
61
|
-
return message.content.source === "line";
|
|
62
|
-
},
|
|
63
|
-
|
|
64
|
-
handler: async (
|
|
65
|
-
runtime: IAgentRuntime,
|
|
66
|
-
message: Memory,
|
|
67
|
-
state: State | undefined,
|
|
68
|
-
_options?: Record<string, unknown>,
|
|
69
|
-
callback?: HandlerCallback,
|
|
70
|
-
): Promise<ActionResult> => {
|
|
71
|
-
const lineService = runtime.getService(LINE_SERVICE_NAME) as unknown as
|
|
72
|
-
| LineService
|
|
73
|
-
| undefined;
|
|
74
|
-
|
|
75
|
-
if (!lineService || !lineService.isConnected()) {
|
|
76
|
-
if (callback) {
|
|
77
|
-
callback({ text: "LINE service is not available.", source: "line" });
|
|
78
|
-
}
|
|
79
|
-
return { success: false, error: "LINE service not available" };
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const currentState = state ?? (await runtime.composeState(message));
|
|
83
|
-
|
|
84
|
-
// Extract parameters using LLM
|
|
85
|
-
const prompt = composePromptFromState({
|
|
86
|
-
template: SEND_MESSAGE_TEMPLATE,
|
|
87
|
-
state: currentState,
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
let msgInfo: SendMessageParams | null = null;
|
|
91
|
-
|
|
92
|
-
for (let attempt = 0; attempt < 3; attempt++) {
|
|
93
|
-
const response = await runtime.useModel(ModelType.TEXT_SMALL, {
|
|
94
|
-
prompt,
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
const parsed = parseJSONObjectFromText(response);
|
|
98
|
-
if (parsed?.text) {
|
|
99
|
-
msgInfo = {
|
|
100
|
-
text: String(parsed.text),
|
|
101
|
-
to: String(parsed.to || "current"),
|
|
102
|
-
};
|
|
103
|
-
break;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if (!msgInfo || !msgInfo.text) {
|
|
108
|
-
if (callback) {
|
|
109
|
-
callback({
|
|
110
|
-
text: "I couldn't understand what message you want me to send. Please try again.",
|
|
111
|
-
source: "line",
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
return { success: false, error: "Could not extract message parameters" };
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// Determine target
|
|
118
|
-
let targetId: string | undefined;
|
|
119
|
-
|
|
120
|
-
if (msgInfo.to && msgInfo.to !== "current") {
|
|
121
|
-
const normalized = normalizeLineTarget(msgInfo.to);
|
|
122
|
-
if (normalized && isValidLineId(normalized)) {
|
|
123
|
-
targetId = normalized;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// Fall back to current chat
|
|
128
|
-
if (!targetId) {
|
|
129
|
-
const stateData = (currentState.data || {}) as Record<string, unknown>;
|
|
130
|
-
targetId =
|
|
131
|
-
(stateData.groupId as string) ||
|
|
132
|
-
(stateData.roomId as string) ||
|
|
133
|
-
(stateData.userId as string);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if (!targetId) {
|
|
137
|
-
if (callback) {
|
|
138
|
-
callback({
|
|
139
|
-
text: "I couldn't determine where to send the message. Please specify a target.",
|
|
140
|
-
source: "line",
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
return { success: false, error: "Could not determine target" };
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// Send message
|
|
147
|
-
const result = await lineService.sendMessage(targetId, msgInfo.text);
|
|
148
|
-
|
|
149
|
-
if (!result.success) {
|
|
150
|
-
if (callback) {
|
|
151
|
-
callback({
|
|
152
|
-
text: `Failed to send message: ${result.error}`,
|
|
153
|
-
source: "line",
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
return { success: false, error: result.error };
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
logger.debug(`Sent LINE message to ${targetId}`);
|
|
160
|
-
|
|
161
|
-
if (callback) {
|
|
162
|
-
callback({
|
|
163
|
-
text: "Message sent successfully.",
|
|
164
|
-
source: message.content.source as string,
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
return {
|
|
169
|
-
success: true,
|
|
170
|
-
text: "Message sent successfully",
|
|
171
|
-
};
|
|
172
|
-
},
|
|
173
|
-
|
|
174
|
-
examples: [
|
|
175
|
-
[
|
|
176
|
-
{
|
|
177
|
-
name: "{{user1}}",
|
|
178
|
-
content: { text: "Send them a message saying 'Hello!'" },
|
|
179
|
-
},
|
|
180
|
-
{
|
|
181
|
-
name: "{{agent}}",
|
|
182
|
-
content: {
|
|
183
|
-
text: "I'll send that message via LINE.",
|
|
184
|
-
actions: ["LINE_SEND_MESSAGE"],
|
|
185
|
-
},
|
|
186
|
-
},
|
|
187
|
-
],
|
|
188
|
-
[
|
|
189
|
-
{
|
|
190
|
-
name: "{{user1}}",
|
|
191
|
-
content: { text: "Message the group saying 'Meeting in 5 minutes'" },
|
|
192
|
-
},
|
|
193
|
-
{
|
|
194
|
-
name: "{{agent}}",
|
|
195
|
-
content: {
|
|
196
|
-
text: "I'll send that to the group.",
|
|
197
|
-
actions: ["LINE_SEND_MESSAGE"],
|
|
198
|
-
},
|
|
199
|
-
},
|
|
200
|
-
],
|
|
201
|
-
],
|
|
202
|
-
};
|
package/src/index.ts
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* LINE Plugin for ElizaOS
|
|
3
|
-
*
|
|
4
|
-
* Provides LINE Messaging API integration for ElizaOS agents,
|
|
5
|
-
* supporting text, flex messages, locations, and more.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import type { IAgentRuntime, Plugin } from "@elizaos/core";
|
|
9
|
-
import { logger } from "@elizaos/core";
|
|
10
|
-
import { sendFlexMessage, sendLocation, sendMessage } from "./actions/index.js";
|
|
11
|
-
import { chatContextProvider, userContextProvider } from "./providers/index.js";
|
|
12
|
-
import { LineService } from "./service.js";
|
|
13
|
-
|
|
14
|
-
// Re-export types and service
|
|
15
|
-
export * from "./types.js";
|
|
16
|
-
export { LineService };
|
|
17
|
-
export { sendMessage, sendFlexMessage, sendLocation };
|
|
18
|
-
export { chatContextProvider, userContextProvider };
|
|
19
|
-
|
|
20
|
-
// Account management exports
|
|
21
|
-
export {
|
|
22
|
-
DEFAULT_ACCOUNT_ID,
|
|
23
|
-
isLineMentionRequired,
|
|
24
|
-
isLineUserAllowed,
|
|
25
|
-
isMultiAccountEnabled,
|
|
26
|
-
type LineAccountConfig,
|
|
27
|
-
type LineGroupConfig,
|
|
28
|
-
type LineMultiAccountConfig,
|
|
29
|
-
type LineTokenResolution,
|
|
30
|
-
type LineTokenSource,
|
|
31
|
-
listEnabledLineAccounts,
|
|
32
|
-
listLineAccountIds,
|
|
33
|
-
normalizeAccountId,
|
|
34
|
-
type ResolvedLineAccount,
|
|
35
|
-
resolveDefaultLineAccountId,
|
|
36
|
-
resolveLineAccount,
|
|
37
|
-
resolveLineGroupConfig,
|
|
38
|
-
resolveLineSecret,
|
|
39
|
-
resolveLineToken,
|
|
40
|
-
} from "./accounts.js";
|
|
41
|
-
|
|
42
|
-
// Messaging utilities exports
|
|
43
|
-
export {
|
|
44
|
-
buildLineDeepLink,
|
|
45
|
-
type ChunkLineTextOpts,
|
|
46
|
-
type CodeBlock,
|
|
47
|
-
chunkLineText,
|
|
48
|
-
extractCodeBlocks,
|
|
49
|
-
extractLinks,
|
|
50
|
-
extractMarkdownTables,
|
|
51
|
-
formatCodeBlockAsText,
|
|
52
|
-
formatLineUser,
|
|
53
|
-
formatTableAsText,
|
|
54
|
-
getChatId,
|
|
55
|
-
getChatType,
|
|
56
|
-
hasMarkdownContent,
|
|
57
|
-
isGroupChat,
|
|
58
|
-
LINE_MAX_REPLY_MESSAGES,
|
|
59
|
-
LINE_TEXT_CHUNK_LIMIT,
|
|
60
|
-
type MarkdownLink,
|
|
61
|
-
type MarkdownTable,
|
|
62
|
-
markdownToLineChunks,
|
|
63
|
-
type ProcessedLineMessage,
|
|
64
|
-
processLineMessage,
|
|
65
|
-
resolveLineSystemLocation,
|
|
66
|
-
stripMarkdown,
|
|
67
|
-
truncateText,
|
|
68
|
-
} from "./messaging.js";
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* LINE plugin for ElizaOS agents.
|
|
72
|
-
*/
|
|
73
|
-
const linePlugin: Plugin = {
|
|
74
|
-
name: "line",
|
|
75
|
-
description: "LINE Messaging API plugin for ElizaOS agents",
|
|
76
|
-
|
|
77
|
-
services: [LineService],
|
|
78
|
-
actions: [sendMessage, sendFlexMessage, sendLocation],
|
|
79
|
-
providers: [chatContextProvider, userContextProvider],
|
|
80
|
-
tests: [],
|
|
81
|
-
|
|
82
|
-
init: async (
|
|
83
|
-
config: Record<string, string>,
|
|
84
|
-
_runtime: IAgentRuntime,
|
|
85
|
-
): Promise<void> => {
|
|
86
|
-
logger.info("Initializing LINE plugin...");
|
|
87
|
-
|
|
88
|
-
const hasAccessToken = Boolean(
|
|
89
|
-
config.LINE_CHANNEL_ACCESS_TOKEN || process.env.LINE_CHANNEL_ACCESS_TOKEN,
|
|
90
|
-
);
|
|
91
|
-
const hasSecret = Boolean(
|
|
92
|
-
config.LINE_CHANNEL_SECRET || process.env.LINE_CHANNEL_SECRET,
|
|
93
|
-
);
|
|
94
|
-
|
|
95
|
-
logger.info("LINE plugin configuration:");
|
|
96
|
-
logger.info(
|
|
97
|
-
` - Access token configured: ${hasAccessToken ? "Yes" : "No"}`,
|
|
98
|
-
);
|
|
99
|
-
logger.info(` - Channel secret configured: ${hasSecret ? "Yes" : "No"}`);
|
|
100
|
-
logger.info(
|
|
101
|
-
` - DM policy: ${config.LINE_DM_POLICY || process.env.LINE_DM_POLICY || "pairing"}`,
|
|
102
|
-
);
|
|
103
|
-
logger.info(
|
|
104
|
-
` - Group policy: ${config.LINE_GROUP_POLICY || process.env.LINE_GROUP_POLICY || "allowlist"}`,
|
|
105
|
-
);
|
|
106
|
-
|
|
107
|
-
if (!hasAccessToken) {
|
|
108
|
-
logger.warn(
|
|
109
|
-
"LINE channel access token not configured. Set LINE_CHANNEL_ACCESS_TOKEN.",
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
if (!hasSecret) {
|
|
114
|
-
logger.warn(
|
|
115
|
-
"LINE channel secret not configured. Set LINE_CHANNEL_SECRET.",
|
|
116
|
-
);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
logger.info("LINE plugin initialized");
|
|
120
|
-
},
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
export default linePlugin;
|