Smithable websitedocsGitHub
Menu

Mail and calls into your app

Other things can put records into an app: a mail sent to a support address, or a call from another service, such as a monitor that finds a site down. You say in smithable.yml what each one does. The app gives it an address of its own, /incoming/<name>, checks the caller's secret, and adds the record as a role you choose.

1. Mail that becomes a record

A support desk where each mail to the support address becomes a request:

incoming:
  support:
    mail: true
    create: Request
    set: { status: new }
    fields: { from: email, subject: title, body: body, attachments: files }

From the command line: smithable op addIncoming support --mail --create Request --fields from=email subject=title body=body attachments=files.

Where the mail comes from

The app doesn't read a mailbox itself. Something passes each mail on to /incoming/support as JSON in this shape:

{
  "from": "Ada Lovelace <ada@example.com>",
  "to": "support@your-domain.example",
  "subject": "The invoice page is blank",
  "text": "Hello, since this morning…",
  "html": "<p>Hello, since this morning…</p>",
  "attachments": [{ "name": "screenshot.png", "type": "image/png", "data": "<base64>" }]
}

That can be:

2. Calls from other services

A monitor that posts JSON when a site stops answering, so each alert becomes an incident:

incoming:
  monitorDown:
    create: Incident
    set:
      title: "{check.name} is not responding"   # {path}: a value from the call's JSON
      status: investigating
      detectedAt: NOW()
    id: "{event.id}"                 # optional: a call seen in the last day is not acted on again
    as: staff                        # the role the call acts as

From the command line: smithable op addIncoming monitorDown --create Incident --set "status=investigating" --as staff.

3. The secret, repeats and answers

The full rules are in the spec reference.