Creating an Email Input

As you'll have seen from our visualisation, we don't yet have any inputs to our Sift, so creating one will be our first task. Open up the Sift folder in your favourite editor, and select sift.json at the top level. It should look like this:

{
  "name": "example-sift",
  "display-name": "Example Sift Sift",
  "description": "",
  "author": "",
  "version": "1.0.0",
  "icon": "assets/blueprint.svg",
  "interfaces": {
    "email": {
      "thread" : {
        "controller": "dist/js/controller.umd-es2015.js"
      },
      "client" : {
        "controller": "dist/js/email-client-controller.umd-es2015.js"
      }
    },
    "summary": {
      "controller": "dist/js/controller.umd-es2015.js"
    }
  },
  "dag": {
    "inputs":{
      "emails": {},
      "webhooks": {}
    },
    "nodes":[{
      "#": "First Node",
      "implementation": {
        "javascript": "server/node1.js",
        "when":{
          "interval": 900
        }
      },
      "outputs": {
        "output1-st": {}
      }
    }],
    "stores":{
      "output1-st" : {
        "key$schema":"string"
      }
    },
    "outputs":{}
  }
}

Replace line 23 (the empty emails input) with this code:

{
    // ...
    "emails":{
      "gmailEmails": {
        "filter": {
          "conditions":[{
            "date": "between now and 1 week before now"
          }]
        },
        "wants": [
          "archive",
          "headers",
          "extensions",
          "textBody",
          "strippedHtmlBody"
        ],
        "inMailbox": "Important"
      }
    }
    // ...
}

Breaking this down,

  1. We want emails and have labelled the input gmailEmails.
  2. We want 1 week of the user’s archive in addition to new emails as we want to show a new user some of our results.
  3. We want the text of the message, we don’t care about attachments in this use case.
  4. We want everything from the Important gmail folder as we only want to count messages that have been flagged as important.

As we are not using any other streaming data source, we can delete the slack-bot and webhooks inputs.

Now let’s wire this up by adding it as an input to our node. Replace the nodes section of sift.json with the following code.

{
    // ...
    "nodes":[{
      "#": "Parse Emails Node",
      "input": {
        "bucket": "gmailEmails"
      },
      "implementation": {
        "javascript": "server/node1.js"
      },
      "outputs": {
        "output1-st": {}
      }
    }],
    // ...
}

Let's just check this by showing the visualisation of our Sift. It should look like this:

Great, so now we have a GMail input and it's being piped into the First Node. Note that we have also removed the when clause from the node. In the skeleton this made it run every 900 seconds, now it will run when new mail comes in. However, while you are developing your Sift, you'll be driving this manually from the web interface.

📘

If you left your browser on the visualisation page, you'll notice that it updated automatically.
The SDK monitors the Sift directory and rebuilds the Sift as necessary when files change.

Rename the nodes and stores to make them more descriptive (this will change the store schema and can require a reset or migration).

{
    // ...
    "nodes":[{
      "#": "Parse Emails Node",
      "input": {
        "bucket": "gmailEmails"
      },
      "implementation": {
        "javascript": "server/parser.js"
      },
      "outputs": {
        "emails-st": {}
      }
    }],
    // ...
}
{
    // ...
    "stores":{
      "emails-st" : {
        "key$schema":"string"
      }
    },
    // ...
}

The Sift visualisation should now look like this, where k$s:string is shorthand for the store key schema.