-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOT_WEBPOST_HAIKU_ADOBE_SNIPPET.js
More file actions
201 lines (163 loc) · 5.82 KB
/
Copy pathBOT_WEBPOST_HAIKU_ADOBE_SNIPPET.js
File metadata and controls
201 lines (163 loc) · 5.82 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
/**
* BOT.JS INTEGRATION SNIPPET
*
* /webpost-adobe command using Haiku + Adobe Creative MCP
*
* Copy this section and paste into bot.js message handler
*/
// ============================================
// At the TOP of bot.js:
// ============================================
const WebPostHaikuAdobeMCP = require('./webpost-haiku-adobe-mcp-module.js');
const webpostHaikuAdobe = new WebPostHaikuAdobeMCP();
// ============================================
// In the message handler (inside bot.on('text')):
// ============================================
// /webpost-adobe command
if (msg.text?.startsWith('/webpost-adobe ')) {
const query = msg.text.replace('/webpost-adobe ', '').trim();
if (!query || query.length === 0) {
await bot.sendMessage(
chatId,
`📱 *WebPost with Adobe Creative*\n\nUsage: /webpost-adobe <topic>\n\nExample:\n/webpost-adobe Chile tech startups\n\nFeatures:\n✍️ Post generation (Haiku)\n🎨 Image carousel (Adobe Creative)\n🎬 Video (Runway)`,
{ parse_mode: 'Markdown' }
);
return;
}
const loadingMsg = await bot.sendMessage(
chatId,
`🔍 Searching "${query}"...\n⏳ Generating post with Haiku...\n🎨 Creating images with Adobe...`,
{ parse_mode: 'Markdown' }
);
try {
console.log(`[Bot] /webpost-adobe "${query}"`);
// Run with image generation enabled
const result = await webpostHaikuAdobe.run(query, {
generateImages: true,
generateVideo: true,
imageCount: 3,
});
if (!result.success) {
throw new Error(result.error);
}
// Format for Telegram
const formatted = webpostHaikuAdobe.formatForTelegram(result);
// Delete loading message
try {
await bot.deleteMessage(chatId, loadingMsg.message_id);
} catch (e) {
// Ignore delete errors
}
// Send final post
await bot.sendMessage(chatId, formatted, {
parse_mode: 'Markdown',
disable_web_page_preview: true,
});
console.log(`[Bot] ✅ /webpost-adobe complete (${result.tokens.total} tokens)`);
} catch (error) {
console.error(`[Bot] ❌ /webpost-adobe error:`, error.message);
// Delete loading message
try {
await bot.deleteMessage(chatId, loadingMsg.message_id);
} catch (e) {
// Ignore
}
// Send error
await bot.sendMessage(
chatId,
`❌ *Error:* ${error.message}\n\nMake sure ANTHROPIC_API_KEY is set.`,
{ parse_mode: 'Markdown' }
);
}
}
// ============================================
// Optional: /webpost-adobe-help command
// ============================================
if (msg.text === '/webpost-adobe-help') {
const helpText = `📱 *WebPost with Adobe Creative*
*Usage:*
\`/webpost-adobe <topic>\`
*Examples:*
• /webpost-adobe Chile tech startups
• /webpost-adobe AI regulation trends
• /webpost-adobe Web3 adoption enterprise
*What it does:*
1. 🔍 Search with Brave API (0 tokens)
2. ✍️ Generate post with Claude Haiku (~150 tokens)
3. 🎨 Create carousel images with Adobe Creative
4. 🎬 Generate video with Runway ML
5. 📚 Link to source articles
*Token breakdown (Haiku path):*
• Brave search: 0 ✅
• Haiku post: ~150 tokens (cheaper than OpenRouter!)
• Adobe images: Separate billing
• Runway video: Async (no tokens)
• Total: ~150 tokens per post
*Environment variables:*
\`ANTHROPIC_API_KEY\` (required for Haiku)
\`BRAVE_SEARCH_API_KEY\` (optional, falls back to mock)
\`ADOBE_ACCESS_TOKEN\` (required for images)
\`RUNWAY_API_KEY\` (optional for video)
*No Grok. No DeepSeek. No OpenRouter.*
*Haiku + Adobe + Brave. All in-house.*
`;
await bot.sendMessage(chatId, helpText, { parse_mode: 'Markdown' });
}
// ============================================
// Optional: /webpost-compare command (show all versions)
// ============================================
if (msg.text === '/webpost-compare') {
const compareText = `📱 *WebPost Commands Comparison*
| Command | Search | Model | Tokens | Images |
|---------|--------|-------|--------|--------|
| /post | — | Grok | ~350 | Grok |
| /webpost | Brave ✅ | OpenRouter | ~200 | Runway |
| /webpost-carousel | Web | OpenRouter | ~300 | Web |
| /webpost-adobe | Brave ✅ | Haiku ✅ | ~150 ✅ | Adobe ✅ |
*Winner for cost?* /webpost-adobe (~150 tokens)
*Winner for images?* /webpost-adobe (Adobe Creative)
*Winner for speed?* /webpost-adobe (Haiku is fastest)
Try: /webpost-adobe Chile tech startups`;
await bot.sendMessage(chatId, compareText, { parse_mode: 'Markdown' });
}
// ============================================
// INTEGRATION CHECKLIST
// ============================================
/*
SETUP CHECKLIST for /webpost-adobe
Environment Variables:
☐ ANTHROPIC_API_KEY=sk-ant-... (Haiku)
☐ ADOBE_CLIENT_ID=xxx (for images)
☐ ADOBE_CLIENT_SECRET=xxx
☐ ADOBE_ACCESS_TOKEN=xxx
☐ BRAVE_SEARCH_API_KEY=xxx (optional)
☐ RUNWAY_API_KEY=xxx (optional for video)
Code Changes:
☐ 1. Copy webpost-haiku-adobe-mcp-module.js to /tmp/map/
☐ 2. Add import at top of bot.js:
const WebPostHaikuAdobeMCP = require('./webpost-haiku-adobe-mcp-module.js');
const webpostHaikuAdobe = new WebPostHaikuAdobeMCP();
☐ 3. Add /webpost-adobe handler to message listener (above)
☐ 4. Add /webpost-adobe-help handler (optional)
☐ 5. Add /webpost-compare handler (optional)
Testing:
☐ npm start (local test)
☐ /webpost-adobe Chile tech (verify works)
☐ Check token usage in output
☐ Check image generation
Deployment:
☐ Set all env vars in Render
☐ Deploy bot to Render
☐ Test: /webpost-adobe test query
☐ Monitor: Check logs for errors
Token Monitoring:
☐ Install token-monitor.js integration
☐ Track Haiku tokens per command
☐ Set up token alerts
Success Criteria:
✅ Post generates in ~4 seconds
✅ Images (if Adobe key set) appear in output
✅ Token count shown (150-200 for Haiku)
✅ Sources linked
✅ Video queues (if Runway key set)
*/