Glific v0.3.1 Glific.Flows View Source

The Flows context.

Link to this section Summary

Functions

A generic json traversal and building the structure for a specific flow schema which is an array of objects in the json file. Used for Node/Actions, Node/Exits, Router/Cases, and Router/Categories

Returns an %Ecto.Changeset{} for tracking flow changes.

Check the required fields for all flow objects. If missing, raise an exception

Return the count of tags, using the same filter as list_tags

Creates a flow.

Save new revision for the flow

Deletes a flow.

Check if a flow has been activated since the time sent as a parameter e.g. outofoffice will check if that flow was activated in the last 24 hours daily/weekly will check since start of day/week, etc

A helper function to interact with the Caching API and get the cached flow. It will also set the loaded flow to cache in case it does not exists.

Gets a single flow.

Get specific flow revision by number

Get a list of all the revisions based on a flow UUID

Returns the list of flows.

Update latest flow revision status as done Reset old published flow revision status as draft Update cached flow definition

Start flow for a contact

Start flow for contacts of a group

Update the cached flow from db. This typically happens when the flow definition is updated via the UI

Updates a flow.

Link to this section Functions

Link to this function

build_flow_objects(json, uuid_map, process_fn, object \\ nil)

View Source

Specs

build_flow_objects(map(), map(), (map(), map(), any() -> {any(), map()}), any()) ::
  {any(), map()}

A generic json traversal and building the structure for a specific flow schema which is an array of objects in the json file. Used for Node/Actions, Node/Exits, Router/Cases, and Router/Categories

Link to this function

change_flow(flow, attrs \\ %{})

View Source

Specs

change_flow(Glific.Flows.Flow.t(), map()) :: Ecto.Changeset.t()

Returns an %Ecto.Changeset{} for tracking flow changes.

Examples

iex> change_flow(flow)
%Ecto.Changeset{data: %Flow{}}
Link to this function

check_required_fields(json, required)

View Source

Specs

check_required_fields(map(), [atom()]) :: boolean()

Check the required fields for all flow objects. If missing, raise an exception

Specs

count_flows(map()) :: integer()

Return the count of tags, using the same filter as list_tags

Link to this function

create_flow(attrs \\ %{})

View Source

Specs

create_flow(map()) ::
  {:ok, Glific.Flows.Flow.t()} | {:error, Ecto.Changeset.t()}

Creates a flow.

Examples

iex> create_flow(%{field: value})
{:ok, %Flow{}}

iex> create_flow(%{field: bad_value})
{:error, %Ecto.Changeset{}}
Link to this function

create_flow_revision(definition)

View Source

Specs

create_flow_revision(map()) :: Glific.Flows.FlowRevision.t()

Save new revision for the flow

Specs

delete_flow(Glific.Flows.Flow.t()) ::
  {:ok, Glific.Flows.Flow.t()} | {:error, Ecto.Changeset.t()}

Deletes a flow.

Examples

iex> delete_flow(flow)
{:ok, %Flow{}}

iex> delete_flow(flow)
{:error, %Ecto.Changeset{}}
Link to this function

flow_activated(flow_id, contact_id, since)

View Source

Specs

flow_activated(non_neg_integer(), non_neg_integer(), DateTime.t()) :: boolean()

Check if a flow has been activated since the time sent as a parameter e.g. outofoffice will check if that flow was activated in the last 24 hours daily/weekly will check since start of day/week, etc

Link to this function

get_cached_flow(key, args)

View Source

Specs

get_cached_flow(any(), any()) :: {atom(), any()}

A helper function to interact with the Caching API and get the cached flow. It will also set the loaded flow to cache in case it does not exists.

Specs

get_flow!(integer()) :: Glific.Flows.Flow.t()

Gets a single flow.

Raises Ecto.NoResultsError if the Flow does not exist.

Examples

iex> get_flow!(123)
%Flow{}

iex> get_flow!(456)
** (Ecto.NoResultsError)
Link to this function

get_flow_revision(flow_uuid, revision_id)

View Source

Specs

get_flow_revision(String.t(), String.t()) :: map()

Get specific flow revision by number

Link to this function

get_flow_revision_list(flow_uuid)

View Source

Specs

get_flow_revision_list(String.t()) :: %{results: list()}

Get a list of all the revisions based on a flow UUID

Specs

list_flows(map()) :: [Glific.Flows.Flow.t()]

Returns the list of flows.

Examples

iex> list_flows()
[%Flow{}, ...]

Specs

publish_flow(Glific.Flows.Flow.t()) :: {:ok, Glific.Flows.Flow.t()}

Update latest flow revision status as done Reset old published flow revision status as draft Update cached flow definition

Link to this function

start_contact_flow(flow, contact)

View Source

Specs

start_contact_flow(Glific.Flows.Flow.t(), Glific.Contacts.Contact.t()) ::
  {:ok, Glific.Flows.Flow.t()} | {:error, String.t()}

Start flow for a contact

Link to this function

start_group_flow(flow, group)

View Source

Specs

Start flow for contacts of a group

Link to this function

update_cached_flow(flow_uuid)

View Source

Specs

update_cached_flow(Glific.Flows.Flow.t()) :: {atom(), any()}

Update the cached flow from db. This typically happens when the flow definition is updated via the UI

Link to this function

update_flow(flow, attrs)

View Source

Specs

update_flow(Glific.Flows.Flow.t(), map()) ::
  {:ok, Glific.Flows.Flow.t()} | {:error, Ecto.Changeset.t()}

Updates a flow.

Examples

iex> update_flow(flow, %{field: new_value})
{:ok, %Flow{}}

iex> update_flow(flow, %{field: bad_value})
{:error, %Ecto.Changeset{}}