Fallback Intents
Fallback intents in Oscova get evaluated when no other declared intents are matched against user input. From v2.6.0 Oscova supports global and contextual fallbacks.
Global Fallback
A global fallback is triggered when none of the developer declared intents are matched with the specified minimum confidence score. To create a global fallback decorate an intent method with an empty FallbackAttribute
.
[Fallback]
public void GlobalFallback(Context context, Result result)
{
result.SendResponse("I am sorry. Could you please rephrase that for me?");
}
Contextual Fallback
Contextual fallback intents are triggered when no other intent with the specified context is matched. To create a contextual fallback decorate an intent method with a FallBackAttribute
and explicitly specify the context name via the Context
property.
The following code shows how a contextual fallback for the context in-logout
.
public class LogoutDialog : Dialog
{
[Expression("{log out}")]
[Expression("{logout}")]
[Expression("please {log out}")]
[Entity("logout")]
public void Logout(Context context, Result result)
{
context.Add("in-logout", 1);
result.SendResponse("Are you sure?");
}
[Expression("@sys.positive")]
[Context("in-logout")]
public void LogoutYes(Context context, Result result)
{
context.Remove("in-logout");
//Do something here.
}
[Expression("@sys.negative")]
[Context("in-logout")]
public void LogoutNo(Context context, Result result)
{
context.Remove("in-logout");
//Do something here.
}
[Fallback(Context = "in-logout")]
public void LogoutFallback(Context context, Result result)
{
context.Remove("in-logout");
result.SendResponse("Logout canceled.");
}
}
Context handling by fallbacks
By default on every contextual fallback OSCOVA removes the specified context name from context container. To let the context specified in Fallback
stay active for the specified lifespan instead of getting automatically removed you can manually set the value to false
in Bot configuration for the RemoveContextOnFallback
property.
OscovaBot.Configuration.RemoveContextOnFallback = false;