VoiceEventToRequestEventMapper.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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.Events;
  9. using Meta.WitAi.Json;
  10. namespace Meta.WitAi.Requests
  11. {
  12. /// <summary>
  13. /// A Facade to easily map events from a VoiceServiceRequestEvents event object to a VoiceEvents object's callbacks.
  14. /// </summary>
  15. public class VoiceEventToRequestEventMapper : VoiceServiceRequestEventsWrapper
  16. {
  17. private VoiceEvents _voiceEvents;
  18. public VoiceEvents VoiceEvents
  19. {
  20. get => _voiceEvents;
  21. set => _voiceEvents = value;
  22. }
  23. public VoiceEventToRequestEventMapper()
  24. {
  25. }
  26. public VoiceEventToRequestEventMapper(VoiceEvents voiceEvents)
  27. {
  28. _voiceEvents = voiceEvents;
  29. }
  30. protected override void OnStateChange(VoiceServiceRequest request)
  31. {
  32. }
  33. protected override void OnStopListening(VoiceServiceRequest request)
  34. {
  35. _voiceEvents.OnStoppedListening.Invoke();
  36. }
  37. protected override void OnStartListening(VoiceServiceRequest request)
  38. {
  39. _voiceEvents.OnStartListening.Invoke();
  40. }
  41. protected override void OnFullTranscription(string transcription)
  42. {
  43. _voiceEvents.OnFullTranscription.Invoke(transcription);
  44. }
  45. protected override void OnPartialTranscription(string transcription)
  46. {
  47. _voiceEvents.OnPartialTranscription.Invoke(transcription);
  48. }
  49. protected override void OnPartialResponse(WitResponseNode response)
  50. {
  51. _voiceEvents.OnPartialResponse.Invoke(response);
  52. }
  53. protected override void OnFullResponse(WitResponseNode response)
  54. {
  55. _voiceEvents.OnResponse.Invoke(response);
  56. }
  57. protected override void OnSuccess(VoiceServiceRequest request)
  58. {
  59. }
  60. protected override void OnSend(VoiceServiceRequest request)
  61. {
  62. }
  63. protected override void OnInit(VoiceServiceRequest request)
  64. {
  65. }
  66. protected override void OnFailed(VoiceServiceRequest request)
  67. {
  68. _voiceEvents.OnError.Invoke(request.Results.Message, "Error: " + request.Results.StatusCode);
  69. }
  70. protected override void OnComplete(VoiceServiceRequest request)
  71. {
  72. _voiceEvents.OnComplete.Invoke(request);
  73. }
  74. protected override void OnCancel(VoiceServiceRequest request)
  75. {
  76. _voiceEvents.OnCanceled.Invoke(request.Results?.Message ?? "");
  77. }
  78. }
  79. }