@zlr_236/popo 0.0.6 → 0.0.8
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/package.json +1 -1
- package/src/bot.ts +22 -32
- package/src/monitor.ts +1 -1
package/package.json
CHANGED
package/src/bot.ts
CHANGED
|
@@ -20,6 +20,15 @@ import {
|
|
|
20
20
|
import { createPopoReplyDispatcher } from "./reply-dispatcher.js";
|
|
21
21
|
import { downloadMessageFilePopo } from "./media.js";
|
|
22
22
|
|
|
23
|
+
//1-普通文本消息 211 - 引用消息; 171 - 文件消息; 142 - 视频消息; 161 - 合并消息;
|
|
24
|
+
export enum PopoEventType {
|
|
25
|
+
Message = 1,
|
|
26
|
+
Qoute = 2,
|
|
27
|
+
File = 171,
|
|
28
|
+
Video = 142,
|
|
29
|
+
Merge = 161,
|
|
30
|
+
}
|
|
31
|
+
|
|
23
32
|
export type PopoMessageEvent = {
|
|
24
33
|
eventType: "IM_P2P_TO_ROBOT_MSG" | "IM_CHAT_TO_ROBOT_AT_MSG";
|
|
25
34
|
eventData: {
|
|
@@ -27,8 +36,7 @@ export type PopoMessageEvent = {
|
|
|
27
36
|
from: string; // Sender email
|
|
28
37
|
sessionId: string; // P2P=email, group=groupId
|
|
29
38
|
notify: string; // Message content
|
|
30
|
-
msgType?:
|
|
31
|
-
fileId?: string; // File message ID
|
|
39
|
+
msgType?: PopoEventType; // text, image, file, etc.
|
|
32
40
|
timestamp?: number;
|
|
33
41
|
groupId?: string;
|
|
34
42
|
fileInfo?: {
|
|
@@ -51,11 +59,8 @@ export type PopoActionEvent = {
|
|
|
51
59
|
};
|
|
52
60
|
};
|
|
53
61
|
|
|
54
|
-
function parseMessageContent(
|
|
55
|
-
|
|
56
|
-
msgType?: string | number,
|
|
57
|
-
): string {
|
|
58
|
-
if (msgType === "text" || !msgType) {
|
|
62
|
+
function parseMessageContent(notify: string, msgType?: number): string {
|
|
63
|
+
if (msgType === 1 || !msgType) {
|
|
59
64
|
return notify;
|
|
60
65
|
}
|
|
61
66
|
// For non-text messages, return the raw notify as placeholder
|
|
@@ -74,7 +79,6 @@ function inferPlaceholder(msgType?: string | number): string {
|
|
|
74
79
|
case 171:
|
|
75
80
|
return "<media:document>";
|
|
76
81
|
case "audio":
|
|
77
|
-
case 171:
|
|
78
82
|
return "<media:audio>";
|
|
79
83
|
case "video":
|
|
80
84
|
case 142:
|
|
@@ -94,16 +98,12 @@ async function resolvePopoMediaList(params: {
|
|
|
94
98
|
log?: (msg: string) => void;
|
|
95
99
|
}): Promise<PopoMediaInfo[]> {
|
|
96
100
|
const { cfg, event, maxBytes, log } = params;
|
|
97
|
-
const { msgType,
|
|
101
|
+
const { msgType, fileInfo } = event.eventData;
|
|
98
102
|
log?.(`popo: resolvePopoMediaList: ${JSON.stringify(event)}`);
|
|
99
103
|
|
|
100
104
|
// Only process media message types
|
|
101
|
-
const mediaTypes = [
|
|
102
|
-
if (
|
|
103
|
-
!msgType ||
|
|
104
|
-
!mediaTypes.includes(msgType) ||
|
|
105
|
-
(!fileId && !fileInfo?.fileId)
|
|
106
|
-
) {
|
|
105
|
+
const mediaTypes = [PopoEventType.File, PopoEventType.Video];
|
|
106
|
+
if (!msgType || !mediaTypes.includes(msgType) || !fileInfo?.fileId) {
|
|
107
107
|
return [];
|
|
108
108
|
}
|
|
109
109
|
|
|
@@ -114,22 +114,9 @@ async function resolvePopoMediaList(params: {
|
|
|
114
114
|
// First, get download URL using downloadMessageFilePopo
|
|
115
115
|
const urlResult = await downloadMessageFilePopo({
|
|
116
116
|
cfg,
|
|
117
|
-
fileId:
|
|
117
|
+
fileId: fileInfo?.fileId,
|
|
118
118
|
});
|
|
119
|
-
|
|
120
|
-
try {
|
|
121
|
-
// Write urlResult to res.txt
|
|
122
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
123
|
-
const __dirname = dirname(__filename);
|
|
124
|
-
const resFilePath = join(__dirname, "res.txt");
|
|
125
|
-
await fs.writeFile(
|
|
126
|
-
resFilePath,
|
|
127
|
-
JSON.stringify(urlResult, null, 2),
|
|
128
|
-
"utf-8",
|
|
129
|
-
);
|
|
130
|
-
} catch (e) {
|
|
131
|
-
log?.(`popo: DEBUG failed to write event data: ${String(e)}`);
|
|
132
|
-
}
|
|
119
|
+
log?.(`popo: 33333333333333333 ${JSON.stringify(urlResult)}`);
|
|
133
120
|
|
|
134
121
|
if (!urlResult.success || !urlResult.downloadUrl) {
|
|
135
122
|
throw new Error(urlResult.error || "Failed to get download URL");
|
|
@@ -138,6 +125,7 @@ async function resolvePopoMediaList(params: {
|
|
|
138
125
|
// Fetch file content from the download URL
|
|
139
126
|
const response = await fetch(urlResult.downloadUrl);
|
|
140
127
|
if (!response.ok) {
|
|
128
|
+
log?.(`popo: 44444444444444444 ${JSON.stringify(response)}`);
|
|
141
129
|
throw new Error(
|
|
142
130
|
`Failed to fetch file: ${response.status} ${response.statusText}`,
|
|
143
131
|
);
|
|
@@ -213,7 +201,7 @@ export function parsePopoMessageEvent(
|
|
|
213
201
|
chatType: isGroup ? "group" : "p2p",
|
|
214
202
|
content,
|
|
215
203
|
contentType: eventData.msgType ?? "text",
|
|
216
|
-
fileId: eventData.
|
|
204
|
+
fileId: eventData.fileInfo?.fileId,
|
|
217
205
|
};
|
|
218
206
|
}
|
|
219
207
|
|
|
@@ -325,7 +313,9 @@ export async function handlePopoMessage(params: {
|
|
|
325
313
|
sessionKey: route.sessionKey,
|
|
326
314
|
contextKey: `popo:message:${ctx.sessionId}:${ctx.messageId}`,
|
|
327
315
|
});
|
|
328
|
-
|
|
316
|
+
log(
|
|
317
|
+
`popo: 111111111111111111 ${JSON.parse(ctx.messageId)} ${JSON.stringify(event)} ${JSON.stringify(popoCfg)}`,
|
|
318
|
+
);
|
|
329
319
|
// Resolve media from message
|
|
330
320
|
const mediaMaxBytes = (popoCfg?.mediaMaxMb ?? 20) * 1024 * 1024;
|
|
331
321
|
const mediaList = await resolvePopoMediaList({
|
package/src/monitor.ts
CHANGED
|
@@ -178,7 +178,7 @@ export async function monitorPopoProvider(
|
|
|
178
178
|
log(`popo: DEBUG write failed: ${String(e)}`);
|
|
179
179
|
}
|
|
180
180
|
log(
|
|
181
|
-
`popo:
|
|
181
|
+
`popo: DEBUG2 eventType=${event.eventType} eventData=${JSON.stringify(eventData).slice(0, 500)}`,
|
|
182
182
|
);
|
|
183
183
|
|
|
184
184
|
// Handle valid_url event
|