MCPcopy
hub / github.com/zarazhangrui/follow-builders / main

Function main

scripts/deliver.js:154–215  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

152// -- Main --------------------------------------------------------------------
153
154async function main() {
155 // Load env and config
156 loadEnv({ path: ENV_PATH });
157
158 let config = {};
159 if (existsSync(CONFIG_PATH)) {
160 config = JSON.parse(await readFile(CONFIG_PATH, 'utf-8'));
161 }
162
163 const delivery = config.delivery || { method: 'stdout' };
164 const digestText = await getDigestText();
165
166 if (!digestText || digestText.trim().length === 0) {
167 console.log(JSON.stringify({ status: 'skipped', reason: 'Empty digest text' }));
168 return;
169 }
170
171 try {
172 switch (delivery.method) {
173 case 'telegram': {
174 const botToken = process.env.TELEGRAM_BOT_TOKEN;
175 const chatId = delivery.chatId;
176 if (!botToken) throw new Error('TELEGRAM_BOT_TOKEN not found in .env');
177 if (!chatId) throw new Error('delivery.chatId not found in config.json');
178 await sendTelegram(digestText, botToken, chatId);
179 console.log(JSON.stringify({
180 status: 'ok',
181 method: 'telegram',
182 message: 'Digest sent to Telegram'
183 }));
184 break;
185 }
186
187 case 'email': {
188 const apiKey = process.env.RESEND_API_KEY;
189 const toEmail = delivery.email;
190 if (!apiKey) throw new Error('RESEND_API_KEY not found in .env');
191 if (!toEmail) throw new Error('delivery.email not found in config.json');
192 await sendEmail(digestText, apiKey, toEmail);
193 console.log(JSON.stringify({
194 status: 'ok',
195 method: 'email',
196 message: `Digest sent to ${toEmail}`
197 }));
198 break;
199 }
200
201 case 'stdout':
202 default:
203 // Just print to terminal — the agent or OpenClaw handles delivery
204 console.log(digestText);
205 break;
206 }
207 } catch (err) {
208 console.log(JSON.stringify({
209 status: 'error',
210 method: delivery.method,
211 message: err.message

Callers 1

deliver.jsFile · 0.70

Calls 3

getDigestTextFunction · 0.85
sendTelegramFunction · 0.85
sendEmailFunction · 0.85

Tested by

no test coverage detected