Based on an Expression

AMPS provides an If module for stopping execution of the action unless a specific condition is met.

Module Name
Does

amps-action-if-condition

Checks whether the specified expression is true or false.

If the expression evaluates to true, subsequent steps in the action run. If not, the action stops at this step.

Parameter
Description

Condition

(required)

Specifies the condition to evaluate. The condition must be a valid AMPS filter.

The condition will substitute variables from the current context before being evaluated.

There is no default for this parameter.

This module does not add any variables to the AMPS context.

For example, the following action publishes a message to a topic if a client with a name that matches a specific expression logs on.

<Actions>
    <Action>
        <On>
            <Module>amps-action-on-connect-client</Module>
        </On>
        <If>
            <Module>amps-action-if-condition</Module>
            <Options>
                <Condition>'{{AMPS_CLIENT_NAME}}' LIKE 'important'</Condition>
            </Options>
        </If>
        <Do>
            <Module>amps-action-do-publish-message</Module>
            <Options>
               <Topic>important-logon-notification</Topic>
               <MessageType>json</MessageType>
               <Data>{"name":"{{AMPS_CLIENT_NAME}}"}</Data>
            </Options>
        </Do>
    </Action>
</Actions>

The example above is provided to illustrate use of amps-action-if-condition.

In practice, this could also be done using an amps-action-on-publish-message action to monitor the /AMPS/ClientStatus topic with a filter.

Last updated