OutOfScopeUtteranceHandler.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * Copyright (c) Meta Platforms, Inc. and affiliates.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the license found in the
  6. * LICENSE file in the root directory of this source tree.
  7. */
  8. using Meta.WitAi.Attributes;
  9. using Meta.WitAi.Json;
  10. using Meta.WitAi.Utilities;
  11. using UnityEngine;
  12. using Utilities;
  13. namespace Meta.WitAi.CallbackHandlers
  14. {
  15. /// <summary>
  16. /// Triggers an event when no intents were recognized in an utterance.
  17. /// </summary>
  18. [AddComponentMenu("Wit.ai/Response Matchers/Out Of Domain")]
  19. public class OutOfScopeUtteranceHandler : WitResponseHandler
  20. {
  21. [Space(WitRuntimeStyles.HeaderPaddingTop)]
  22. [TooltipBox("Triggered when a activation on the associated AppVoiceExperience does not return any intents.")]
  23. [SerializeField] private StringEvent onOutOfDomain = new StringEvent();
  24. protected override string OnValidateResponse(WitResponseNode response, bool isEarlyResponse)
  25. {
  26. if (response == null)
  27. {
  28. return "Response is null";
  29. }
  30. if (response["intents"].Count > 0)
  31. {
  32. return "Intents found";
  33. }
  34. return string.Empty;
  35. }
  36. protected override void OnResponseInvalid(WitResponseNode response, string error) {}
  37. protected override void OnResponseSuccess(WitResponseNode response)
  38. {
  39. onOutOfDomain?.Invoke(response.GetTranscription());
  40. }
  41. }
  42. }