Add sleep and spin-around global command handling
This commit is contained in:
@@ -3096,6 +3096,56 @@ public sealed class JiboInteractionServiceTests
|
||||
Assert.Equal("global_commands", decision.SkillPayload["nluDomain"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task BuildDecisionAsync_CanYouGoToSleep_UsesSourceBackedSleepReply()
|
||||
{
|
||||
var service = CreateService();
|
||||
|
||||
var decision = await service.BuildDecisionAsync(new TurnContext
|
||||
{
|
||||
RawTranscript = "can you go to sleep",
|
||||
NormalizedTranscript = "can you go to sleep"
|
||||
});
|
||||
|
||||
Assert.Equal("robot_can_sleep", decision.IntentName);
|
||||
Assert.Contains("I do. I usually fall asleep at night.", decision.ReplyText, StringComparison.OrdinalIgnoreCase);
|
||||
Assert.Equal("ScriptedResponse", decision.ContextUpdates![ChitchatRouteKey]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task BuildDecisionAsync_GoToSleep_MapsToIdleSleepCommand()
|
||||
{
|
||||
var service = CreateService();
|
||||
|
||||
var decision = await service.BuildDecisionAsync(new TurnContext
|
||||
{
|
||||
RawTranscript = "go to sleep",
|
||||
NormalizedTranscript = "go to sleep"
|
||||
});
|
||||
|
||||
Assert.Equal("sleep", decision.IntentName);
|
||||
Assert.Equal("@be/idle", decision.SkillName);
|
||||
Assert.Equal("sleep", decision.SkillPayload!["globalIntent"]);
|
||||
Assert.Equal("global_commands", decision.SkillPayload["nluDomain"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task BuildDecisionAsync_TurnAround_MapsToIdleSpinAroundCommand()
|
||||
{
|
||||
var service = CreateService();
|
||||
|
||||
var decision = await service.BuildDecisionAsync(new TurnContext
|
||||
{
|
||||
RawTranscript = "turn around",
|
||||
NormalizedTranscript = "turn around"
|
||||
});
|
||||
|
||||
Assert.Equal("spin_around", decision.IntentName);
|
||||
Assert.Equal("@be/idle", decision.SkillName);
|
||||
Assert.Equal("spinAround", decision.SkillPayload!["globalIntent"]);
|
||||
Assert.Equal("global_commands", decision.SkillPayload["nluDomain"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task BuildDecisionAsync_NeverMindWithPunctuation_MapsToIdleStopCommand()
|
||||
{
|
||||
|
||||
@@ -2831,6 +2831,90 @@ public sealed class JiboWebSocketServiceTests
|
||||
redirectPayload.RootElement.GetProperty("data").GetProperty("nlu").GetProperty("intent").GetString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ClientAsr_GoToSleep_EmitsIdleSleepRedirect()
|
||||
{
|
||||
await _service.HandleMessageAsync(new WebSocketMessageEnvelope
|
||||
{
|
||||
HostName = "neo-hub.jibo.com",
|
||||
Path = "/listen",
|
||||
Kind = "neo-hub-listen",
|
||||
Token = "hub-sleep-token",
|
||||
Text =
|
||||
"""{"type":"LISTEN","transID":"trans-sleep","data":{"hotphrase":true,"rules":["launch","globals/global_commands_launch"]}}"""
|
||||
});
|
||||
|
||||
var replies = await _service.HandleMessageAsync(new WebSocketMessageEnvelope
|
||||
{
|
||||
HostName = "neo-hub.jibo.com",
|
||||
Path = "/listen",
|
||||
Kind = "neo-hub-listen",
|
||||
Token = "hub-sleep-token",
|
||||
Text = """{"type":"CLIENT_ASR","transID":"trans-sleep","data":{"text":"go to sleep"}}"""
|
||||
});
|
||||
|
||||
Assert.Equal(5, replies.Count);
|
||||
Assert.Equal("LISTEN", ReadReplyType(replies[0]));
|
||||
Assert.Equal("EOS", ReadReplyType(replies[1]));
|
||||
Assert.Equal("SKILL_REDIRECT", ReadReplyType(replies[2]));
|
||||
Assert.Equal("SKILL_ACTION", ReadReplyType(replies[3]));
|
||||
Assert.Equal("SKILL_ACTION", ReadReplyType(replies[4]));
|
||||
|
||||
using var listenPayload = JsonDocument.Parse(replies[0].Text!);
|
||||
var nlu = listenPayload.RootElement.GetProperty("data").GetProperty("nlu");
|
||||
Assert.Equal("sleep", nlu.GetProperty("intent").GetString());
|
||||
Assert.Equal("global_commands", nlu.GetProperty("domain").GetString());
|
||||
Assert.Equal("globals/global_commands_launch", nlu.GetProperty("rules")[0].GetString());
|
||||
|
||||
using var redirectPayload = JsonDocument.Parse(replies[2].Text!);
|
||||
Assert.Equal("@be/idle",
|
||||
redirectPayload.RootElement.GetProperty("data").GetProperty("match").GetProperty("skillID").GetString());
|
||||
Assert.Equal("sleep",
|
||||
redirectPayload.RootElement.GetProperty("data").GetProperty("nlu").GetProperty("intent").GetString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ClientAsr_TurnAround_EmitsIdleSpinAroundRedirect()
|
||||
{
|
||||
await _service.HandleMessageAsync(new WebSocketMessageEnvelope
|
||||
{
|
||||
HostName = "neo-hub.jibo.com",
|
||||
Path = "/listen",
|
||||
Kind = "neo-hub-listen",
|
||||
Token = "hub-spin-token",
|
||||
Text =
|
||||
"""{"type":"LISTEN","transID":"trans-spin","data":{"hotphrase":true,"rules":["launch","globals/global_commands_launch"]}}"""
|
||||
});
|
||||
|
||||
var replies = await _service.HandleMessageAsync(new WebSocketMessageEnvelope
|
||||
{
|
||||
HostName = "neo-hub.jibo.com",
|
||||
Path = "/listen",
|
||||
Kind = "neo-hub-listen",
|
||||
Token = "hub-spin-token",
|
||||
Text = """{"type":"CLIENT_ASR","transID":"trans-spin","data":{"text":"turn around"}}"""
|
||||
});
|
||||
|
||||
Assert.Equal(5, replies.Count);
|
||||
Assert.Equal("LISTEN", ReadReplyType(replies[0]));
|
||||
Assert.Equal("EOS", ReadReplyType(replies[1]));
|
||||
Assert.Equal("SKILL_REDIRECT", ReadReplyType(replies[2]));
|
||||
Assert.Equal("SKILL_ACTION", ReadReplyType(replies[3]));
|
||||
Assert.Equal("SKILL_ACTION", ReadReplyType(replies[4]));
|
||||
|
||||
using var listenPayload = JsonDocument.Parse(replies[0].Text!);
|
||||
var nlu = listenPayload.RootElement.GetProperty("data").GetProperty("nlu");
|
||||
Assert.Equal("spinAround", nlu.GetProperty("intent").GetString());
|
||||
Assert.Equal("global_commands", nlu.GetProperty("domain").GetString());
|
||||
Assert.Equal("globals/global_commands_launch", nlu.GetProperty("rules")[0].GetString());
|
||||
|
||||
using var redirectPayload = JsonDocument.Parse(replies[2].Text!);
|
||||
Assert.Equal("@be/idle",
|
||||
redirectPayload.RootElement.GetProperty("data").GetProperty("match").GetProperty("skillID").GetString());
|
||||
Assert.Equal("spinAround",
|
||||
redirectPayload.RootElement.GetProperty("data").GetProperty("nlu").GetProperty("intent").GetString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task ClientAsr_TurnItDown_EmitsGlobalVolumeDownWithoutCloudSpeech()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user