How to write automation rules using BLANG

Rule expressions are the data types, parameters and operators that make up rules.

Together, they represent what a rule looks for when processing a piece of content.

Data types

Integer

An Integer represents a whole number, without a fractional part.

Example: 42

Number

A Number represents a numerical value, with or without a fractional part (i.e. integer or float).

Examples: 42, 3.14

Boolean

Boolean is a data type that can have either of two values: true or false.   
Example: true

String

A String represents a piece of text in between double quote characters.

Example: "This is just a piece of text"

Regular expression

Regular expressions can be used where a String value is expected. They can also be a part of an array.
Example: /[a-z]*/

Regular expressions support flags, so you can write: /[a-z]*/i .

The flag g for global search is implied by default.

List

Instead of comparing values one by one and creating long expressions, you can use lists to compare a variable against a list of String, Number, or Regex values. Note that data types can be mixed and matched in your lists. If the list is using Regex the operator should be CONTAINS and not EQUALS.

Lists can either be defined inline in your expressions, or created and populated using the Implio user interface and then referred to in your expression by their name.

Sample expression Equivalent using an inline List Equivalent using a named List
$ip EQUALS "24.8.52.249" OR $ip EQUALS "212.97.3.45" $ip EQUALS ("24.8.52.249", "212.97.3.45") $ip EQUALS @blacklistedUsers
$title CONTAINS "hello" OR $title CONTAINS "hallo" OR $title CONTAINS "ola" $title CONTAINS ("hello", "hallo", "ola") $title CONTAINS @greetings
$text CONTAINS /dog(s)?/ OR $text CONTAINS /cat(s)?/ $text CONTAINS (/dog(s)?/, /cat(s)?/) $text CONTAINS @animals

BLANG variables

The following section describes all the variables that can currently be accessed using BLANG.

Variables representing API input

The following variables correspond to fields specific in the API request payload.

Variable Description Type Example
$title Title of an item String "For sale"
$body Body of an item String "It is really nice"
$text Concatenation of the title and body of an item, with a line break separating them. String "For sale   
It is really nice"
$email First email address of the user posting the item String "test@besedo.com"
$phoneNumber First phone number of the user posting the item String "08-123 123 33"
$categoryName Category name of the item String "Cars"
$categoryId Category ID of the item String "cars", "vehicles-cars" or "22"
$price Price of the item Number 1400
$currency ISO 4217 currency code String "EUR"
$type Type of the item String "buy", "sell" or "rent"
$userId Id of the user posting the item String "fjuki97"
$userName Username of the user posting the item String "Fjodor Kiriakos"
$city City name String "Stockholm"
$postalCode Postal (zip) code String "12346"
$region Region String "Stockholm"
$countryCode Two-letter country code (ISO 3166-1 alpha-2) String "SE"
$ip IP address of the user posting the ad String "127.0.0.1"
$status Status of the item in your system String "published"
$images.count Number of images that the item contains Integer 3
$images.failCount Number of item images that failed to be retrieved from the specified URL and therefore couldn't be processed Integer 0
$videos.count Number of videos that the item contains Integer 1
$images.fingerprint Image fingerprint (phash) calculated by implio to identify and compare images between each other. String "c6766953849aae6ba53cdd87e1b6342c6"

Variables representing user's moderation history

The following variables contain statistics about the moderation history of the user (referred to by the user.id specified in the API request payload) to date.

Variable Description Type Example
$user.itemCount Number of items seen in Implio for that user to date. Integer 10
$user.itemCount.1minute Number of items seen in Implio for that user over the past minute (past 60 seconds). Integer 0
$user.itemCount.1hour Number of items seen in Implio for that user over the past hour (past 60 minutes). Integer 1
$user.itemCount.1day Number of items seen in Implio for that user over the past day (past 24 hours). Integer 4
$user.itemCount.1week Number of items seen in Implio for that user over the past day (past 7 days). Integer 10
$user.itemCount.1month Number of items seen in Implio for that user over the past month (past 30 days). Integer 34
$user.itemCount.1year Number of items seen in Implio for that user over the past month (past 12 months). Integer 60
$user.decisionCount Number of items with an Approved or Refused decision for that user to date. Integer 10
$user.noDecisionCount Number of items without a decision (No decision) for that user to date. Integer 0
$user.approvedCount   
$user.refusedCount
Number of Approved (resp. Refused) decisions for that user to date. Integer 9   
1
$user.approvedPercentage   
$user.refusedPercentage
Percentage of Approved (resp. Refused) items over decision count for that user to date. Integer 90   
10
$user.approvedStreak   
$user.refusedStreak
Number of items last Approved (resp. Refused) in a row for that user to date.   

If the last decision is not Approved (resp. Refused), then $user.approvedStreak (resp. $user.refusedStreak) will necessarily have a null (0) value.
Integer 5   
0

Variables augmented from input

Geolocation

The following variables allow you to leverage the built-in automatic geolocation of end users in your automation rules.

See How to locate end users using geolocation to learn more about geolocation and how to make use of it.

Variable Description Type Example
$geoCity Name of the city (in English) associated with the user's geolocation at the time of posting String "Stockholm"
$geoContinent Name of the continent (in English) associated with the user's geolocation at the time of posting String "Europe"
$geoCountry Name of the country (in English) associated with the user's geolocation at the time of posting String "Sweden"
$geoCountryCode Two-letter country code (ISO 3166-1 alpha-2) associated with the user's geolocation at the time of posting String "SE"
$geoPostalCode Postal code associated with the user's geolocation at the time of posting String "117 43"

User agent

The following variables allow you to leverage information extracted from the user.agent field supplied in the API.

