Working with Emotions
As SIML offers EmotionML to be used for emotions an emotion for the Bot or the User can be retrieved using the following code. In SIML the developer has the option of setting the Bot/User emotion but can only retrieve its ID and Name during a Chat session. Much of the action is meant to happen on the Avatar end. A developer may use the Emotion and its properties to help the Avatar ( if being used ) to display complex expressions.
var botEmotion = chatResult.BotEmotion;
var categories = botEmotion.Categories;
var dimensions = botEmotion.Dimensions;
var duration = botEmotion.Duration;
var id = botEmotion.ID;
If no emotions are specified in a response the emotion will stay with its previous value.
Detecting Emotional change in Bot
Emotion of the Bot can change at run-time. Changes in emotions can help developers map the Bot’s current emotion to any desired behavior including but not limited to dynamic facial expressions.
Say for example your SIML code changes the emotion of your Bot from pleased to happy.
<Model>
<Pattern>I LIKE YOU</Pattern>
<Response>You make me blush!<BotEmotion ID="Happy"/></Response>
</Model>
You can detect these emotional changes and act accordingly by attaching an event handler to the Bot’s EmotionChanged
event as shown below.
var simlbot = new SimlBot();
simlbot.EmotionChanged += simlbot_EmotionChanged;
Once the emotion of the Bot is changed the event is fired and the following code gets executed. The event argument is a EmotionChangeEventArgs
class object which provides the Current
emotion, the Previous
emotion and the User associated with the concerned emotional state change
void simlbot_EmotionChanged(object sender, EmotionChangedEventArgs e)
{
var emotion = e.Current;
//Do something with the new Emotion
}
Detecting Emotional change in User
Just like the change in the Bot’s emotion any emotional change of the User can also be detected via the EmotionChanged
event of the User. The procedure is very similar to that of detecting emotional changes in the Bot. Usually an emotional change is triggered when an SIML code with the UserEmotion tag is evaluated as shown below.
<Model>
<Pattern>I am overjoyed</Pattern>
<Response>That is very pleasing.<UserEmotion ID="very-happy"/></Response>
</Model>
Example code to attach an event handler to the user’s EmotionChanged event.
var simlbot = new SimlBot();
var mainUser = simlbot.MainUser;
mainUser.EmotionChanged += mainUser_EmotionChanged;