@ynhcj/xiaoyi-channel 1.0.2 → 1.0.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/src/push.js +57 -26
- package/package.json +1 -1
package/dist/src/push.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
// Push message service for scheduled tasks
|
|
2
2
|
import fetch from "node-fetch";
|
|
3
3
|
import { randomUUID } from "crypto";
|
|
4
|
-
import { logger } from "./utils/logger.js";
|
|
5
4
|
import { configManager } from "./utils/config-manager.js";
|
|
6
5
|
/**
|
|
7
6
|
* Service for sending push messages to users.
|
|
@@ -29,22 +28,22 @@ export class XYPushService {
|
|
|
29
28
|
// Get dynamic pushId for the session (falls back to config pushId)
|
|
30
29
|
const dynamicPushId = configManager.getPushId(sessionId);
|
|
31
30
|
const pushId = dynamicPushId || this.config.pushId;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
31
|
+
console.log(`[PUSH] 📤 Preparing to send push message`);
|
|
32
|
+
console.log(`[PUSH] - Title: "${title}"`);
|
|
33
|
+
console.log(`[PUSH] - Content length: ${content.length} chars`);
|
|
34
|
+
console.log(`[PUSH] - Session ID: ${sessionId || 'none'}`);
|
|
35
|
+
console.log(`[PUSH] - Trace ID: ${traceId}`);
|
|
36
|
+
console.log(`[PUSH] - Push URL: ${pushUrl}`);
|
|
38
37
|
if (dynamicPushId) {
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
console.log(`[PUSH] - Using dynamic pushId (from session): ${pushId.substring(0, 20)}...`);
|
|
39
|
+
console.log(`[PUSH] - Full dynamic pushId: ${pushId}`);
|
|
41
40
|
}
|
|
42
41
|
else {
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
console.log(`[PUSH] - Using config pushId (fallback): ${pushId.substring(0, 20)}...`);
|
|
43
|
+
console.log(`[PUSH] - Full config pushId: ${pushId}`);
|
|
45
44
|
}
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
console.log(`[PUSH] - API ID: ${this.config.apiId}`);
|
|
46
|
+
console.log(`[PUSH] - UID: ${this.config.uid}`);
|
|
48
47
|
try {
|
|
49
48
|
const requestBody = {
|
|
50
49
|
jsonrpc: "2.0",
|
|
@@ -68,7 +67,7 @@ export class XYPushService {
|
|
|
68
67
|
],
|
|
69
68
|
},
|
|
70
69
|
};
|
|
71
|
-
|
|
70
|
+
console.log(`[PUSH] Full request body:`, JSON.stringify(requestBody, null, 2));
|
|
72
71
|
const response = await fetch(pushUrl, {
|
|
73
72
|
method: "POST",
|
|
74
73
|
headers: {
|
|
@@ -81,24 +80,56 @@ export class XYPushService {
|
|
|
81
80
|
},
|
|
82
81
|
body: JSON.stringify(requestBody),
|
|
83
82
|
});
|
|
83
|
+
// Log response status and headers
|
|
84
|
+
console.log(`[PUSH] 📥 Response received`);
|
|
85
|
+
console.log(`[PUSH] - HTTP Status: ${response.status} ${response.statusText}`);
|
|
86
|
+
console.log(`[PUSH] - Content-Type: ${response.headers.get('content-type')}`);
|
|
87
|
+
console.log(`[PUSH] - Content-Length: ${response.headers.get('content-length')}`);
|
|
84
88
|
if (!response.ok) {
|
|
85
89
|
const errorText = await response.text();
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
90
|
+
console.log(`[PUSH] ❌ Push request failed`);
|
|
91
|
+
console.log(`[PUSH] - HTTP Status: ${response.status}`);
|
|
92
|
+
console.log(`[PUSH] - Response body: ${errorText}`);
|
|
89
93
|
throw new Error(`Push failed: HTTP ${response.status} - ${errorText}`);
|
|
90
94
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
95
|
+
// Try to parse JSON response with detailed error handling
|
|
96
|
+
let result;
|
|
97
|
+
try {
|
|
98
|
+
const responseText = await response.text();
|
|
99
|
+
console.log(`[PUSH] 📄 Response body length: ${responseText.length} chars`);
|
|
100
|
+
console.log(`[PUSH] 📄 Response body preview: ${responseText.substring(0, 200)}`);
|
|
101
|
+
if (!responseText || responseText.trim() === '') {
|
|
102
|
+
console.log(`[PUSH] ⚠️ Received empty response body`);
|
|
103
|
+
result = {};
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
result = JSON.parse(responseText);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
catch (parseError) {
|
|
110
|
+
console.log(`[PUSH] ❌ Failed to parse JSON response`);
|
|
111
|
+
console.log(`[PUSH] - Parse error: ${parseError instanceof Error ? parseError.message : String(parseError)}`);
|
|
112
|
+
throw new Error(`Invalid JSON response from push service: ${parseError instanceof Error ? parseError.message : String(parseError)}`);
|
|
113
|
+
}
|
|
114
|
+
console.log(`[PUSH] ✅ Push message sent successfully`);
|
|
115
|
+
console.log(`[PUSH] - Title: "${title}"`);
|
|
116
|
+
console.log(`[PUSH] - Trace ID: ${traceId}`);
|
|
117
|
+
console.log(`[PUSH] - Used pushId: ${pushId.substring(0, 20)}...`);
|
|
118
|
+
console.log(`[PUSH] - Response:`, result);
|
|
97
119
|
}
|
|
98
120
|
catch (error) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
121
|
+
console.log(`[PUSH] ❌ Failed to send push message`);
|
|
122
|
+
console.log(`[PUSH] - Trace ID: ${traceId}`);
|
|
123
|
+
console.log(`[PUSH] - Target URL: ${pushUrl}`);
|
|
124
|
+
console.log(`[PUSH] - Push ID: ${pushId.substring(0, 20)}...`);
|
|
125
|
+
if (error instanceof Error) {
|
|
126
|
+
console.log(`[PUSH] - Error name: ${error.name}`);
|
|
127
|
+
console.log(`[PUSH] - Error message: ${error.message}`);
|
|
128
|
+
console.log(`[PUSH] - Error stack:`, error.stack);
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
console.log(`[PUSH] - Error:`, error);
|
|
132
|
+
}
|
|
102
133
|
throw error;
|
|
103
134
|
}
|
|
104
135
|
}
|