Advanced keywords enable you to create a much wider variety of combinations for keyword triggers. For example, if a user types 'data' and 'policy', the bot will reply with a message you've created on data policies. If the user types in just 'policy' but not 'data', then the bot will just reply with a message about just policies.
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 in the meantime.
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("policy", input) - where “policy” is the word you’d like to check for, and input represents what the user has typed into the bot. Both “policy” and the input are passed into the is function and compared with each other. If input is a perfect match for “policy” then this function returns true, which means the message associated with the advanced keyword is sent.
CONTAINS: contains("policy", input) - where “policy” is the word you’d like to check for, and input represents what the user has typed into the bot. Both “policy” and the input are passed into the is function and compared with each other. If input is contains the word “policy” 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
Example input: “Are there any in depth documents on our diversity policy?”
Advanced keyword: contains("documents", input) && contains("diversity", input)
Bot reply: “Here are some documents that go into detail about our diversity policy”
Explanation: Here we’re saying that what the user typed into the bot must contain both “documents” and “diversity”. 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.
-
Example input: “What is our diversity policy?”
Advanced keyword: contains("diversity policy", input) && !contains("documents", input)
Bot reply: “Our diversity policy is....”
Explanation: Here we’re saying that what the user typed into the bot must contain “diversity policy” but not contain “documents”. 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 “documents” 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("documents", input) we’re saying “user input does not contain the word ‘documents’”.
-
Say I'm making a lunch buddy bot. I would program my advanced keywords in this way:
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”
Advanced keyword: (contains("sandwich", input) && contains("bacon", input) && !contains("cheese", input)) || (contains("sandwich", input) && contains("cheese", input) && !contains("bacon", input))
Bot reply: “your sandwich with one filling is coming up!”
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!