cal_core/device/
shared.rs1use std::fmt::{Debug, Formatter};
2use crate::{AsrVendor, NumberFormat, DEFAULT_CALL_TIME, DEFAULT_COUNTRY_CODE, DEFAULT_DIGITS_FINISH_KEY, DEFAULT_DIGIT_TIMEOUT, DEFAULT_ENDPOINT_PRESENT, DEFAULT_MAX_DIGITS, DEFAULT_RECORDING_RETENTION, DEFAULT_REMOTE_DESTINATION, DEFAULT_RING_TIME, DEFAULT_TIMEZONE, DEFAULT_TTS_VOICE, DEFAULT_VM_FINISH_KEY, DEFAULT_VM_MAX_LENGTH, DEFAULT_VM_TIMEOUT, HANG_UP_CONNECT};
3use cal_jambonz::listen::{MixType, SampleRate};
4use cal_jambonz::recognizer::Recognizer;
5use serde::{Deserialize, Serialize};
6use crate::client::ClientProfile;
7
8
9#[derive(Serialize, Deserialize, Clone)]
10pub struct TranscribeOptions {
11 pub enabled: bool,
12 pub language: AsrVendor,
13}
14
15impl Default for TranscribeOptions {
16 fn default() -> Self {
17 Self {
18 enabled: false,
19 language: AsrVendor::Google,
20 }
21 }
22}
23
24#[derive(Serialize, Deserialize, Clone)]
25#[serde(rename_all = "camelCase")]
26pub struct RecordOptions {
27 #[serde(default = "build_record")]
28 pub enabled: bool,
29 #[serde(default = "build_record_retention")]
30 pub retention: String,
31 #[serde(default = "build_mix_type")]
32 pub mix_type: MixType,
33 #[serde(default = "build_sample_rate")]
34 pub sample_rate: SampleRate,
35}
36
37impl Default for RecordOptions {
38 fn default() -> Self {
39 Self {
40 enabled: false,
41 retention: String::from(DEFAULT_RECORDING_RETENTION),
42 mix_type: MixType::Stereo,
43 sample_rate: SampleRate::SR8000,
44 }
45 }
46}
47
48#[derive(Serialize, Deserialize, Clone)]
49pub struct AiOptions {
50 pub transcribe: bool,
51 pub summary: bool,
52 pub recognizer: Option<Recognizer>,
53}
54
55impl Default for AiOptions {
56 fn default() -> Self {
57 Self {
58 transcribe: false,
59 summary: false,
60 recognizer: None,
61 }
62 }
63}
64
65#[derive(Serialize, Deserialize, Clone)]
66pub struct CallControl {
67 enabled: bool,
68 channels: u8,
69 stats: bool,
70 action: CacAction,
71}
72
73impl Default for CallControl {
74 fn default() -> Self {
75 CallControl {
76 enabled: false,
77 channels: 0,
78 stats: false,
79 action: CacAction::Warn,
80 }
81 }
82}
83
84#[derive(Serialize, Deserialize, Clone)]
85#[serde(rename_all = "camelCase")]
86pub enum CacAction {
87 Warn,
88 Deny,
89}
90
91
92impl Debug for AiOptions {
93 fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), std::fmt::Error> {
94 f.debug_struct("AiOptions")
95 .field("transcribe", &self.transcribe)
96 .field("summary", &self.summary)
97 .field("recognizer", &self.recognizer)
98 .finish()
99 }
100}
101
102impl Debug for CallControl {
103 fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), std::fmt::Error> {
104 f.debug_struct("CallControl")
105 .field("enabled", &self.enabled)
106 .field("channels", &self.channels)
107 .field("stats", &self.stats)
108 .field("action", &self.action)
109 .finish()
110 }
111}
112
113impl Debug for CacAction {
114 fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), std::fmt::Error> {
115 match self {
116 CacAction::Warn => write!(f, "Warn"),
117 CacAction::Deny => write!(f, "Deny"),
118 }
119 }
120}
121
122pub fn build_record() -> bool {
123 false
124}
125
126pub fn build_record_retention() -> String {
127 String::from(DEFAULT_RECORDING_RETENTION)
128}
129
130pub fn build_mix_type() -> MixType {
131 MixType::Stereo
132}
133
134pub fn build_sample_rate() -> SampleRate {
135 SampleRate::SR8000
136}
137
138pub fn build_connect_to() -> String {
139 String::from(HANG_UP_CONNECT)
140}
141
142pub fn build_tts_voice() -> String {
143 String::from(DEFAULT_TTS_VOICE)
144}
145
146pub fn build_vm_finish_key() -> String {
147 String::from(DEFAULT_VM_FINISH_KEY)
148}
149
150pub fn build_default_timezone() -> String {
151 String::from(DEFAULT_TIMEZONE)
152}
153
154pub fn build_vm_timeout() -> u8 {
155 DEFAULT_VM_TIMEOUT
156}
157
158pub fn build_vm_max_length() -> u8 {
159 DEFAULT_VM_MAX_LENGTH
160}
161
162
163pub fn build_present() -> String {
164 String::from(DEFAULT_ENDPOINT_PRESENT)
165}
166
167pub fn build_destination() -> String {
168 String::from(DEFAULT_REMOTE_DESTINATION)
169}
170
171pub fn build_format() -> NumberFormat {
172 NumberFormat::National
173}
174
175pub fn build_client_profile() -> ClientProfile {
176 ClientProfile::GenericE164Plus
177}
178
179pub fn build_country_code() -> String {
180 String::from(DEFAULT_COUNTRY_CODE)
181}
182
183pub fn build_finish_key() -> String {
184 String::from(DEFAULT_DIGITS_FINISH_KEY)
185}
186
187pub fn build_call_time() -> u16 {
188 DEFAULT_CALL_TIME
189}
190
191pub fn build_ring_time() -> u8 {
192 DEFAULT_RING_TIME
193}
194
195pub fn build_digit_timeout() -> u8 {
196 DEFAULT_DIGIT_TIMEOUT
197}
198
199pub fn build_max_digits() -> u8 {
200 DEFAULT_MAX_DIGITS
201}