View Source Glific.Flows (Glific v5.1.6)

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

Make a copy of a flow

Return the count of flows, using the same filter as list_flows

Creates a flow.

Save new revision for the flow

Deletes a flow.

Generate a json map with all the flows related fields.

Process sub flows and check if there is more sub flows in it.

Fetches a single 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

Create a map of keywords that map to flow ids for each active organization. Also cache this value including the outOfOffice shortcode

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

Extract all the sub flows form the parent flow definition.

Check if the type is a media type we handle in flows

Check if the flow is optin flow. Currently we are checking based on the optin keyword only.

Returns the list of flows.

Update latest flow revision status as published and increment the version Update cached flow definition

Start flow for a contact and cache the result

Start flow for contacts of a group

Terminate all flows for a contact

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
@spec build_flow_objects(
  list(),
  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
@spec change_flow(Glific.Flows.Flow.t(), map()) :: Ecto.Changeset.t()

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

examples

Examples

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

check_required_fields(json, required)

View Source
@spec check_required_fields(map(), [atom()]) :: boolean()

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

@spec copy_flow(Glific.Flows.Flow.t(), map()) ::
  {:ok, Glific.Flows.Flow.t()} | {:error, String.t()}

Make a copy of a flow

@spec count_flows(map()) :: integer()

Return the count of flows, using the same filter as list_flows

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

Creates a flow.

examples

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
@spec create_flow_revision(map()) :: Glific.Flows.FlowRevision.t()

Save new revision for the flow

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

Deletes a flow.

examples

Examples

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

iex> delete_flow(flow)
{:error, %Ecto.Changeset{}}
@spec export_flow(non_neg_integer()) :: map()

Generate a json map with all the flows related fields.

Link to this function

export_flow_details(flow_uuid, results)

View Source
@spec export_flow_details(String.t(), map()) :: map()

Process sub flows and check if there is more sub flows in it.

@spec fetch_flow(integer()) :: {:ok, any()} | {:error, any()}

Fetches a single flow

Returns Resource not found if the Interactive Template does not exist.

examples

Examples

iex> fetch_interactive_template(123, 1)
  {:ok, %Flow{}}

iex> fetch_interactive_template(456, 1)
  {:error, ["Elixir.Glific.Flows.Flow", "Resource not found"]}
Link to this function

flow_activated(flow_id, contact_id, since)

View Source
@spec 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

flow_keywords_map(organization_id)

View Source
@spec flow_keywords_map(non_neg_integer()) :: map()

Create a map of keywords that map to flow ids for each active organization. Also cache this value including the outOfOffice shortcode

Link to this function

get_cached_flow(organization_id, key)

View Source
@spec get_cached_flow(non_neg_integer(), {atom(), any(), String.t()}) ::
  {atom(), any()} | {atom(), String.t()}

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.

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

Gets a single flow.

Raises Ecto.NoResultsError if the Flow does not exist.

examples

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
@spec 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
@spec get_flow_revision_list(String.t()) :: %{results: list()}

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

@spec get_sub_flows(list()) :: list()

Extract all the sub flows form the parent flow definition.

Link to this function

import_flow(import_flow, organization_id)

View Source
@spec import_flow(map(), non_neg_integer()) :: boolean()

import a flow from json

@spec is_media_type?(atom()) :: boolean()

Check if the type is a media type we handle in flows

@spec is_optin_flow?(Glific.Flows.Flow.t()) :: boolean()

Check if the flow is optin flow. Currently we are checking based on the optin keyword only.

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

Returns the list of flows.

examples

Examples

iex> list_flows()
[%Flow{}, ...]
@spec publish_flow(Glific.Flows.Flow.t()) ::
  {:ok, Glific.Flows.Flow.t()} | {:error, any()}

Update latest flow revision status as published and increment the version Update cached flow definition

Link to this function

start_contact_flow(f, c, default_results \\ %{})

View Source
@spec start_contact_flow(
  Glific.Flows.Flow.t() | integer(),
  Glific.Contacts.Contact.t(),
  map()
) ::
  {:ok, Glific.Flows.Flow.t()} | {:error, String.t()}

Start flow for a contact and cache the result

Link to this function

start_group_flow(flow, group, default_results \\ %{})

View Source
@spec start_group_flow(Glific.Flows.Flow.t(), Glific.Groups.Group.t(), map()) ::
  {:ok, Glific.Flows.Flow.t()}

Start flow for contacts of a group

Link to this function

terminate_contact_flows?(contact_id)

View Source
@spec terminate_contact_flows?(non_neg_integer()) :: :ok

Terminate all flows for a contact

Link to this function

update_cached_flow(flow, status)

View Source
@spec update_cached_flow(Glific.Flows.Flow.t(), String.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
@spec update_flow(Glific.Flows.Flow.t(), map()) ::
  {:ok, Glific.Flows.Flow.t()} | {:error, Ecto.Changeset.t()}

Updates a flow.

examples

Examples

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

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