Intent Naming
Oscova offers a few ways to let developers control how Intents are named during serialization. By default the name of an Intent is the concatenation of the name of the Dialog and the Intent Method name.
Intent name generation process involves:
Step | Description |
---|---|
1 | Check if IntentAttribute is specified. If Yes use the value specified for Name property If No move to Step 2. |
2 | Check the value of UseFullIntentName . If true prefix the name of the Dialog to intent name. If false use the method name. |
3 | InvokeIntentNameProvider and apply the returned string value as the name of the intent. |
Default naming scheme
In the code below the name of the intent during serialization would be GarageDialog.OpenDoor.
class GarageDialog : Dialog
{
[Expression("Open garage door")]
public void OpenDoor(Context context, Result result)
{
//Do something
}
}
Without a Dialog name
In order to dismiss the Dialoag name from being added to Intent names set the value of UseFullIntentName
in Bot.Configuration
property to false
.
var bot = new OscovaBot();
bot.Configuration.UseFullIntentName = false;
Once the value of UseFullIntentName
is set to false
the name of the Intent in the example code below would become MoveToDirection.
class RobotDialog : Dialog
{
[Expression("Move @direction")]
public void MoveToDirection(Context context, Result result)
{
//Do something
}
}
Explicitly specifying an Intent name
The IntentAttribute
allows developers to explicitly specify an Intent name that disregards whether or not the UseFullIntentName
property is set to true
or false
.
class EmployeeDialog : Dialog
{
[Expression("Find @employee")]
[Intent(Name="find.employee")]
public void FindEmployee(Context context, Result result)
{
//Do something
}
}
In the above example code as the Intent
attribute's Name
property is set, the name of the intent will now become find.employee. The value of UseFullIntentName
in Bot.Configuration
has no effect if the name of an Intent is explicitly specified using the IntentAttribute
.
IntentNameProvider
Delegate
The IntentNameProvider
delegate of Bot.Configuration
holds a reference method that performs the final transformation on every intent name.
Example
The example code below shows how you can override the default IntentNameProvider
reference method to convert all intent names to their lowercase forms.
var bot = new OscovaBot();
bot.Configuration.UseFullIntentName = false;
bot.Configuration.IntentNameProvider = delegate(string name)
{
//Change intent name to its lowercase and replace underscore with dot
return name.ToLower().Replace("_", ".");
};
After the above implementation is added to IntentNameProvider
, the name of the intent in the example code below would become confirm.order.
class OrderDialog : Dialog
{
[Expression("{Yes}")]
[Entity("@sys.positive")]
public void Confirm_Order(Context context, Result result)
{
//Do something
}
}
Duplicate Intent names
From version 2.9.0
OSCOVA enforces duplicate intent name exceptions. This is to ensure that developers who manually set intents names do not, by mistake, give different intents the same global identifiers.
If for some reason you wish to disable this check you can set the value to false
on Bot configuration as shown in the code below.
OscovaBot.Configuration.CheckIntentNames = false;
Important
Changing the value to false
may result in unexpected behavior. We recommend you keep the value of CheckIntentNames
to its default value of true
.