Contents

Support Managers

Rehnaeaislinn
English
online
TwixiChardonnay
English
online
show offline managers  
English, Hindi, Russian  

if (SBSL Command)

Have a question? Ask at SmartBots DevPortal!

DevPortal is a blog and forum for developers. Ask your questions to get a prompt reply!

Continue to DevPortal


Provides the conditional execution of the commands.

Syntax

if $VARIABLE_NAME compare TEXT_OR_VARIABLE
   ...COMMANDS 1...
elsif $VARIABLE_NAME compare TEXT_OR_VARIABLE_2
   ...COMMANDS 2...
else
   ...COMMANDS 3...
endif

Command parameters

The following table explain the entries of the command:

Entry Description
$VARIABLE_NAME is one of the event's predefined variables
compare is a comparison operator (see below)
TEXT_OR_VARIABLE is either predefined variable or string


Comparison operators

compare is a comparison operator:

== exact match
!= no match
=~ $VARIABLE_NAME contains the TEXT (case sensitive!)
!~ $VARIABLE_NAME does not contain the TEXT (case sensitive!)
=~* $VARIABLE_NAME contains the TEXT (case insensitive)
!~* $VARIABLE_NAME does not contain the TEXT (case insensitive)

Whole word match only

Substring comparison matches with any substring by default:

# this will work for the following messages:
# "ok", "okay", "ok, fine!", "spoke", "it is ok"
 
if $message =~* ok
  ...
endif

You can force the complete word match by placing your string to double quotes:

# this will work only with:
# "ok", "ok, fine!", "it is ok"
 
# these strings DO NOT match anymore:
# "okay", "spoke"
 
if $message =~* "ok"
  ...
endif

Comments

Subsequent comparisons

Each if may contain one or more elsif lines to check subsequent conditions. Also, else keyword may contain additional commands which does not fit any comparison.

See one of SBSL examples for demonstration.

Comparing empty strings

To compare variable against empty string, use NULL:

if $message != NULL
   ...COMMANDS...
endif

<< return back to SBSL commands