Skip to content

Commit be70cd7

Browse files
committed
update function signature
1 parent 6bfc15c commit be70cd7

File tree

2 files changed

+113
-63
lines changed

2 files changed

+113
-63
lines changed

app/src/utils/handlers/javascript.ts

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -256,76 +256,76 @@ export async function executeJavaScript(
256256

257257
// --- UPDATED FUNCTIONS ---
258258

259-
sendSms: async (message: string, number: string) => {
259+
sendSms: async (number: string, message: string, images?: string[]) => {
260260
try {
261261
if (!getToken) throw new Error("Authentication context not available for sendSms.");
262262

263263
const token = await getToken();
264264
if (!token) throw new Error("Failed to retrieve authentication token for SMS.");
265265

266-
await utils.sendSms(message, number, token);
267-
Logger.info(agentId, `SMS sent to ${number}`, {
266+
await utils.sendSms(message, number, token, images);
267+
Logger.info(agentId, `SMS sent to ${number}${images && images.length > 0 ? ` with ${images.length} images` : ''}`, {
268268
logType: 'tool-success',
269269
iterationId,
270-
content: { tool: 'sendSms', params: { message: message.slice(0,100), number }, success: true }
270+
content: { tool: 'sendSms', params: { message: message.slice(0,100), number, imageCount: images?.length || 0 }, success: true }
271271
});
272272
} catch (error) {
273273
Logger.error(agentId, `Failed to send SMS to ${number}`, {
274274
logType: 'tool-error',
275275
iterationId,
276-
content: { tool: 'sendSms', params: { message: message.slice(0,100), number }, error: extractErrorMessage(error) }
276+
content: { tool: 'sendSms', params: { message: message.slice(0,100), number, imageCount: images?.length || 0 }, error: extractErrorMessage(error) }
277277
});
278278
throw error;
279279
}
280280
},
281281

282-
sendWhatsapp: async(message: string, number: string) => {
282+
sendWhatsapp: async (number: string, message: string, images?: string[]) => {
283283
try {
284284
if (!getToken) throw new Error("Authentication context not available for sendWhatsapp.");
285285

286286
const token = await getToken();
287287
if (!token) throw new Error("Failed to retrieve authentication token for WhatsApp.");
288288

289-
await utils.sendWhatsapp(message, number, token);
290-
Logger.info(agentId, `WhatsApp sent to ${number}`, {
289+
await utils.sendWhatsapp(message, number, token, images);
290+
Logger.info(agentId, `WhatsApp sent to ${number}${images && images.length > 0 ? ` with ${images.length} images` : ''}`, {
291291
logType: 'tool-success',
292292
iterationId,
293-
content: { tool: 'sendWhatsapp', params: { message: message.slice(0,100), number }, success: true }
293+
content: { tool: 'sendWhatsapp', params: { message: message.slice(0,100), number, imageCount: images?.length || 0 }, success: true }
294294
});
295295
} catch (error) {
296296
Logger.error(agentId, `Failed to send WhatsApp to ${number}`, {
297297
logType: 'tool-error',
298298
iterationId,
299-
content: { tool: 'sendWhatsapp', params: { message: message.slice(0,100), number }, error: extractErrorMessage(error) }
299+
content: { tool: 'sendWhatsapp', params: { message: message.slice(0,100), number, imageCount: images?.length || 0 }, error: extractErrorMessage(error) }
300300
});
301301
throw error;
302302
}
303303
},
304304

305-
sendEmail: async (message: string, emailAddress: string) => {
305+
sendEmail: async (emailAddress: string, message: string, images?: string[]) => {
306306
try {
307307
if (!getToken) throw new Error("Authentication context not available for sendEmail.");
308308

309309
const token = await getToken();
310310
if (!token) throw new Error("Failed to retrieve authentication token for Email.");
311311

312-
await utils.sendEmail(message, emailAddress, token);
313-
Logger.info(agentId, `Email sent to ${emailAddress}`, {
312+
await utils.sendEmail(message, emailAddress, token, images);
313+
Logger.info(agentId, `Email sent to ${emailAddress}${images && images.length > 0 ? ` with ${images.length} images` : ''}`, {
314314
logType: 'tool-success',
315315
iterationId,
316-
content: { tool: 'sendEmail', params: { message: message.slice(0,100), emailAddress }, success: true }
316+
content: { tool: 'sendEmail', params: { message: message.slice(0,100), emailAddress, imageCount: images?.length || 0 }, success: true }
317317
});
318318
} catch (error) {
319319
Logger.error(agentId, `Failed to send email to ${emailAddress}`, {
320320
logType: 'tool-error',
321321
iterationId,
322-
content: { tool: 'sendEmail', params: { message: message.slice(0,100), emailAddress }, error: extractErrorMessage(error) }
322+
content: { tool: 'sendEmail', params: { message: message.slice(0,100), emailAddress, imageCount: images?.length || 0 }, error: extractErrorMessage(error) }
323323
});
324324
throw error;
325325
}
326326
},
327327

328-
sendPushover: async (message: string, userKey: string, title?: string) => {
328+
sendPushover: async (userKey: string, message: string, images?: string[], title?: string) => {
329329
try {
330330
if (!getToken) {
331331
throw new Error("Authentication context not available for sendPushover.");
@@ -336,67 +336,67 @@ export async function executeJavaScript(
336336
throw new Error("Failed to retrieve authentication token for Pushover.");
337337
}
338338

339-
await utils.sendPushover(message, userKey, token, title);
340-
Logger.info(agentId, `Pushover notification sent`, {
339+
await utils.sendPushover(message, userKey, token, images, title);
340+
Logger.info(agentId, `Pushover notification sent${images && images.length > 0 ? ` with ${images.length} images` : ''}`, {
341341
logType: 'tool-success',
342342
iterationId,
343-
content: { tool: 'sendPushover', params: { message: message.slice(0,100), title }, success: true }
343+
content: { tool: 'sendPushover', params: { message: message.slice(0,100), title, imageCount: images?.length || 0 }, success: true }
344344
});
345345
} catch (error) {
346346
Logger.error(agentId, `Failed to send Pushover notification`, {
347347
logType: 'tool-error',
348348
iterationId,
349-
content: { tool: 'sendPushover', params: { message: message.slice(0,100), title }, error: extractErrorMessage(error) }
349+
content: { tool: 'sendPushover', params: { message: message.slice(0,100), title, imageCount: images?.length || 0 }, error: extractErrorMessage(error) }
350350
});
351351
throw error;
352352
}
353353
},
354354

355-
sendDiscordBot: async (message: string, webhookUrl: string) => {
355+
sendDiscord: async (webhookUrl: string, message: string, images?: string[]) => {
356356
try {
357357
if (!getToken) {
358-
throw new Error("Authentication context not available for sendDiscordBot.");
358+
throw new Error("Authentication context not available for sendDiscord.");
359359
}
360360

361361
const token = await getToken();
362362
if (!token) {
363-
throw new Error("Failed to retrieve authentication token for sendDiscordBot.");
363+
throw new Error("Failed to retrieve authentication token for sendDiscord.");
364364
}
365365

366-
await utils.sendDiscordBot(message, webhookUrl, token);
367-
Logger.info(agentId, `Discord notification sent`, {
366+
await utils.sendDiscord(message, webhookUrl, token, images);
367+
Logger.info(agentId, `Discord notification sent${images && images.length > 0 ? ` with ${images.length} images` : ''}`, {
368368
logType: 'tool-success',
369369
iterationId,
370-
content: { tool: 'sendDiscordBot', params: { message: message.slice(0,100) }, success: true }
370+
content: { tool: 'sendDiscord', params: { message: message.slice(0,100), imageCount: images?.length || 0 }, success: true }
371371
});
372372
} catch (error) {
373373
Logger.error(agentId, `Failed to send Discord notification`, {
374374
logType: 'tool-error',
375375
iterationId,
376-
content: { tool: 'sendDiscordBot', params: { message: message.slice(0,100) }, error: extractErrorMessage(error) }
376+
content: { tool: 'sendDiscord', params: { message: message.slice(0,100), imageCount: images?.length || 0 }, error: extractErrorMessage(error) }
377377
});
378378
throw error;
379379
}
380380
},
381381

382-
sendTelegram: async (message: string, chatId: string) => {
382+
sendTelegram: async (chatId: string, message: string, images?: string[]) => {
383383
try {
384384
if (!getToken) throw new Error("Authentication context not available for sendTelegram.");
385385

386386
const token = await getToken();
387387
if (!token) throw new Error("Failed to retrieve authentication token for Telegram.");
388388

389-
await utils.sendTelegram(message, chatId, token);
390-
Logger.info(agentId, `Telegram message sent to ${chatId}`, {
389+
await utils.sendTelegram(message, chatId, token, images);
390+
Logger.info(agentId, `Telegram message sent to ${chatId}${images && images.length > 0 ? ` with ${images.length} images` : ''}`, {
391391
logType: 'tool-success',
392392
iterationId,
393-
content: { tool: 'sendTelegram', params: { message: message.slice(0,100), chatId }, success: true }
393+
content: { tool: 'sendTelegram', params: { message: message.slice(0,100), chatId, imageCount: images?.length || 0 }, success: true }
394394
});
395395
} catch (error) {
396396
Logger.error(agentId, `Failed to send Telegram message to ${chatId}`, {
397397
logType: 'tool-error',
398398
iterationId,
399-
content: { tool: 'sendTelegram', params: { message: message.slice(0,100), chatId }, error: extractErrorMessage(error) }
399+
content: { tool: 'sendTelegram', params: { message: message.slice(0,100), chatId, imageCount: images?.length || 0 }, error: extractErrorMessage(error) }
400400
});
401401
throw error;
402402
}

0 commit comments

Comments
 (0)