@ynhcj/xiaoyi-channel 1.0.3 → 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 +38 -39
- 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: {
|
|
@@ -82,25 +81,25 @@ export class XYPushService {
|
|
|
82
81
|
body: JSON.stringify(requestBody),
|
|
83
82
|
});
|
|
84
83
|
// Log response status and headers
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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')}`);
|
|
89
88
|
if (!response.ok) {
|
|
90
89
|
const errorText = await response.text();
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
90
|
+
console.log(`[PUSH] ❌ Push request failed`);
|
|
91
|
+
console.log(`[PUSH] - HTTP Status: ${response.status}`);
|
|
92
|
+
console.log(`[PUSH] - Response body: ${errorText}`);
|
|
94
93
|
throw new Error(`Push failed: HTTP ${response.status} - ${errorText}`);
|
|
95
94
|
}
|
|
96
95
|
// Try to parse JSON response with detailed error handling
|
|
97
96
|
let result;
|
|
98
97
|
try {
|
|
99
98
|
const responseText = await response.text();
|
|
100
|
-
|
|
101
|
-
|
|
99
|
+
console.log(`[PUSH] 📄 Response body length: ${responseText.length} chars`);
|
|
100
|
+
console.log(`[PUSH] 📄 Response body preview: ${responseText.substring(0, 200)}`);
|
|
102
101
|
if (!responseText || responseText.trim() === '') {
|
|
103
|
-
|
|
102
|
+
console.log(`[PUSH] ⚠️ Received empty response body`);
|
|
104
103
|
result = {};
|
|
105
104
|
}
|
|
106
105
|
else {
|
|
@@ -108,28 +107,28 @@ export class XYPushService {
|
|
|
108
107
|
}
|
|
109
108
|
}
|
|
110
109
|
catch (parseError) {
|
|
111
|
-
|
|
112
|
-
|
|
110
|
+
console.log(`[PUSH] ❌ Failed to parse JSON response`);
|
|
111
|
+
console.log(`[PUSH] - Parse error: ${parseError instanceof Error ? parseError.message : String(parseError)}`);
|
|
113
112
|
throw new Error(`Invalid JSON response from push service: ${parseError instanceof Error ? parseError.message : String(parseError)}`);
|
|
114
113
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
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);
|
|
120
119
|
}
|
|
121
120
|
catch (error) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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)}...`);
|
|
126
125
|
if (error instanceof Error) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
126
|
+
console.log(`[PUSH] - Error name: ${error.name}`);
|
|
127
|
+
console.log(`[PUSH] - Error message: ${error.message}`);
|
|
128
|
+
console.log(`[PUSH] - Error stack:`, error.stack);
|
|
130
129
|
}
|
|
131
130
|
else {
|
|
132
|
-
|
|
131
|
+
console.log(`[PUSH] - Error:`, error);
|
|
133
132
|
}
|
|
134
133
|
throw error;
|
|
135
134
|
}
|