Action
Annotation | <Action> |
---|---|
Definition | Used to specify the pre-declared action that is to be invoked. |
Attributes | ID : An <Action> element MUST contain an ID attribute that specifies the ID of the action that is to be invoked. |
Occurrence | An <Action> element MUST occur as a child of <Intent> element if the <Intent> element has no child <Response> element OR as a child of <Siml> element if the action represents a global response action with one <Response> element. |
Action Declaration
An <Action>
enables developer to create an abstraction layer between expressions and the target action that is to be invoked. An <Action>
must only exist within an <Intent>
element if it does not have an explicit <Response>
element.
Example
<Intent>
<Expression Value="Employees who joined on @sys.date"/>
<Action ID="find.by.date.action"/>
</Intent>
Explanation
In the above expression, when the user says Employees who joined on Sixth of January the action with the ID
find.by.date.action
is invoked by the bot.
An example action for the above SIML code would look like the following:
[Action(ID = "find.by.date.action")]
public void FindEmployeesByDate(Context context, Result result)
{
//Do Something here
}
Action
can also be declared within Response
elements in case the called action doesn't generate any textual response.
Example
<Intent>
<Expression Value="Employees who joined on @sys.date" />
<Response>
Here's a list of employees who joined on the specified date.
<Action ID="find.by.date.action" />
</Response>
</Intent>
Important
If you are specifying an Action
within a Response
element ensure that the action that is being called does not generate a response. If the action to be called is supposed to generate a response then use Action Intent format instead.
Global Actions
Global SIML actions are defined when a particular response need to be made reusable during the execution of the Bot. To create a global response action create an <Action>
element directly within an <Siml>
element and specify the value for the <Response>
element.
<Action ID="bye-action">
<Response>
<Random>
<Item>See you.</Item>
<Item>Talk to later.</Item>
<Item>Bye.</Item>
</Random>
</Response>
</Action>
Using the response within an SIML intent
<Intent Name="ByeIntent">
<Expression Value="bye"/>
<Expression Value="see ya"/>
<Action ID="bye-action"/>
</Intent>
Using the response action within an Intent
[Expression("bye")]
[Expression("take care")]
public void ByeIntent(Context context, Result result)
{
result.Bot.Actions["bye-action"].Invoke(context, result);
}