Trait
Category 1: As children of root <Siml>
element.
Annotation | <Trait> |
---|---|
Definition | Encapsulates a collection of <Expression> elements for reusability by intents in different contexts. |
Children | The element MUST contain one or more <Expression> elements. |
Attributes | Required: Type : An attribute that specifies a unique trait type that MUST exist in <Trait> element. |
Occurrence | One or more <Trait> element MAY occur as children of <Siml> element |
Category 1: As children of <Intent>
element.
Annotation | <Trait> |
---|---|
Definition | Specifies an existing trait whose expressions are to be imported. |
Attributes | Required: Type : An attribute that specifies the trait type that MUST exist in <Trait> element. |
Occurrence | One <Trait> element MAY occur as children of <Intent> element |
Trait elements are powerful elements that allows developers to group expressions within a specified name for reusability. Traits dramatically reduce redundancy of rewriting similar expression groups in large projects.
Using traits that are coded in SIML Modern, developers can also decouple expressions from backend intents written within a bot application. This allows later changes to the expressions within the trait without having to rebuild a bot project.
Creating a Trait
SIML
<Trait Type="#startapp">
<Expression Value="launch @app"/>
<Expression Value="run @app"/>
<Expression Value="start the @app application"/>
</Trait>
The above trait can later be used as shown in the SIML code below.
<Intent Name="launch_app">
<Trait Type="#startapp"/>
<Action ID="start-app-action"/>
</Intent>
Traits and fields
Optionally developers can specify placeholders for values within a trait's expression collection that may later be filled by the calling intent.
In the SIML code below $ITEM
is the placeholder that all intents making use of this trait should specify a value for.
<Trait Type="#download-product">
<Expression Value="where can I download $ITEM"/>
<Expression Value="download link for $ITEM"/>
<Expression Value="where can I find $ITEM"/>
</Trait>
The above trait can now be used in different intents that will explicitly specify a value for the placeholder $ITEM
<Intent Name="download_product_a">
<Trait Type="download-product" Fields="@productA"/>
<Response>
The download link is https://example.com/productA
</Response>
</Intent>
<Intent Name="download_product_b">
<Trait Type="download-product" Fields="@productB"/>
<Response>
The download link is https://example.com/productB
</Response>
</Intent>
Note
By convention, names of placeholders should start with a dollar sign ($)