View Source Glific (Glific v5.1.6)
Glific keeps the contexts that define your domain and business logic.
Contexts are also responsible for managing your data, regardless if it comes from the database, an external API or others.
For now we'll keep some commonly used functions here, until we need a new file
Link to this section Summary
Functions
Adds a limit to restrict accessing data from big tables like messages, contacts which slows DB and takes longer to complete request
Convert map string keys to :atom keys
Delete multiple items from the map
execute string in eex
Return a time object where you go back x units. We introduce the notion of hour and minute
A hack to suppress error messages when running lots of flows. These are expected and we want to improve signal <-> noise ratio
See if the current time is within the past time units
Log the error and also send it over to our friends at appsignal
Given a string separated by spaces, commas, or semi-colons, create a set of individual elements in the string
Wrapper to return :ok/:error when parsing strings to potential integers
parse and integer and die if parse fails
Wrapper to return :ok/:error when parsing strings to potential integers
You shouldn’t really use String.to_atom/1 on user-supplied data. The BEAM has a limit on how many different atoms you can have and they’re not garbage collected! With data coming from outside the system, stick to strings or use String.to_existing_atom/1 instead! So this is a generic function which will convert the string to atom and throws an error in case of invalid key
Compute the signature at a specific time for the body
easy way for glific developers to get a stacktrace when debugging
Lets get rid of all non valid characters. We are assuming any language and hence using unicode syntax and not restricting ourselves to alphanumeric
convert string to snake case
Intermediary function to update the input params with organization id as operation is performed by glific_admin for other organizations
Really simple function to ensure folks do not add Repo and/or IO calls to an EEx snippet. This is an extremely short term fix to avoid shooting ourselves in the foot, but we should move to lua for flows scripting in the near future
Validates inputted shortcode, if shortcode is invalid it returns message that the shortcode is invalid along with the valid shortcode.
Verifying Google Captcha
Link to this section Functions
Adds a limit to restrict accessing data from big tables like messages, contacts which slows DB and takes longer to complete request
Adding upper limit to 50 when limit is passed and is more than 50 Adding limit to 25 when limit is not passed in args
Convert map string keys to :atom keys
Delete multiple items from the map
execute string in eex
@spec go_back_time(integer(), DateTime.t(), atom()) :: DateTime.t()
Return a time object where you go back x units. We introduce the notion of hour and minute
A hack to suppress error messages when running lots of flows. These are expected and we want to improve signal <-> noise ratio
@spec in_past_time(DateTime.t(), atom(), integer()) :: boolean()
See if the current time is within the past time units
Log the error and also send it over to our friends at appsignal
Given a string separated by spaces, commas, or semi-colons, create a set of individual elements in the string
Wrapper to return :ok/:error when parsing strings to potential integers
parse and integer and die if parse fails
Wrapper to return :ok/:error when parsing strings to potential integers
You shouldn’t really use String.to_atom/1 on user-supplied data. The BEAM has a limit on how many different atoms you can have and they’re not garbage collected! With data coming from outside the system, stick to strings or use String.to_existing_atom/1 instead! So this is a generic function which will convert the string to atom and throws an error in case of invalid key
@spec signature(non_neg_integer(), String.t(), non_neg_integer()) :: String.t()
Compute the signature at a specific time for the body
@spec stacktrace() :: String.t()
easy way for glific developers to get a stacktrace when debugging
Lets get rid of all non valid characters. We are assuming any language and hence using unicode syntax and not restricting ourselves to alphanumeric
convert string to snake case
Intermediary function to update the input params with organization id as operation is performed by glific_admin for other organizations
Really simple function to ensure folks do not add Repo and/or IO calls to an EEx snippet. This is an extremely short term fix to avoid shooting ourselves in the foot, but we should move to lua for flows scripting in the near future
Note that folks can potentially find other ways to access the same modules, so this by no means should be considered remotely secure
@spec validate_shortcode(Ecto.Changeset.t()) :: Ecto.Changeset.t() | Ecto.Changeset.t()
Validates inputted shortcode, if shortcode is invalid it returns message that the shortcode is invalid along with the valid shortcode.
Verifying Google Captcha