Skip to content

Mustache Triggers for object aggregated values #1203

@noaccOS

Description

@noaccOS

Current behavior

Currently, trying to define a trigger using the mustache template on an object aggregated value falis

Example trigger action:

{
  "http_post_url": "http://hello.world.ai",
  "template": "{{new_value}}",
  "template_type": "mustache"
}

Example event:

%ValueChangeEvent{
  interface: "org.astarte-platform.genericsensors.ServerOwnedAggregateObj",
  path: "/my_path",
  old_bson_value: Cyanide.encode!(%{v: %{"enable" => true, "samplingPeriod" => 10}}),
  new_bson_value: Cyanide.encode!(%{v: %{"enable" => false, "samplingPeriod" => 11}})
}

Result:

** (ErlangError) Erlang error: :unsupported_term

Reproducing the issue

This is an example of the values available to the mustache template

%{
  "__unknown_fields__" => [],
  "device_id" => "f0VMRgIBAQAAAAAAAAAAAA",
  "event_type" => "value_change_event",
  "interface" => "org.astarte-platform.genericsensors.ServerOwnedAggregateObj",
  "new_value" => %{"enable" => false, "samplingPeriod" => 11},
  "old_value" => %{"enable" => true, "samplingPeriod" => 10},
  "path" => "/my_path",
  "realm" => "realm579",
  "trigger_name" => "trigger_mustache_2"
}

And this is how bbmustache behaves on IEx

iex(4)> :bbmustache.render("{{a}}", %{"a" => 3}, key_type: :binary)
"3"
iex(5)> :bbmustache.render("{{a}}", %{"a" => %{b: 2}}, key_type: :binary)
** (ErlangError) Erlang error: :unsupported_term
iex(5)> :bbmustache.render("{{a}}", %{"a" => %{"b" => 2}}, key_type: :binary)
** (ErlangError) Erlang error: :unsupported_term
iex(5)>

Metadata

Metadata

Assignees

No one assigned

    Labels

    app:trigger_engineThis issue or pull request is about astarte_trigger_engine applicationbugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions