module Agents class EventFormattingAgent < Agent cannot_be_scheduled! can_dry_run! description <<-MD The Event Formatting Agent allows you to format incoming Events, adding new fields as needed. For example, here is a possible Event: { "high": { "celsius": "18", "fahreinheit": "64" }, "date": { "epoch": "1357959600", "pretty": "10:00 PM EST on January 11, 2013" }, "conditions": "Rain showers", "data": "This is some data" } You may want to send this event to another Agent, for example a Twilio Agent, which expects a `message` key. You can use an Event Formatting Agent's `instructions` setting to do this in the following way: "instructions": { "message": "Today's conditions look like {{conditions}} with a high temperature of {{high.celsius}} degrees Celsius.", "subject": "{{data}}", "created_at": "{{created_at}}" } Names here like `conditions`, `high` and `data` refer to the corresponding values in the Event hash. The special key `created_at` refers to the timestamp of the Event, which can be reformatted by the `date` filter, like `{{created_at | date:"at %I:%M %p" }}`. The upstream agent of each received event is accessible via the key `agent`, which has the following attributes: #{''.tap { |s| s << AgentDrop.instance_methods(false).map { |m| "`#{m}`" }.join(', ') }}. Have a look at the [Wiki](https://github.com/cantino/huginn/wiki/Formatting-Events-using-Liquid) to learn more about liquid templating. Events generated by this possible Event Formatting Agent will look like: { "message": "Today's conditions look like Rain showers with a high temperature of 18 degrees Celsius.", "subject": "This is some data" } In `matchers` setting you can perform regular expression matching against contents of events and expand the match data for use in `instructions` setting. Here is an example: { "matchers": [ { "path": "{{date.pretty}}", "regexp": "\\A(?