@zlr_236/popo 0.0.7 → 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 +18 -19
- 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,17 +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
|
-
) {
|
|
107
|
-
log(`popo: 22222222222222222`);
|
|
105
|
+
const mediaTypes = [PopoEventType.File, PopoEventType.Video];
|
|
106
|
+
if (!msgType || !mediaTypes.includes(msgType) || !fileInfo?.fileId) {
|
|
108
107
|
return [];
|
|
109
108
|
}
|
|
110
109
|
|
|
@@ -115,7 +114,7 @@ async function resolvePopoMediaList(params: {
|
|
|
115
114
|
// First, get download URL using downloadMessageFilePopo
|
|
116
115
|
const urlResult = await downloadMessageFilePopo({
|
|
117
116
|
cfg,
|
|
118
|
-
fileId:
|
|
117
|
+
fileId: fileInfo?.fileId,
|
|
119
118
|
});
|
|
120
119
|
log?.(`popo: 33333333333333333 ${JSON.stringify(urlResult)}`);
|
|
121
120
|
|
|
@@ -126,7 +125,7 @@ async function resolvePopoMediaList(params: {
|
|
|
126
125
|
// Fetch file content from the download URL
|
|
127
126
|
const response = await fetch(urlResult.downloadUrl);
|
|
128
127
|
if (!response.ok) {
|
|
129
|
-
log?.(`popo: 44444444444444444 ${response}`);
|
|
128
|
+
log?.(`popo: 44444444444444444 ${JSON.stringify(response)}`);
|
|
130
129
|
throw new Error(
|
|
131
130
|
`Failed to fetch file: ${response.status} ${response.statusText}`,
|
|
132
131
|
);
|
|
@@ -202,7 +201,7 @@ export function parsePopoMessageEvent(
|
|
|
202
201
|
chatType: isGroup ? "group" : "p2p",
|
|
203
202
|
content,
|
|
204
203
|
contentType: eventData.msgType ?? "text",
|
|
205
|
-
fileId: eventData.
|
|
204
|
+
fileId: eventData.fileInfo?.fileId,
|
|
206
205
|
};
|
|
207
206
|
}
|
|
208
207
|
|
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
|