Skip to content

featuredotapp/template-attachments-to-webhook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 

Repository files navigation

Mailscript templates: send attachments to webhook

You can use this template to setup a workflow that listens in to incoming email messages with attachments and when it gets a hit it will deliver the attachments to an endpoint.

Workflow

version: "0.2"
addresses:
  [email protected]:
    keys:
      - name: owner
        read: true
        write: true
accessories:
  - name: [email protected]
    type: mailscript-email
    address: [email protected]
    key: owner
workflows:
  - name: attachments
    trigger: attachments-trigger
    action: attachments-webhook-action
triggers:
  - name: attachments-trigger
    accessory: [email protected]
    config:
      criterias:
        - hasAttachments: true
actions:
  - name: attachments-webhook-action
    config:
    type: webhook
    body: |
      {
        "attachments": "{{msg.attachments}}"
      }
    url: "https://endpoint.url"
    opts:
      headers:
        Content-Type: application/json
      method: POST

Manual setup

Expects body.json file containing { attachments: "{{msg.attachments}}" }

mailscript workflows:add \
  --name "attachments to webhook" \
  --trigger [email protected] \
  --action webhook \
  --webhook "https://endpoint.url" \
  --body ./body.json

Read from request

Example usage to read payload:

const express = require("express")
const fs = require("fs")

const handler = async (req, res) => {
  const { attachments } = req.body
  for (const attachment of attachments) {
    const { filename, content } = attachment
    const path = `./files/${filename}`
    fs.writeFileSync(path, Buffer.from(content))
  }
  res.status(200).send({ status: "ok" })
}

const app = express()
app.post("/", express.json(), handler)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published