From 2dd99da67f0c83fc50ac0ecfea82fc2e251da861 Mon Sep 17 00:00:00 2001 From: Neil Dorin Date: Thu, 11 Jun 2026 16:55:03 -0600 Subject: [PATCH] feat: implement IAudioCodecPhonebookMessenger for phonebook messaging functionality --- .../Interfaces/IAudioCodecPhonebook.cs | 29 +++++- .../IAudioCodecPhonebookMessenger.cs | 94 +++++++++++++++++++ .../Messengers/IHasDialerMessenger.cs | 1 - 3 files changed, 120 insertions(+), 4 deletions(-) create mode 100644 src/PepperDash.Essentials.MobileControl.Messengers/Messengers/IAudioCodecPhonebookMessenger.cs diff --git a/src/PepperDash.Essentials.Devices.Common/AudioCodec/Interfaces/IAudioCodecPhonebook.cs b/src/PepperDash.Essentials.Devices.Common/AudioCodec/Interfaces/IAudioCodecPhonebook.cs index 31021fbe..253680d7 100644 --- a/src/PepperDash.Essentials.Devices.Common/AudioCodec/Interfaces/IAudioCodecPhonebook.cs +++ b/src/PepperDash.Essentials.Devices.Common/AudioCodec/Interfaces/IAudioCodecPhonebook.cs @@ -1,15 +1,38 @@ - - - +using Newtonsoft.Json; using System.Collections.Generic; using PepperDash.Essentials.Devices.Common.Codec; namespace PepperDash.Essentials.Devices.Common.AudioCodec; +/// +/// Defines the contract for a device that has a phonebook. +/// This is used to provide a common interface for devices that have phonebook functionality +/// public interface IAudioCodecPhonebook : IHasDialer { + /// + /// Sets a phonebook entry at the specified index. The implementation of this method is up to the device, but it should update the phonebook entry at the specified index with the provided name and number. + /// + /// + /// + /// + void SetPhonebookEntry(int index, string name, string number); + /// /// Gets the list of phonebook entries for the device. /// List PhonebookEntries { get; } +} + +/// +/// Defines a phonebook entry for the audio codec phonebook. +/// This is used to provide a common data structure for phonebook entries across different devices. +/// +public class CodecPhonebookEntry +{ + [JsonProperty("name")] + public string Name { get; set; } + + [JsonProperty("number")] + public string Number { get; set; } } \ No newline at end of file diff --git a/src/PepperDash.Essentials.MobileControl.Messengers/Messengers/IAudioCodecPhonebookMessenger.cs b/src/PepperDash.Essentials.MobileControl.Messengers/Messengers/IAudioCodecPhonebookMessenger.cs new file mode 100644 index 00000000..acf5fcff --- /dev/null +++ b/src/PepperDash.Essentials.MobileControl.Messengers/Messengers/IAudioCodecPhonebookMessenger.cs @@ -0,0 +1,94 @@ +using System; +using System.Threading.Tasks; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using PepperDash.Core; +using PepperDash.Core.Logging; +using PepperDash.Essentials.Core; +using PepperDash.Essentials.Devices.Common.AudioCodec; +using System.Collections.Generic; + +namespace PepperDash.Essentials.AppServer.Messengers +{ + /// + /// Provides a messaging bridge for devices implementing + /// + public class IAudioCodecPhonebookMessenger : MessengerBase + { + private readonly IAudioCodecPhonebook _phonebook; + + /// + /// Initializes a new instance of the class. + /// + /// + /// + /// + /// + public IAudioCodecPhonebookMessenger(string key, string messagePath, EssentialsDevice device) + : base(key, messagePath, device) + { + _phonebook = device as IAudioCodecPhonebook ?? throw new ArgumentNullException(nameof(device)); + } + + /// + protected override void RegisterActions() + { + base.RegisterActions(); + + AddAction("/fullStatus", (id, content) => SendFullStatus(id)); + + AddAction("/phonebookStatus", (id, content) => SendFullStatus(id)); + + AddAction("/setEntry", (id, content) => + { + var entry = content.ToObject(); + _phonebook.SetPhonebookEntry(entry.Index, entry.Name, entry.Number); + SendFullStatus(); + }); + } + + private void SendFullStatus(string id = null) + { + try + { + var state = new IAudioCodecPhonebookStateMessage + { + PhonebookEntries = _phonebook.PhonebookEntries + }; + + Task.Run(() => PostStatusMessage(state, id)); + } + catch (Exception ex) + { + this.LogError(ex, "Error sending phonebook full status"); + } + } + } + + /// + /// State message for + /// + public class IAudioCodecPhonebookStateMessage : DeviceStateMessageBase + { + /// + /// Gets or sets the list of phonebook entries + /// + [JsonProperty("phonebookEntries", NullValueHandling = NullValueHandling.Ignore)] + public List PhonebookEntries { get; set; } + } + + /// + /// Content model for the setEntry action + /// + public class SetPhonebookEntryContent + { + [JsonProperty("index")] + public int Index { get; set; } + + [JsonProperty("name")] + public string Name { get; set; } + + [JsonProperty("number")] + public string Number { get; set; } + } +} diff --git a/src/PepperDash.Essentials.MobileControl.Messengers/Messengers/IHasDialerMessenger.cs b/src/PepperDash.Essentials.MobileControl.Messengers/Messengers/IHasDialerMessenger.cs index 143f953e..63a83270 100644 --- a/src/PepperDash.Essentials.MobileControl.Messengers/Messengers/IHasDialerMessenger.cs +++ b/src/PepperDash.Essentials.MobileControl.Messengers/Messengers/IHasDialerMessenger.cs @@ -94,6 +94,5 @@ namespace PepperDash.Essentials.AppServer.Messengers /// [JsonProperty("isInCall", NullValueHandling = NullValueHandling.Ignore)] public bool? IsInCall { get; set; } - } }