MCPcopy Create free account
hub / github.com/simstudioai/sim / downloadOutlookAttachments

Function downloadOutlookAttachments

apps/sim/lib/webhooks/polling/outlook.ts:488–544  ·  view source on GitHub ↗
(
  accessToken: string,
  messageId: string,
  requestId: string,
  logger: Logger
)

Source from the content-addressed store, hash-verified

486}
487
488async function downloadOutlookAttachments(
489 accessToken: string,
490 messageId: string,
491 requestId: string,
492 logger: Logger
493): Promise<OutlookAttachment[]> {
494 const attachments: OutlookAttachment[] = []
495
496 try {
497 const response = await fetchWithRetry(
498 `https://graph.microsoft.com/v1.0/me/messages/${messageId}/attachments`,
499 {
500 headers: {
501 Authorization: `Bearer ${accessToken}`,
502 },
503 }
504 )
505
506 if (!response.ok) {
507 logger.error(`[${requestId}] Failed to fetch attachments for message ${messageId}`)
508 return attachments
509 }
510
511 const data = await response.json()
512 const attachmentsList = data.value || []
513
514 for (const attachment of attachmentsList) {
515 try {
516 if (attachment['@odata.type'] === '#microsoft.graph.fileAttachment') {
517 const contentBytes = attachment.contentBytes
518 if (contentBytes) {
519 const buffer = Buffer.from(contentBytes, 'base64')
520 attachments.push({
521 name: attachment.name,
522 data: buffer,
523 contentType: attachment.contentType,
524 size: attachment.size,
525 })
526 }
527 }
528 } catch (error) {
529 logger.error(
530 `[${requestId}] Error processing attachment ${attachment.id} for message ${messageId}:`,
531 error
532 )
533 }
534 }
535
536 logger.info(
537 `[${requestId}] Downloaded ${attachments.length} attachments for message ${messageId}`
538 )
539 } catch (error) {
540 logger.error(`[${requestId}] Error downloading attachments for message ${messageId}:`, error)
541 }
542
543 return attachments
544}
545

Callers 1

processOutlookEmailsFunction · 0.85

Calls 4

fetchWithRetryFunction · 0.90
errorMethod · 0.80
infoMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected