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.
import a flow from json
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
@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
@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{}}
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
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{}}
@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.
Process sub flows and check if there is more sub flows in it.
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"]}
@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
@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
@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)
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.
@spec import_flow(map(), non_neg_integer()) :: boolean()
import a flow from json
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
@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
@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
@spec terminate_contact_flows?(non_neg_integer()) :: :ok
Terminate all flows for a contact
@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
@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{}}