-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsend-final-version.js
More file actions
224 lines (186 loc) · 6.32 KB
/
send-final-version.js
File metadata and controls
224 lines (186 loc) · 6.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#!/usr/bin/env node
// Send the final perfect mobile diff design to Telegram
const fs = require('fs');
const path = require('path');
const os = require('os');
const https = require('https');
// Load config
function loadConfig() {
const configPath = path.join(os.homedir(), '.afk', 'config.json');
try {
return JSON.parse(fs.readFileSync(configPath, 'utf8'));
} catch (e) {
throw new Error('Could not load AFK config');
}
}
// Send document to Telegram
async function sendTelegramDocument(token, chatId, imagePath, caption, filename) {
const boundary = '----AFK' + Math.random().toString(36).substring(2);
const imageData = fs.readFileSync(imagePath);
const parts = [];
parts.push(`--${boundary}\r\n`);
parts.push(`Content-Disposition: form-data; name="chat_id"\r\n\r\n`);
parts.push(`${chatId}\r\n`);
if (caption) {
parts.push(`--${boundary}\r\n`);
parts.push(`Content-Disposition: form-data; name="caption"\r\n\r\n`);
parts.push(`${caption}\r\n`);
}
parts.push(`--${boundary}\r\n`);
parts.push(`Content-Disposition: form-data; name="document"; filename="${filename}"\r\n`);
parts.push(`Content-Type: image/png\r\n\r\n`);
const formDataBuffer = Buffer.concat([
Buffer.from(parts.join('')),
imageData,
Buffer.from(`\r\n--${boundary}--\r\n`)
]);
const options = {
hostname: 'api.telegram.org',
path: `/bot${token}/sendDocument`,
method: 'POST',
headers: {
'Content-Type': `multipart/form-data; boundary=${boundary}`,
'Content-Length': formDataBuffer.length
},
timeout: 30000
};
return new Promise((resolve, reject) => {
const req = https.request(options, res => {
let out = '';
res.on('data', c => out += c);
res.on('end', () => {
try {
const j = JSON.parse(out || '{}');
if (j.ok) {
resolve(j.result);
} else {
reject(new Error(j.description || 'Telegram API error'));
}
} catch (e) {
reject(new Error('Invalid response from Telegram'));
}
});
});
req.on('error', reject);
req.on('timeout', () => {
req.destroy();
reject(new Error('Request timeout'));
});
req.write(formDataBuffer);
req.end();
});
}
// Send photo to Telegram (fallback function)
async function sendTelegramPhoto(token, chatId, imagePath, caption) {
const boundary = '----AFK' + Math.random().toString(36).substring(2);
const imageData = fs.readFileSync(imagePath);
const parts = [];
parts.push(`--${boundary}\r\n`);
parts.push(`Content-Disposition: form-data; name="chat_id"\r\n\r\n`);
parts.push(`${chatId}\r\n`);
if (caption) {
parts.push(`--${boundary}\r\n`);
parts.push(`Content-Disposition: form-data; name="caption"\r\n\r\n`);
parts.push(`${caption}\r\n`);
}
parts.push(`--${boundary}\r\n`);
parts.push(`Content-Disposition: form-data; name="photo"; filename="final-mobile-diff.png"\r\n`);
parts.push(`Content-Type: image/png\r\n\r\n`);
const formDataBuffer = Buffer.concat([
Buffer.from(parts.join('')),
imageData,
Buffer.from(`\r\n--${boundary}--\r\n`)
]);
const options = {
hostname: 'api.telegram.org',
path: `/bot${token}/sendPhoto`,
method: 'POST',
headers: {
'Content-Type': `multipart/form-data; boundary=${boundary}`,
'Content-Length': formDataBuffer.length
},
timeout: 30000
};
return new Promise((resolve, reject) => {
const req = https.request(options, res => {
let out = '';
res.on('data', c => out += c);
res.on('end', () => {
try {
const j = JSON.parse(out || '{}');
if (j.ok) {
resolve(j.result);
} else {
reject(new Error(j.description || 'Telegram API error'));
}
} catch (e) {
reject(new Error('Invalid response from Telegram'));
}
});
});
req.on('error', reject);
req.on('timeout', () => {
req.destroy();
reject(new Error('Request timeout'));
});
req.write(formDataBuffer);
req.end();
});
}
async function sendFinalVersion() {
console.log('🚀 Sending FINAL PERFECT mobile diff design...');
try {
const config = loadConfig();
if (!config.telegram_bot_token || !config.telegram_chat_id) {
console.log('❌ Telegram not configured');
return;
}
const imagePath = path.join(process.cwd(), 'generated-diff-image.png');
if (!fs.existsSync(imagePath)) {
console.log('❌ Final image not found. Running generation script first...');
// Run the generation script
const { execSync } = require('child_process');
execSync('node generate-and-read-diff.js', { stdio: 'inherit' });
}
const stats = fs.statSync(imagePath);
console.log(`✅ Sending FINAL VERSION: ${(stats.size / 1024).toFixed(1)} KB`);
const caption = `🎯 **FINAL PERFECT Mobile Diff Design - Auto-Fixed!**
🔥 **Architect Auto-Fix Loop Results:**
✅ **TRUE Unified Format:**
• Line-by-line layout (not broken side-by-side)
• Perfect for mobile viewing in Telegram
• No wasted empty space anywhere
✅ **Mobile-First Design:**
• 750px width - fits perfectly on phones
• Clean GitHub-like styling
• Optimal for touch interfaces
✅ **Crystal Clear Indicators:**
• Prominent green "+" for additions
• Bright red "-" for deletions
• All inline with code for easy scanning
✅ **Perfect Typography:**
• 12px SF Mono font - highly readable
• 1.25 line height - optimal spacing
• No weird vertical gaps
✅ **Space Efficiency:**
• Every pixel used effectively
• Compact but never cramped
• Professional developer experience
🎨 **Technical:** 750px width, ~90KB, production-ready
📱 **Result:** Perfect mobile diff viewing experience!
This is the FINAL version ready for production use! 🚀`;
// Try sending as document instead of photo to bypass dimension limits
const result = await sendTelegramDocument(
config.telegram_bot_token,
config.telegram_chat_id,
imagePath,
caption,
'diff-image.png'
);
console.log(`🎉 FINAL VERSION SENT! Message ID: ${result.message_id}`);
console.log(`📱 Check your Telegram - this is the PERFECT mobile diff design!`);
} catch (error) {
console.log(`❌ Error: ${error.message}`);
}
}
sendFinalVersion().catch(console.error);