Skip to content

Intents & entities

An intent which uses regular expressions can be defined as follows:

@greeting intent(match: ["hi", "hello there", "howdy", "hello", "hey"])

dialog trigger: @greeting do
  say "Hello to you too!"
  log intent
end

Entity extraction

The entity builtin defines a matcher which can be used for fuzzy matching in user input and in message triggers. The result is an extracted "entity" - a part of a the string, possibly normalized in a generic format.

@yes entity(match: "yes|yep|sure", label: "Yes", return: :yes)
@no  entity(match: "no|nope|nah", label: "No", return: :no)

@yes entity shows the label "Yes" in the quick replies, returning the atom :yes on match. @no shows the label "No" in the quick replies, returning the atom :no on match.

@postcode entity(match: "[0-9]{4}\\s*[a-z]{2}")

Creates an entity extractor which matches on a regular exression.

Entity usage

Entities can be used in the ask statement, to directly match something and return the value. Entities can be passed in the expecting: construct of the ask statement, and the ask then blocks until (one of) the given entit(y)(ies) has matched.

@number entity(match: "[1-9][0-9]*")
dialog main do
  age = ask "What is your age?", expecting: @number
end

Like intents, entities can also be used as dialog triggers as well:

dialog trigger: @email do
  say "Thank you for your email! You entered: #{entity}"
end

Lastly, entities can be extracted from arbitrary strings using the extract_entity() function:

@postcode entity(match: "[0-9]{4}\\s*[a-z]{2}")

dialog extract_entity do
  sentence = "My postcode is 1061BM now"
  entity = extract_entity(sentence, @postcode)
  say entity.value
end