Variable Description Type Example
$user.agent.device.type Type of device String "mobile"
$user.agent.device.model Device model String "Pixel 6"
$user.agent.device.brand Device brand String "Google"
$user.agent.client.name Client (browser or app) name String "Chrome"
$user.agent.os.family Operating system family String "Android"
$user.agent.os.version Operating system version String "13"
$user.agent.cpu.architecture CPU architecture String "amd64"

Deduplication

The following variables allow you to leverage the built-in duplicate detection capabilities of Implio in your automation rules.

See How to detect and moderate duplicate items to learn more about duplicate detection and how to make use of it.

Variable Description Type Example
$numberOfDuplicates Number of text (title + body) duplicates across the entire Implio team Integer 3
$images[N].duplicateCount Number of image duplicates for image N across the entire Implio team Integer 7
$images.duplicateCount Combined number of image duplicates for all images in the item, across the entire Implio team.   

For instance, should an item have 2 images with $images[0].duplicateCount   
having a value of 7 and $images[1].duplicateCount having a value of 5, $images.duplicateCount   
will have a value of 12.
Integer 12

AI features (Text Vision & Image Vision)

Implio comes with a number of built-in models that allow you to make sense of user-generated text and images, and make them actionable via a number of variables.

These are documented here:

Customer-specific variables

In addition to the built-in variables listed above, it is also possible to send in custom parameters. A custom parameter must be prefixed with $$ to avoid naming collisions with present and future built-in variables.

Examples:

  • $$fueltype
  • $$facebookId
  • $$longitude

Comparison operators

The following comparison operators are available in your expressions. These can be combined at will using logical operators (see next section).

Left operand type Operator Right operand type(s) Description (true if…) Example
$variable < Number Variable is less than Number. $price < 1000
$variable <= Number  Variable is less than or equal to Number. $price <= 1000
$variable > Number  Variable is greater than Number. $price > 1000
$variable >= Number Variable is greater than or equal to Number. $price >= 1000
$variable BETWEEN Number range  Variable is in the Number range. $price BETWEEN 100 - 200
$variable EQUALS String, Number, Boolean Variable is equal to value. $price EQUALS 9.99

$categoryName EQUALS "Cars"
$variable EQUALS Text List Variable is equal to one or more values in List. $categoryName EQUALS ("Cars", "Electronics")
$variable CONTAINS String Variable contains the String subsequence.

See Word matching section below for more information about how strings are matched.
$title CONTAINS "Certified"
$variable CONTAINS Regex Variable matches the Regex. $body CONTAINS /whatsapp/
$variable CONTAINS Text List Variable contains one or more String values in List, or matches one or more Regex in List. $text CONTAINS ("CE", "Certificate", /conform/)   

$ip CONTAINS @blacklistedIPs
$variable CONTAINS [x,y] String, Regex, Text List Variable contains or matches between x and y occurrences of String/Regex value(s).

Either x or y can be omitted to specify only a lower or upper boundary.
$text CONTAINS [3,] @badWords
$variable CONTAINS {unique=true} [x,y] Text List Variable contains or matches between x and y unique occurrences of String/Regex values. $body CONTAINS {unique=true} [2,] ("audi", "bmw", /mercedes(-benz)?/, "peugeot", "renault")
$images.fingerprint SIMILAR Image List Images are similar to a list of images. $images.fingerprint SIMILAR @ScammerPicturesList

Word boundaries

Word boundaries are respected for Strings, but not for Regular Expressions.

Examples

Given $text having a value of "Hello friend how are you?":

Expression Result
$text CONTAINS "friend" true
$text CONTAINS "fri" false
$text CONTAINS /fri/ true

Case sensitivity

String matches ignore case but Regular Expressions are case sensitive, unless the /i flag is specified.

Examples

Given $text having a value of "Hello friend how are you?":

Expression Result
$text CONTAINS "hello" true
$text CONTAINS "HELLO" true
$text CONTAINS /hello/ false
$text CONTAINS /hello/i true

Logical operators

Expressions can be combined using AND and OR operators. The evaluation order can be prioritized using parentheses ( ).

By default, AND has a higher priority than OR. This mean that a OR b AND c will be evaluated as a OR (b AND c)

Expressions can also be negated using NOT.

Examples

  • $categoryName EQUALS "Cars" AND $price < 1000
  • $title EQUALS "hello" AND NOT ($body CONTAINS @badWords OR $body CONTAINS @contactInfo)

Operator negation

The following operators can be negated by adding NOT in front of them:

  • NOT BETWEEN
  • NOT EQUALS
  • NOT CONTAINS

The following expressions are strictly equivalent:

NOT ($price BETWEEN 0 - 10) $price NOT BETWEEN 0-10
NOT ($title EQUALS "hello") $title NOT EQUALS "hello"
NOT ($body CONTAINS "whatsapp") $body NOT CONTAINS "whatsapp"

Other operators

Checking whether a variable is defined

You can check whether a variable is defined and has a value different from null, using the EXISTS operator.

It works both with built-in and customer-specific variables.

Examples

  • EXISTS ($price)
  • NOT EXISTS ($$fraudScore)

Testing the length of a string

You can test the length of a variable using the LENGTH operator.

It works both with built-in and customer-specific variables.

Examples

  • LENGTH ($body) < 160
  • LENGTH ($$myCustomField) > 0

Comparing variables

You can compare two variables by using them on both sides of the EQUALS operator.

Examples

  • $title EQUALS $body
  • $text.languageDetected NOT EQUALS $text.languageExpected

Comments

Expressions allow comments to be inserted using the # delimiter. Both line and inline comments are supported:

# This is a comment

$text CONTAINS /regex/ # This is another comment

Was this article helpful?

Can’t find what you’re looking for?

Our customer care team is here for you.