defmodule Slack.Attachment.SelectAction do defstruct [ :name, :text, :options ] defimpl Jason.Encoder, for: __MODULE__ do def encode(value, opts) do value |> Map.take(~w(name text options)a) |> Map.put(:type, "select") |> Map.update!(:options, fn o -> Enum.map(o, fn {k, v} -> %{text: v, value: k} end) end) |> Jason.Encode.map(opts) end end end