Events
From version 4.5 onwards OSCOVA supports event triggers. An Event is similar to an Action or even an Intent. However, you trigger an event by directly specifying the name of the event and it doesn't require a user expression to be matched.
Unlike an Action
, events do not need you to explicitly provide values for Context
and Result
. An event is called with the current context of the user calling it and the result
returns an intent that has a match score of 1.
Creating an Event
To create an event decorate a method with Event
attribute and specify the name
of the event.
Note
The name of an event should be unique to the bot. No two events with the same name are allowed.
[Event("app-started")]
public void WeatherEvent(Context context, Result result)
{
//A response for when the app I started.
result.SendResponse("Welcome user! How may I help you?");
}
Calling an Event
The following code shows how to raise an event from for a particular BotUser
object.
[Expression("start the stopwatch")]
public void StartStopwatch(Context context, Result result)
{
result.Bot.Raise("stopwatch-started", result.User);
}
The following code shows how to raise an event from the main user context.
var bot = new OscovaBot();
bot.Dialogs.Add(new MyEventsDialog());
bot.Trainer.StartTraining();
//Call the event for the main user.
bot.Raise("app-started");