In the previous article we introduced the simple story. In this article we will expand that story by adding an additional agent.

In the simple story, we created an automation story that sends a HTTP POST request when an alert is related to an infection and the affected user’s job is CEO. In this article we will expand the story by sending an email when the user’s job is “engineer”.

Creating an email agent

From the “Agents” dropdown menu choose “New Agent”

Creating a new agent
Creating a new agent

Choose “Email agent” from the list of agent types.

Screen layout

When editing or creating an agent, you will be presented with a screen similar to the below. The agent configuration is shown on the left hand side of the page and the “In-app help” is shown on the right. The In-app help provides easy-access to important information about the agent type, including: description of the agent, configuration options and sample configurations.

Agent page layout
Agent page layout

Common config

The agent’s common config has a number of fields that allow us to specify the agent’s basic operation, including:

  • Name: Provide a name for the agent
  • Story: Specify the story that the agent should be added to
  • Schedule: If the agent should run on a schedule, specify the schedule
  • Keep events: Specify how long events should be retained in Tines. Once this period lapses, Tines will purge the events and they cannot be recovered.
  • Sources: Specify the agent(s) that the newly created agent should receive events from
  • Receivers: Specify the agent(s) that the newly created agent should emit events to

As we want to send an email when the affected user is an engineer, we will specify the source agent as “User is engineer”. As we saw from the previous article, the “User is engineer” agent is a Trigger agent configured to emit events when the field at {{.explode_users.user.job}} contains “engineer”.

The completed common config should look similar to the below:

Agent common config
Agent common config

Editing the options block

In the options block we will configure the granular operation of the agent. The In-app help describes the various fields that can be used in the options block. For an Email Agent, these consist of the following:

  • recipients: Include an email address (or an array of email addresses) to whom the email should be sent. Each recipient will receive an individual email.
  • subject: Include a subject for the email. Include information from upstream events by specifying the key.
  • body: (Optional) Customize the body of the email. Include information from upstream events by specifying the JSONPath (examples below). The body can contain simple HTML and will be sanitized. When using body, it will be wrapped with <html> and <body> tags, so these do not need to be added.
  • content_type: (Optional) Provide a content type for the email by specifying text/plain or text/html. If you do not specify content_type, then the recipient email server will determine the correct rendering.
  • expected_update_period_in_days: Set this key to the maximum amount of time expected to pass between Events being emitted by this Agent. If this period passes without any Events being emitted, the Agent will be flagged as “Not Working”.

For our Email agent we will use the following options block: ```json

{ “recipients”: “tinesdemouser@outlook.com”, “subject”: “Engineer in infected”, “body”: “Hello,

An alert has been detected that relates to an infected engineer. The user’s details are shown below:
Name: {{.explode_users.user.name}}
Age: {{.explode_users.user.age}}
Country: {{.explode_users.user.country}}

Thanks!”, “expected_update_period_in_days”: “2” }

```

API Autocomplete

When editing or creating an agent, ‘API Autocomplete’ allows you to more easily define JSONPaths in the options block. When a source agent is defined and two sets of curly braces are entered into a field with a period, ({{ . }} ), Tines will provide a list of available keys from the most recent event emitted by the defined source agent. When a key is selected and another period is pressed, Tines will present the keys from the most recent event at that level.

API Autocomplete in options block
API Autocomplete in options block

Testing the Agent

Save the agent and return to the simple story diagram. There should now be a new agent ready to receive events from the “User is engineer” agent (shown below).

Simple story with new agent
Simple story with new agent

To test that this agent is working as expected, we can “reemit” an event from the “User is engineer” events page.

Reemit an event
Reemit an event

Viewing the events emitted by our new “Notify by email” Agent, we can see the agent ran and successfully emitted an event similar the below. The corresponding email is also shown below.

Emitted event
Emitted event
Received email
Received email