Advanced keywords enable you to create a much wider variety of combinations for keyword triggers. For example, you could now say if a user types 'burger' and 'fries' then reply with 'the full combo'. If the user types 'burger' but does not type 'fries' then reply with 'just the burger'.

We've written down a few examples of the sort of things you can do with advanced keywords. The interface still needs a lot of work to be user friendly but we hope you can make use of the beta capabilities whilst we make that easier.

Recreating IS and CONTAINS

When creating expressions, we can either say that the user input contains a particular word, or that the user input is a particular word.  In order to check this, use these functions (copy and paste the italic part):  

IS: is("banana", input) - where “banana” is the word you’d like to check for, and input represents what the user has typed into the bot.  Both “banana” and the input are passed into the is function and compared with each other.  If input is a perfect match for “banana” then this function returns true, which means the message associated with the advanced keyword is sent.

CONTAINS: contains("banana", input) -  where “banana” is the word you’d like to check for, and input represents what the user has typed into the bot.  Both “banana” and the input are passed into the is function and compared with each other.  If input is contains the word “banana” then this function returns true, which means the message associated with the advanced keyword is sent.Note that the word input should always be kept as input, as that’s what we use internally to represent what the user typed into the bot.

Examples

Reply: “so you’d like a burger with fries” 

Advanced keyword: contains("burger", input) && contains("fries", input) 

Example input: “I’d like a burger with fries please” 

Explanation: Here we’re saying that what the user typed into the bot must contain both “burger” and “fries”.  We can do this by putting the && between the contains functions which means “and”.  If we wanted the user to have additionally typed in “please” then we could add && contains("please", input).  Using && effectively lets you say “this, and this, and this...” etc.

Reply: “so you’d like a burger without fries” 

Advanced keyword: contains("burger", input) && !contains("fries", input) 

Example input: “I’d like just a burger please” 

Explanation: Here we’re saying that what the user typed into the bot must contain “burger” but not contain “fries”.  So, we’re using the && as before to say that “both these contains functions must ring true”.  However, in order to say that we don’t want “fries” in what the user’s typed, we use the exclamation mark!  It’s effectively a short-hand way of saying “not this”.  So by saying !contains("fries", input) we’re saying “user input does not contain the word ‘fries’”.

Reply: “your sandwich with one filling is coming up!” 

Advanced keyword: (contains("sandwich", input) && contains("bacon", input) && !contains("cheese", input)) || (contains("sandwich", input) && contains("cheese", input) && !contains("bacon", input)) 

Example input: “I’d like a sandwich with bacon please” OR “I’d like a sandwich with cheese please”, but the follow will NOT trigger “I’d like a sandwich with bacon and cheese please” 

Explanation: Here we’re saying that what the user typed into the bot must contain “sandwich” and “cheese”, or “sandwich” and “bacon” but NOT “sandwich”, “cheese” and “bacon”.  So, you can have a sandwich but with only 1 filling - sad huh?  What’s happening here is we’re grouping the 2 options for sandwich fillings.  You’ll see that there’s 3 contains functions checking for “sandwich”, “bacon” and not “cheese” (see the ! mark?).  Then there’s another 3 contains checking for “sandwich”, “cheese” and not “bacon”.  We’ve grouped these together with parentheses.  This is no different from calculating mathematic equations.  E.g., if you see this: (5 + 5) x (6 - 1), you’d probably think “I’ll do 5 + 5 first, so that’s 10, then 6 - 1 second, so that’s 5, then I’ll do 10 x 5 which gives me 50.  The exact same thing is happening with our advanced keyword.  We’re saying “work out if the first 3 contains in parentheses are true” and “work out if the second 3 contains in parentheses are true”.  Now, you’ll probably notice there’s a || in between them.  This is how we say “or”.  So we’re saying “these 3 things must ring true OR these other three things must ring true”.  We’d recommend using parentheses to group things together when checking that multiple things are true.  With parentheses, && and || you can build up quite advanced keywords!

Reply: “see ya!” 

Advanced keyword: is("bye", input) 

Example input: “bye” 

Explanation: Here we’re saying that what the user typed in must exactly match “bye”.

Reply: “hello!!” 

Advanced keyword: input IN ("hello", "hi", "hey", "ola", "bonjour", "wurd up") 

Example input: “hello” OR “hi” OR... you get the idea... 

Explanation: Here we’re saying that what the user types in must exactly match “hello” or “hi” or “hey” or “ola” or “bonjour” or “wurd up”.  This is a nice short-hand way of having to write an advanced keyword like is("hello", input) || is("hi", input) || is("hey", input)... etc.  So, in this case the IN word precedes an array, or list, of things that we’d like to check that input matches.

Did this answer your question?