Add a condition in a custom package for If condition
- Updated: 2022/05/19
Add a condition in a custom package for If condition
Add conditions in a custom package.
Create condition values in an Action
- To create a condition, set commandType property of BotCommand annotation with value as Condition.
- To define the entry method of the condition, use the annotation ConditionTest.
@BotCommand(commandType = Condition)
@CommandPkg(label = "File exists", name = "fileExists",
description = "Checks if the file exists.",
node_label = "file exists at {{sourceFilePath}}", icon = "")
public class Exist extends AbstractCondition {
@ConditionTest
public boolean test(@Idx(index = "1", type = FILE) @LocalFile @Pkg(label = "File path") @NotEmpty String sourceFilePath,
@Idx(index = "2", type = NUMBER) @Pkg(label = "How long you would like to wait for this condition
to be true?(Seconds)",
default_value = "0", default_value_type = DataType.NUMBER)
@GreaterThanEqualTo("0") @LessThanEqualTo("99999") @NotEmpty @NumberInteger Double waitTimeout) {
// Add the logic to check for the condition
}
}
The following example verifies if the provided boolean value is false.
Set commandType to Condition.
@BotCommand(commandType = Condition)
@CommandPkg(label = "False condition example", name = "conditionalTypeExample",
description = "Checks if the boolean value is false.")
public class ConditionalTypeExample {
@ConditionTest
public Boolean validate(
@Idx(index = "1", type = AttributeType.BOOLEAN)
@VariableType(BOOLEAN)
@Pkg(label = "Boolean variable", default_value_type = BOOLEAN) @NotEmpty Boolean variable
) {
return variable == null ? false : !variable ;
}