1use cal_jambonz::shared::shared::SIPStatus;
2use crate::core::*;
3use crate::{Account, ConnectState, FlowState, QueueItemType, RecordReference};
4use chrono::{Datelike, Local, NaiveDateTime, NaiveTime};
5use serde::{Deserialize, Serialize};
6
7pub trait Connector {
8 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState;
9}
10
11#[derive(Serialize, Deserialize, Clone)]
12#[serde(untagged)]
13pub enum Device {
14 InboundFlow(InboundFlowStruct),
15 OutboundFlow(OutboundFlowStruct),
16 WhatsAppFlow(WhatsAppFlowStruct),
17 AppFlow(AppFlowStruct),
18 AniRouter(AniRouterStruct),
19 DnisRouter(DnisRouterStruct),
20 DigitRouter(DigitRouterStruct),
21 TimeRangeRouter(TimeRangeRouterStruct),
22 DayOfWeekRouter(DayOfWeekRouterStruct),
23 DateRangeRouter(DateRangeRouterStruct),
24 HuntGroup(HuntGroupStruct),
25 Client(ClientStruct),
26 Teams(TeamsStruct),
27 SipExtension(SipExtensionStruct),
28 SipGateway(SipGatewayStruct),
29 Remote(RemoteStruct),
30 Plugin(PluginStruct),
31 Play(PlayStruct),
32 Say(SayStruct),
33 Voicemail(VoiceMailStruct),
34 Script(ScriptStruct),
35 Queue(QueueStruct),
36 Sms(SmsStruct),
37 Email(EmailStruct),
38 Tag(TagStruct),
39 TagRouter(TagRouterStruct),
40 MessagePlugin(MessagePluginStruct),
41 MessageText(MessageTextStruct),
42 Service(ServiceStruct),
43}
44
45impl Device {
46 pub fn match_device(&self, str: &str) -> bool {
47 let matched = match self {
48 Device::InboundFlow(_) => self.match_inbound_flow(&str),
49 Device::Client(_) => self.match_username(&str),
50 Device::SipGateway(_) => self.match_gateway(&str),
51 _ => false,
52 };
53 matched || self.get_id().eq(&str) || self.get_extension().to_string().eq(&str)
54 }
55
56 pub fn match_inbound_flow(&self, ddi: &str) -> bool {
57 match self {
58 Device::InboundFlow(value) => value.value.ddis.contains(&ddi.to_string()),
59 _ => false,
60 }
61 }
62
63 pub fn match_outbound_flow(&self) -> bool {
64 match self {
65 Device::OutboundFlow(_value) => true,
66 _ => false,
67 }
68 }
69
70 pub fn match_username(&self, username: &str) -> bool {
71 match self {
72 Device::Client(value) => &value.value.username == username,
73 _ => false,
74 }
75 }
76
77 pub fn match_gateway(&self, id: &str) -> bool {
78 match self {
79 Device::SipGateway(value) => value.value.trunks.contains(&id.to_string()),
80 _ => false,
81 }
82 }
83
84 pub fn get_id(&self) -> String {
85 match self {
86 Device::InboundFlow(value) => value.id.clone(),
87 Device::OutboundFlow(value) => value.id.clone(),
88 Device::AppFlow(value) => value.id.clone(),
89 Device::WhatsAppFlow(value) => value.id.clone(),
90 Device::AniRouter(value) => value.id.clone(),
91 Device::DnisRouter(value) => value.id.clone(),
92 Device::DigitRouter(value) => value.id.clone(),
93 Device::TimeRangeRouter(value) => value.id.clone(),
94 Device::DayOfWeekRouter(value) => value.id.clone(),
95 Device::DateRangeRouter(value) => value.id.clone(),
96 Device::HuntGroup(value) => value.id.clone(),
97 Device::Client(value) => value.id.clone(),
98 Device::Teams(value) => value.id.clone(),
99 Device::SipExtension(value) => value.id.clone(),
100 Device::SipGateway(value) => value.id.clone(),
101 Device::Remote(value) => value.id.clone(),
102 Device::Plugin(value) => value.id.clone(),
103 Device::Play(value) => value.id.clone(),
104 Device::Say(value) => value.id.clone(),
105 Device::Voicemail(value) => value.id.clone(),
106 Device::Script(value) => value.id.clone(),
107 Device::Queue(value) => value.id.clone(),
108 Device::Sms(value) => value.id.clone(),
109 Device::Email(value) => value.id.clone(),
110 Device::Tag(value) => value.id.clone(),
111 Device::TagRouter(value) => value.id.clone(),
112 Device::MessagePlugin(value) => value.id.clone(),
113 Device::MessageText(value) => value.id.clone(),
114 Device::Service(value) => value.id.clone(),
115 }
116 }
117
118 pub fn get_extension(&self) -> u16 {
119 match self {
120 Device::InboundFlow(value) => value.extension.clone(),
121 Device::OutboundFlow(value) => value.extension.clone(),
122 Device::AppFlow(value) => value.extension.clone(),
123 Device::WhatsAppFlow(value) => value.extension.clone(),
124 Device::AniRouter(value) => value.extension.clone(),
125 Device::DnisRouter(value) => value.extension.clone(),
126 Device::DigitRouter(value) => value.extension.clone(),
127 Device::TimeRangeRouter(value) => value.extension.clone(),
128 Device::DayOfWeekRouter(value) => value.extension.clone(),
129 Device::DateRangeRouter(value) => value.extension.clone(),
130 Device::HuntGroup(value) => value.extension.clone(),
131 Device::Client(value) => value.extension.clone(),
132 Device::Teams(value) => value.extension.clone(),
133 Device::SipExtension(value) => value.extension.clone(),
134 Device::SipGateway(value) => value.extension.clone(),
135 Device::Remote(value) => value.extension.clone(),
136 Device::Plugin(value) => value.extension.clone(),
137 Device::Play(value) => value.extension.clone(),
138 Device::Say(value) => value.extension.clone(),
139 Device::Voicemail(value) => value.extension.clone(),
140 Device::Script(value) => value.extension.clone(),
141 Device::Queue(value) => value.extension.clone(),
142 Device::Sms(value) => value.extension.clone(),
143 Device::Email(value) => value.extension.clone(),
144 Device::Tag(value) => value.extension.clone(),
145 Device::TagRouter(value) => value.extension.clone(),
146 Device::MessagePlugin(value) => value.extension.clone(),
147 Device::MessageText(value) => value.extension.clone(),
148 Device::Service(value) => value.extension.clone(),
149 }
150 }
151
152 pub fn is_connector(&self) -> bool {
153 match self {
154 Device::InboundFlow(_value) => true,
155 Device::OutboundFlow(_value) => true,
156 Device::AppFlow(_value) => true,
157 Device::WhatsAppFlow(_value) => true,
158 Device::AniRouter(_value) => true,
159 Device::DnisRouter(_value) => true,
160 Device::DigitRouter(_value) => true,
161 Device::TimeRangeRouter(_value) => true,
162 Device::DayOfWeekRouter(_value) => true,
163 Device::DateRangeRouter(_value) => true,
164 Device::Play(_value) => true,
165 Device::Say(_value) => true,
166 Device::Voicemail(_value) => true,
167 Device::Script(_value) => true,
168 Device::Queue(_value) => true,
169 Device::Sms(_value) => true,
170 Device::Email(_value) => true,
171 Device::Tag(_value) => true,
172 Device::TagRouter(_value) => true,
173 Device::Service(_value) => true,
174 Device::HuntGroup(_value) => false,
175 Device::Client(_value) => false,
176 Device::Teams(_value) => false,
177 Device::SipExtension(_value) => false,
178 Device::SipGateway(_value) => false,
179 Device::Remote(_value) => false,
180 Device::Plugin(_value) => false,
181 Device::MessagePlugin(_value) => false,
182 Device::MessageText(_value) => false,
183 }
184 }
185
186 pub fn is_call_handler(&self) -> bool {
187 match self {
188 Device::InboundFlow(_value) => false,
189 Device::OutboundFlow(_value) => false,
190 Device::AppFlow(_value) => false,
191 Device::WhatsAppFlow(_value) => false,
192 Device::AniRouter(_value) => false,
193 Device::DnisRouter(_value) => false,
194 Device::DigitRouter(_value) => false,
195 Device::TimeRangeRouter(_value) => false,
196 Device::DayOfWeekRouter(_value) => false,
197 Device::DateRangeRouter(_value) => false,
198 Device::Play(_value) => false,
199 Device::Say(_value) => false,
200 Device::Voicemail(_value) => false,
201 Device::Script(_value) => false,
202 Device::Queue(_value) => false,
203 Device::Sms(_value) => false,
204 Device::Email(_value) => false,
205 Device::Tag(_value) => false,
206 Device::TagRouter(_value) => false,
207 Device::Service(_value) => false,
208 Device::HuntGroup(_value) => true,
209 Device::Client(_value) => true,
210 Device::Teams(_value) => true,
211 Device::SipExtension(_value) => true,
212 Device::SipGateway(_value) => true,
213 Device::Remote(_value) => true,
214 Device::Plugin(_value) => true,
215 Device::MessagePlugin(_value) => true,
216 Device::MessageText(_value) => true,
217 }
218 }
219
220 pub fn connect_to(&self) -> String {
221 match self {
222 Device::InboundFlow(value) => value.value.connect_to.clone(),
223 Device::OutboundFlow(value) => value.value.connect_to.clone(),
224 Device::AppFlow(value) => value.value.connect_to.clone(),
225 Device::WhatsAppFlow(value) => value.value.connect_to.clone(),
226 Device::AniRouter(value) => value.value.connect_to.clone(),
227 Device::DnisRouter(value) => value.value.connect_to.clone(),
228 Device::DigitRouter(value) => value.value.connect_to.clone(),
229 Device::TimeRangeRouter(value) => value.value.connect_to.clone(),
230 Device::DayOfWeekRouter(value) => value.value.connect_to.clone(),
231 Device::DateRangeRouter(value) => value.value.connect_to.clone(),
232 Device::Play(value) => value.value.connect_to.clone(),
233 Device::Say(value) => value.value.connect_to.clone(),
234 Device::Voicemail(value) => value.value.connect_to.clone(),
235 Device::Script(value) => value.value.connect_to.clone(),
236 Device::Queue(value) => value.value.connect_to.clone(),
237 Device::Sms(value) => value.value.connect_to.clone(),
238 Device::Email(value) => value.value.connect_to.clone(),
239 Device::Tag(value) => value.value.connect_to.clone(),
240 Device::TagRouter(value) => value.value.connect_to.clone(),
241 Device::Service(value) => value.value.connect_to.clone(),
242 _ => String::from(HANG_UP_CONNECT),
243 }
244 }
245
246 pub fn on_busy(&self) -> String {
247 match self {
248 Device::Plugin(value) => value.value.on_busy.clone(),
249 Device::HuntGroup(value) => value.value.on_busy.clone(),
250 Device::Client(value) => value.value.on_busy.clone(),
251 Device::Teams(value) => value.value.on_busy.clone(),
252 Device::SipExtension(value) => value.value.on_busy.clone(),
253 Device::SipGateway(value) => value.value.on_busy.clone(),
254 Device::Remote(value) => value.value.on_busy.clone(),
255 _ => String::from(HANG_UP_CONNECT),
256 }
257 }
258
259 pub fn on_complete(&self) -> String {
260 match self {
261 Device::Plugin(value) => value.value.on_complete.clone(),
262 Device::HuntGroup(value) => value.value.on_complete.clone(),
263 Device::Client(value) => value.value.on_complete.clone(),
264 Device::Teams(value) => value.value.on_complete.clone(),
265 Device::SipExtension(value) => value.value.on_complete.clone(),
266 Device::SipGateway(value) => value.value.on_complete.clone(),
267 Device::Remote(value) => value.value.on_complete.clone(),
268 _ => String::from(HANG_UP_CONNECT),
269 }
270 }
271
272 pub fn on_no_answer(&self) -> String {
273 match self {
274 Device::Plugin(value) => value.value.on_no_answer.clone(),
275 Device::HuntGroup(value) => value.value.on_no_answer.clone(),
276 Device::Client(value) => value.value.on_no_answer.clone(),
277 Device::Teams(value) => value.value.on_no_answer.clone(),
278 Device::SipExtension(value) => value.value.on_no_answer.clone(),
279 Device::SipGateway(value) => value.value.on_no_answer.clone(),
280 Device::Remote(value) => value.value.on_no_answer.clone(),
281 _ => String::from(HANG_UP_CONNECT),
282 }
283 }
284
285 pub fn on_fail(&self) -> String {
286 match self {
287 Device::Plugin(value) => value.value.on_fail.clone(),
288 Device::HuntGroup(value) => value.value.on_fail.clone(),
289 Device::Client(value) => value.value.on_fail.clone(),
290 Device::Teams(value) => value.value.on_fail.clone(),
291 Device::SipExtension(value) => value.value.on_fail.clone(),
292 Device::SipGateway(value) => value.value.on_fail.clone(),
293 Device::Remote(value) => value.value.on_fail.clone(),
294 _ => String::from(HANG_UP_CONNECT),
295 }
296 }
297
298 pub fn on_transfer(&self) -> String {
299 match self {
300 Device::Plugin(value) => value.value.on_transfer.clone(),
301 _ => String::from(HANG_UP_CONNECT),
302 }
303 }
304
305 pub fn on_error(&self) -> String {
306 match self {
307 Device::Plugin(value) => value.value.on_error.clone(),
308 _ => String::from(HANG_UP_CONNECT),
309 }
310 }
311
312 pub fn connect<'a>(&'a self, account: &'a Account) -> Option<Device> {
313 if account.devices.len() == 0 {
314 return None;
315 }
316 let con: String = String::from(self.connect_to());
317 if con.eq(HANG_UP_CONNECT) {
318 return None;
319 }
320 account
321 .devices
322 .iter()
323 .find(|d| d.get_id().eq(&con))
324 .map(|d| d.clone())
325 }
326}
327
328#[derive(Serialize, Deserialize, Clone)]
329pub struct InboundFlowStruct {
330 pub id: String,
331 pub name: String,
332 pub extension: u16,
333 #[serde(default)]
334 pub tags: Vec<DeviceTag>,
335 #[serde(rename = "startRoute")]
336 pub value: InboundFlow,
337}
338
339impl Connector for InboundFlowStruct {
340 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
341 self.value.clone().get_connect_to(state)
342 }
343}
344
345#[derive(Serialize, Deserialize, Clone)]
346pub struct OutboundFlowStruct {
347 pub id: String,
348 pub name: String,
349 pub extension: u16,
350 #[serde(default)]
351 pub tags: Vec<DeviceTag>,
352 #[serde(rename = "regexRoute")]
353 pub value: OutboundFlow,
354}
355
356impl Connector for OutboundFlowStruct {
357 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
358 self.value.clone().get_connect_to(state)
359 }
360}
361
362#[derive(Serialize, Deserialize, Clone)]
363pub struct WhatsAppFlowStruct {
364 pub id: String,
365 pub name: String,
366 pub extension: u16,
367 #[serde(default)]
368 pub tags: Vec<DeviceTag>,
369 #[serde(rename = "whatsAppRoute")]
370 pub value: WhatsAppFlow,
371}
372
373impl Connector for WhatsAppFlowStruct {
374 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
375 self.value.clone().get_connect_to(state)
376 }
377}
378
379#[derive(Serialize, Deserialize, Clone)]
380pub struct AppFlowStruct {
381 pub id: String,
382 pub name: String,
383 pub extension: u16,
384 #[serde(default)]
385 pub tags: Vec<DeviceTag>,
386 #[serde(rename = "appRoute")]
387 pub value: AppFlow,
388}
389
390impl Connector for AppFlowStruct {
391 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
392 self.value.clone().get_connect_to(state)
393 }
394}
395
396#[derive(Serialize, Deserialize, Clone)]
397pub struct AniRouterStruct {
398 pub id: String,
399 pub name: String,
400 pub extension: u16,
401 #[serde(default)]
402 pub tags: Vec<DeviceTag>,
403 #[serde(rename = "aniRouter")]
404 pub value: ANIRouter,
405}
406
407impl Connector for AniRouterStruct {
408 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
409 self.value.clone().get_connect_to(state)
410 }
411}
412
413#[derive(Serialize, Deserialize, Clone)]
414pub struct DnisRouterStruct {
415 pub id: String,
416 pub name: String,
417 pub extension: u16,
418 #[serde(default)]
419 pub tags: Vec<DeviceTag>,
420 #[serde(rename = "dnisRouter")]
421 pub value: ANIRouter,
422}
423
424impl Connector for DnisRouterStruct {
425 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
426 self.value.clone().get_connect_to(state)
427 }
428}
429
430#[derive(Serialize, Deserialize, Clone)]
431pub struct DigitRouterStruct {
432 pub id: String,
433 pub name: String,
434 pub extension: u16,
435 #[serde(default)]
436 pub tags: Vec<DeviceTag>,
437 #[serde(rename = "numberPlan")]
438 pub value: DigitRouter,
439}
440
441impl Connector for DigitRouterStruct {
442 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
443 self.value.clone().get_connect_to(state)
444 }
445}
446
447#[derive(Serialize, Deserialize, Clone)]
448pub struct TimeRangeRouterStruct {
449 pub id: String,
450 pub name: String,
451 pub extension: u16,
452 #[serde(default)]
453 pub tags: Vec<DeviceTag>,
454 #[serde(rename = "timeRangeRoute")]
455 pub value: TimeRangeRouter,
456}
457
458impl Connector for TimeRangeRouterStruct {
459 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
460 self.value.clone().get_connect_to(state)
461 }
462}
463
464#[derive(Serialize, Deserialize, Clone)]
465pub struct DayOfWeekRouterStruct {
466 pub id: String,
467 pub name: String,
468 pub extension: u16,
469 #[serde(default)]
470 pub tags: Vec<DeviceTag>,
471 #[serde(rename = "dayOfWeekRoute")]
472 pub value: DayOfWeekRouter,
473}
474
475impl Connector for DayOfWeekRouterStruct {
476 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
477 self.value.clone().get_connect_to(state)
478 }
479}
480
481#[derive(Serialize, Deserialize, Clone)]
482pub struct DateRangeRouterStruct {
483 pub id: String,
484 pub name: String,
485 pub extension: u16,
486 #[serde(default)]
487 pub tags: Vec<DeviceTag>,
488 #[serde(rename = "dateRangeRoute")]
489 pub value: DateRangeRouter,
490}
491
492impl Connector for DateRangeRouterStruct {
493 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
494 self.value.clone().get_connect_to(state)
495 }
496}
497
498#[derive(Serialize, Deserialize, Clone)]
499pub struct HuntGroupStruct {
500 pub id: String,
501 pub name: String,
502 pub extension: u16,
503 #[serde(default)]
504 pub tags: Vec<DeviceTag>,
505 #[serde(rename = "huntGroup")]
506 pub value: HuntGroup,
507}
508
509impl Connector for HuntGroupStruct {
510 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
511 self.value.clone().get_connect_to(state)
512 }
513}
514
515#[derive(Serialize, Deserialize, Clone)]
516pub struct ClientStruct {
517 pub id: String,
518 pub name: String,
519 pub extension: u16,
520 #[serde(default)]
521 pub tags: Vec<DeviceTag>,
522 #[serde(rename = "client")]
523 pub value: Client,
524}
525
526impl Connector for ClientStruct {
527 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
528 self.value.clone().get_connect_to(state)
529 }
530}
531
532#[derive(Serialize, Deserialize, Clone)]
533pub struct TeamsStruct {
534 pub id: String,
535 pub name: String,
536 pub extension: u16,
537 #[serde(default)]
538 pub tags: Vec<DeviceTag>,
539 #[serde(rename = "teams")]
540 pub value: Teams,
541}
542
543impl Connector for TeamsStruct {
544 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
545 self.value.clone().get_connect_to(state)
546 }
547}
548
549#[derive(Serialize, Deserialize, Clone)]
550pub struct SipExtensionStruct {
551 pub id: String,
552 pub name: String,
553 pub extension: u16,
554 #[serde(default)]
555 pub tags: Vec<DeviceTag>,
556 #[serde(rename = "sipExtension")]
557 pub value: SipExtension,
558}
559
560impl Connector for SipExtensionStruct {
561 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
562 self.value.clone().get_connect_to(state)
563 }
564}
565
566#[derive(Serialize, Deserialize, Clone)]
567pub struct SipGatewayStruct {
568 pub id: String,
569 pub name: String,
570 pub extension: u16,
571 #[serde(default)]
572 pub tags: Vec<DeviceTag>,
573 #[serde(rename = "sipGateway")]
574 pub value: SipGateway,
575}
576
577impl Connector for SipGatewayStruct {
578 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
579 self.value.clone().get_connect_to(state)
580 }
581}
582
583#[derive(Serialize, Deserialize, Clone)]
584pub struct RemoteStruct {
585 pub id: String,
586 pub name: String,
587 pub extension: u16,
588 #[serde(default)]
589 pub tags: Vec<DeviceTag>,
590 #[serde(rename = "remote")]
591 pub value: Remote,
592}
593
594impl Connector for RemoteStruct {
595 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
596 self.value.clone().get_connect_to(state)
597 }
598}
599
600#[derive(Serialize, Deserialize, Clone)]
601pub struct PluginStruct {
602 pub id: String,
603 pub name: String,
604 pub extension: u16,
605 #[serde(default)]
606 pub tags: Vec<DeviceTag>,
607 #[serde(rename = "plugin")]
608 pub value: Plugin,
609}
610
611impl Connector for PluginStruct {
612 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
613 self.value.clone().get_connect_to(state)
614 }
615}
616
617#[derive(Serialize, Deserialize, Clone)]
618pub struct PlayStruct {
619 pub id: String,
620 pub name: String,
621 pub extension: u16,
622 #[serde(default)]
623 pub tags: Vec<DeviceTag>,
624 #[serde(rename = "play")]
625 pub value: Play,
626}
627
628impl Connector for PlayStruct {
629 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
630 self.value.clone().get_connect_to(state)
631 }
632}
633
634#[derive(Serialize, Deserialize, Clone)]
635pub struct SayStruct {
636 pub id: String,
637 pub name: String,
638 pub extension: u16,
639 #[serde(default)]
640 pub tags: Vec<DeviceTag>,
641 #[serde(rename = "say")]
642 pub value: Say,
643}
644
645impl Connector for SayStruct {
646 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
647 self.value.clone().get_connect_to(state)
648 }
649}
650
651#[derive(Serialize, Deserialize, Clone)]
652pub struct VoiceMailStruct {
653 pub id: String,
654 pub name: String,
655 pub extension: u16,
656 #[serde(default)]
657 pub tags: Vec<DeviceTag>,
658 #[serde(rename = "voicemail")]
659 pub value: VoiceMail,
660}
661
662impl Connector for VoiceMailStruct {
663 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
664 self.value.clone().get_connect_to(state)
665 }
666}
667
668#[derive(Serialize, Deserialize, Clone)]
669pub struct ScriptStruct {
670 pub id: String,
671 pub name: String,
672 pub extension: u16,
673 #[serde(default)]
674 pub tags: Vec<DeviceTag>,
675 #[serde(rename = "script")]
676 pub value: Script,
677}
678
679impl Connector for ScriptStruct {
680 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
681 self.value.clone().get_connect_to(state)
682 }
683}
684
685#[derive(Serialize, Deserialize, Clone)]
686pub struct QueueStruct {
687 pub id: String,
688 pub name: String,
689 pub extension: u16,
690 #[serde(default)]
691 pub tags: Vec<DeviceTag>,
692 #[serde(rename = "queue")]
693 pub value: Queue,
694}
695
696impl Connector for QueueStruct {
697 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
698 self.value.clone().get_connect_to(state)
699 }
700}
701
702#[derive(Serialize, Deserialize, Clone)]
703pub struct SmsStruct {
704 pub id: String,
705 pub name: String,
706 pub extension: u16,
707 #[serde(default)]
708 pub tags: Vec<DeviceTag>,
709 #[serde(rename = "sms")]
710 pub value: Sms,
711}
712
713impl Connector for SmsStruct {
714 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
715 self.value.clone().get_connect_to(state)
716 }
717}
718
719#[derive(Serialize, Deserialize, Clone)]
720pub struct EmailStruct {
721 pub id: String,
722 pub name: String,
723 pub extension: u16,
724 #[serde(default)]
725 pub tags: Vec<DeviceTag>,
726 #[serde(rename = "email")]
727 pub value: Email,
728}
729
730impl Connector for EmailStruct {
731 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
732 self.value.clone().get_connect_to(state)
733 }
734}
735
736#[derive(Serialize, Deserialize, Clone)]
737pub struct TagStruct {
738 pub id: String,
739 pub name: String,
740 pub extension: u16,
741 #[serde(default)]
742 pub tags: Vec<DeviceTag>,
743 #[serde(rename = "tag")]
744 pub value: Tag,
745}
746
747impl Connector for TagStruct {
748 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
749 self.value.clone().get_connect_to(state)
750 }
751}
752
753#[derive(Serialize, Deserialize, Clone)]
754pub struct TagRouterStruct {
755 pub id: String,
756 pub name: String,
757 pub extension: u16,
758 #[serde(default)]
759 pub tags: Vec<DeviceTag>,
760 #[serde(rename = "tagRouter")]
761 pub value: TagRouter,
762}
763
764impl Connector for TagRouterStruct {
765 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
766 self.value.clone().get_connect_to(state)
767 }
768}
769
770#[derive(Serialize, Deserialize, Clone)]
771pub struct MessagePluginStruct {
772 pub id: String,
773 pub name: String,
774 pub extension: u16,
775 #[serde(default)]
776 pub tags: Vec<DeviceTag>,
777 #[serde(rename = "messagePlugin")]
778 pub value: MessagePlugin,
779}
780
781impl Connector for MessagePluginStruct {
782 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
783 self.value.clone().get_connect_to(state)
784 }
785}
786
787#[derive(Serialize, Deserialize, Clone)]
788#[serde(rename_all = "camelCase")]
789pub struct MessageTextStruct {
790 pub id: String,
791 pub name: String,
792 pub extension: u16,
793 #[serde(default)]
794 pub tags: Vec<DeviceTag>,
795 #[serde(rename = "messageText")]
796 pub value: MessageText,
797}
798
799impl Connector for MessageTextStruct {
800 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
801 self.value.clone().get_connect_to(state)
802 }
803}
804#[derive(Serialize, Deserialize, Clone)]
805#[serde(rename_all = "camelCase")]
806pub struct ServiceStruct {
807 pub id: String,
808 pub name: String,
809 pub extension: u16,
810 #[serde(default)]
811 pub tags: Vec<DeviceTag>,
812 #[serde(rename = "service")]
813 pub value: Service,
814 #[serde(default = "build_connect_to")]
815 pub connect_to: String,
816}
817
818impl Connector for ServiceStruct {
819 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
820 self.value.clone().get_connect_to(state)
821 }
822}
823
824#[derive(Serialize, Deserialize, Clone)]
825#[serde(rename_all = "camelCase")]
826pub struct DeviceTag {
827 #[serde(rename = "type")]
828 pub tag_type: String,
829 pub name: String,
830 pub value: String,
831}
832
833#[derive(Serialize, Deserialize, Clone)]
834#[serde(rename_all = "camelCase")]
835pub struct InboundFlow {
836 #[serde(default)]
837 pub ddis: Vec<String>,
838 #[serde(default = "build_connect_to")]
839 pub connect_to: String,
840}
841
842impl Connector for InboundFlow {
843 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
844 let connect_state = ConnectState::default(&self.connect_to, None);
845 state.add_state(connect_state);
846 state.clone()
847 }
848}
849
850#[derive(Serialize, Deserialize, Clone)]
851#[serde(rename_all = "camelCase")]
852pub struct OutboundFlow {
853 pub reg_exp: String,
854 #[serde(default = "build_connect_to")]
855 pub connect_to: String,
856}
857
858impl Connector for OutboundFlow {
859 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
860 let connect_state = ConnectState::default(&self.connect_to, None);
861 state.add_state(connect_state);
862 state.clone()
863 }
864}
865
866#[derive(Serialize, Deserialize, Clone)]
867#[serde(rename_all = "camelCase")]
868pub struct WhatsAppFlow {
869 #[serde(default)]
870 pub ddis: Vec<String>,
871 #[serde(default = "build_connect_to")]
872 pub connect_to: String,
873}
874
875impl Connector for WhatsAppFlow {
876 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
877 let connect_state = ConnectState::default(&self.connect_to, None);
878 state.add_state(connect_state);
879 state.clone()
880 }
881}
882
883#[derive(Serialize, Deserialize, Clone)]
884#[serde(rename_all = "camelCase")]
885pub struct AppFlow {
886 #[serde(default = "build_connect_to")]
887 pub connect_to: String,
888}
889
890impl Connector for AppFlow {
891 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
892 let connect_state = ConnectState::default(&self.connect_to, None);
893 state.add_state(connect_state);
894 state.clone()
895 }
896}
897
898#[derive(Serialize, Deserialize, Clone)]
899#[serde(rename_all = "camelCase")]
900pub struct ANIRouter {
901 #[serde(default)]
902 pub options: Vec<RouterOption>,
903 #[serde(default = "build_connect_to")]
904 pub connect_to: String,
905}
906
907impl ANIRouter {
908 fn get_opts(&mut self) -> Vec<RouterOption> {
909 let opts = &mut self.options.clone();
910 opts.sort_by_key(|o| o.option.chars().count());
911 opts.reverse();
912 opts.clone()
913 }
914}
915impl Connector for ANIRouter {
916 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
917 let str = state.get_paid_or_from();
918 let connect_state = self
919 .get_opts()
920 .iter()
921 .find(|o| o.option.starts_with(str.as_str()))
922 .map(|o| {
923 ConnectState::matched(
924 o.connect_to.as_str(),
925 Some(str.to_string()),
926 Some(o.option.clone()),
927 )
928 })
929 .unwrap_or_else(|| {
930 ConnectState::default(self.connect_to.as_str(), Some(str.to_string()))
931 });
932 state.add_state(connect_state);
933 state.clone()
934 }
935}
936
937#[derive(Serialize, Deserialize, Clone)]
938#[serde(rename_all = "camelCase")]
939pub struct DNISRouter {
940 #[serde(default)]
941 pub options: Vec<RouterOption>,
942 #[serde(default = "build_connect_to")]
943 pub connect_to: String,
944}
945
946impl DNISRouter {
947 fn get_opts(&mut self) -> Vec<RouterOption> {
948 let opts = &mut self.options.clone();
949 opts.sort_by_key(|o| o.option.chars().count());
950 opts.reverse();
951 opts.clone()
952 }
953}
954impl Connector for DNISRouter {
955 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
956 let str = state.get_to();
957 let connect_state = self
958 .get_opts()
959 .iter()
960 .find(|o| o.option.starts_with(str.as_str()))
961 .map(|o| {
962 ConnectState::matched(
963 o.connect_to.as_str(),
964 Some(str.to_string()),
965 Some(o.option.clone()),
966 )
967 })
968 .unwrap_or_else(|| {
969 ConnectState::default(self.connect_to.as_str(), Some(str.to_string()))
970 });
971 state.add_state(connect_state);
972 state.clone()
973 }
974}
975
976#[derive(Serialize, Deserialize, Clone)]
977#[serde(rename_all = "camelCase")]
978pub struct DigitRouter {
979 pub text: String,
980 #[serde(rename = "ttsLanguage")]
981 #[serde(default = "build_tts_voice")]
982 pub tts_voice: String,
983 #[serde(default = "build_finish_key")]
984 pub finish_on_key: String,
985 #[serde(default = "build_connect_to")]
986 pub connect_to: String,
987 #[serde(default)]
988 pub options: Vec<RouterOption>,
989 #[serde(default = "build_digit_timeout")]
990 pub timeout: u8,
991 #[serde(default = "build_max_digits")]
992 pub max_digits: u8,
993}
994
995impl DigitRouter {
996 fn get_opts(&mut self) -> Vec<RouterOption> {
997 let opts = &mut self.options.clone();
998 opts.sort_by_key(|o| o.option.chars().count());
999 opts.reverse();
1000 opts.clone()
1001 }
1002}
1003impl Connector for DigitRouter {
1004 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
1005 match &state.get_digits() {
1006 Some(d) => {
1007 let connect_state = self
1008 .get_opts()
1009 .iter()
1010 .find(|o| o.option.eq(d.as_str()))
1011 .map(|o| {
1012 ConnectState::matched(
1013 &o.connect_to.to_string(),
1014 Some(d.to_string()),
1015 Some(o.option.clone()),
1016 )
1017 })
1018 .unwrap_or_else(|| {
1019 ConnectState::default(&self.connect_to.to_string(), Some(d.to_string()))
1020 });
1021 state.add_state(connect_state);
1022 state.clone()
1023 }
1024 None => {
1025 state.device = None;
1026 state.clone()
1027 }
1028 }
1029 }
1030}
1031
1032#[derive(Serialize, Deserialize, Clone)]
1033#[serde(rename_all = "camelCase")]
1034pub struct HuntGroup {
1035 #[serde(default = "build_present")]
1036 pub present: String,
1037 #[serde(default = "build_country_code")]
1038 pub country_code: String,
1039 #[serde(default = "build_connect_to")]
1040 pub on_complete: String,
1041 #[serde(default = "build_connect_to")]
1042 pub on_busy: String,
1043 #[serde(default = "build_connect_to")]
1044 pub on_fail: String,
1045 #[serde(default = "build_connect_to")]
1046 pub on_no_answer: String,
1047 #[serde(default = "build_ring_time")]
1048 pub ring_time: u8,
1049 #[serde(default = "build_call_time")]
1050 pub max_call_time: u16,
1051 #[serde(default)]
1052 pub transcribe_options: TranscribeOptions,
1053 #[serde(default)]
1054 pub record_options: RecordOptions,
1055 #[serde(default)]
1056 pub devices: Vec<String>,
1057}
1058
1059impl Connector for HuntGroup {
1060 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
1061 match &state.get_dial_status() {
1062 Some(status) => {
1063 let complete_state = match status {
1064 SIPStatus::Ok => ConnectState::complete(self.on_complete.as_str()),
1065 SIPStatus::RequestTerminated => {
1066 ConnectState::no_answer(self.on_no_answer.as_str())
1067 }
1068 SIPStatus::BusyHere | SIPStatus::BusyEverywhere => {
1069 ConnectState::busy(self.on_busy.as_str())
1070 }
1071 (st) => ConnectState::fail(self.on_fail.as_str()),
1072 };
1073 state.add_state(complete_state);
1074 state.clone()
1075 }
1076 None => {
1077 state.add_state(ConnectState::dialling());
1078 state.clone()
1079 }
1080 }
1081 }
1082}
1083#[derive(Serialize, Deserialize, Clone)]
1084#[serde(rename_all = "camelCase")]
1085pub struct Client {
1086 pub username: String,
1087 pub password: String,
1088 #[serde(default = "build_client_profile")]
1089 pub profile: String,
1090 pub user: Option<RecordReference>,
1091 #[serde(default = "build_format")]
1092 pub format: String,
1093 #[serde(default = "build_present")]
1094 pub present: String,
1095 #[serde(default = "build_country_code")]
1096 pub country_code: String,
1097 #[serde(default = "build_connect_to")]
1098 pub on_complete: String,
1099 #[serde(default = "build_connect_to")]
1100 pub on_busy: String,
1101 #[serde(default = "build_connect_to")]
1102 pub on_fail: String,
1103 #[serde(default = "build_connect_to")]
1104 pub on_no_answer: String,
1105 #[serde(default = "build_ring_time")]
1106 pub ring_time: u8,
1107 #[serde(default = "build_call_time")]
1108 pub max_call_time: u16,
1109 #[serde(default)]
1110 pub transcribe_options: TranscribeOptions,
1111 #[serde(default)]
1112 pub record_options: RecordOptions,
1113}
1114
1115impl Connector for Client {
1116 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
1117 match &state.get_dial_status() {
1118 Some(status) => {
1119 let complete_state = match status {
1120 SIPStatus::Ok => ConnectState::complete(self.on_complete.as_str()),
1121 SIPStatus::RequestTerminated => {
1122 ConnectState::no_answer(self.on_no_answer.as_str())
1123 }
1124 SIPStatus::BusyHere | SIPStatus::BusyEverywhere => {
1125 ConnectState::busy(self.on_busy.as_str())
1126 }
1127 (st) => ConnectState::fail(self.on_fail.as_str()),
1128 };
1129 state.add_state(complete_state);
1130 state.clone()
1131 }
1132 None => {
1133 state.add_state(ConnectState::dialling());
1134 state.clone()
1135 }
1136 }
1137 }
1138}
1139
1140#[derive(Serialize, Deserialize, Clone)]
1141#[serde(rename_all = "camelCase")]
1142pub struct Teams {
1143 pub to: String,
1144 #[serde(default = "build_present")]
1145 pub present: String,
1146 #[serde(default = "build_country_code")]
1147 pub country_code: String,
1148 #[serde(default = "build_connect_to")]
1149 pub on_complete: String,
1150 #[serde(default = "build_connect_to")]
1151 pub on_busy: String,
1152 #[serde(default = "build_connect_to")]
1153 pub on_fail: String,
1154 #[serde(default = "build_connect_to")]
1155 pub on_no_answer: String,
1156 #[serde(default = "build_ring_time")]
1157 pub ring_time: u8,
1158 #[serde(default = "build_call_time")]
1159 pub max_call_time: u16,
1160 #[serde(default)]
1161 pub transcribe_options: TranscribeOptions,
1162 #[serde(default)]
1163 pub record_options: RecordOptions,
1164}
1165
1166impl Connector for Teams {
1167 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
1168 match &state.get_dial_status() {
1169 Some(status) => {
1170 let complete_state = match status {
1171 SIPStatus::Ok => ConnectState::complete(self.on_complete.as_str()),
1172 SIPStatus::RequestTerminated => {
1173 ConnectState::no_answer(self.on_no_answer.as_str())
1174 }
1175 SIPStatus::BusyHere | SIPStatus::BusyEverywhere => {
1176 ConnectState::busy(self.on_busy.as_str())
1177 }
1178 (st) => ConnectState::fail(self.on_fail.as_str()),
1179 };
1180 state.add_state(complete_state);
1181 state.clone()
1182 }
1183 None => {
1184 state.add_state(ConnectState::dialling());
1185 state.clone()
1186 }
1187 }
1188 }
1189}
1190#[derive(Serialize, Deserialize, Clone)]
1191#[serde(rename_all = "camelCase")]
1192pub struct SipExtension {
1193 pub gateway: String,
1194 #[serde(default = "build_present")]
1195 pub present: String,
1196 #[serde(default = "build_country_code")]
1197 pub country_code: String,
1198 #[serde(default = "build_connect_to")]
1199 pub on_complete: String,
1200 #[serde(default = "build_connect_to")]
1201 pub on_busy: String,
1202 #[serde(default = "build_connect_to")]
1203 pub on_fail: String,
1204 #[serde(default = "build_connect_to")]
1205 pub on_no_answer: String,
1206 #[serde(default = "build_ring_time")]
1207 pub ring_time: u8,
1208 #[serde(default = "build_call_time")]
1209 pub max_call_time: u16,
1210 #[serde(default)]
1211 pub transcribe_options: TranscribeOptions,
1212 #[serde(default)]
1213 pub record_options: RecordOptions,
1214}
1215
1216impl Connector for SipExtension {
1217 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
1218 match &state.get_dial_status() {
1219 Some(status) => {
1220 let complete_state = match status {
1221 SIPStatus::Ok => ConnectState::complete(self.on_complete.as_str()),
1222 SIPStatus::RequestTerminated => {
1223 ConnectState::no_answer(self.on_no_answer.as_str())
1224 }
1225 SIPStatus::BusyHere | SIPStatus::BusyEverywhere => {
1226 ConnectState::busy(self.on_busy.as_str())
1227 }
1228 (st) => ConnectState::fail(self.on_fail.as_str()),
1229 };
1230 state.add_state(complete_state);
1231 state.clone()
1232 }
1233 None => {
1234 state.add_state(ConnectState::dialling());
1235 state.clone()
1236 }
1237 }
1238 }
1239}
1240
1241#[derive(Serialize, Deserialize, Clone)]
1242#[serde(rename_all = "camelCase")]
1243pub struct SipGateway {
1244 #[serde(default = "build_format")]
1245 pub format: String,
1246 #[serde(default)]
1247 pub trunks: Vec<String>,
1248 #[serde(default)]
1249 pub proxies: Vec<String>,
1250 #[serde(default = "build_present")]
1251 pub present: String,
1252 #[serde(default = "build_country_code")]
1253 pub country_code: String,
1254 #[serde(default = "build_connect_to")]
1255 pub on_complete: String,
1256 #[serde(default = "build_connect_to")]
1257 pub on_busy: String,
1258 #[serde(default = "build_connect_to")]
1259 pub on_fail: String,
1260 #[serde(default = "build_connect_to")]
1261 pub on_no_answer: String,
1262 #[serde(default = "build_ring_time")]
1263 pub ring_time: u8,
1264 #[serde(default = "build_call_time")]
1265 pub max_call_time: u16,
1266 #[serde(default)]
1267 pub transcribe_options: TranscribeOptions,
1268 #[serde(default)]
1269 pub record_options: RecordOptions,
1270}
1271
1272impl Connector for SipGateway {
1273 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
1274 match &state.get_dial_status() {
1275 Some(status) => {
1276 let complete_state = match status {
1277 SIPStatus::Ok => ConnectState::complete(self.on_complete.as_str()),
1278 SIPStatus::RequestTerminated => {
1279 ConnectState::no_answer(self.on_no_answer.as_str())
1280 }
1281 SIPStatus::BusyHere | SIPStatus::BusyEverywhere => {
1282 ConnectState::busy(self.on_busy.as_str())
1283 }
1284 (st) => ConnectState::fail(self.on_fail.as_str()),
1285 };
1286 state.add_state(complete_state);
1287 state.clone()
1288 }
1289 None => {
1290 state.add_state(ConnectState::dialling());
1291 state.clone()
1292 }
1293 }
1294 }
1295}
1296
1297#[derive(Serialize, Deserialize, Clone)]
1298#[serde(rename_all = "camelCase")]
1299pub struct Remote {
1300 pub destination: String,
1301 #[serde(default)]
1302 pub proxies: Option<Vec<String>>,
1303 #[serde(default = "build_present")]
1304 pub present: String,
1305 #[serde(default = "build_country_code")]
1306 pub country_code: String,
1307 #[serde(default = "build_connect_to")]
1308 pub on_complete: String,
1309 #[serde(default = "build_connect_to")]
1310 pub on_busy: String,
1311 #[serde(default = "build_connect_to")]
1312 pub on_fail: String,
1313 #[serde(default = "build_connect_to")]
1314 pub on_no_answer: String,
1315 #[serde(default = "build_ring_time")]
1316 pub ring_time: u8,
1317 #[serde(default = "build_call_time")]
1318 pub max_call_time: u16,
1319 #[serde(default)]
1320 pub transcribe_options: TranscribeOptions,
1321 #[serde(default)]
1322 pub record_options: RecordOptions,
1323}
1324
1325impl Connector for Remote {
1326 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
1327 match &state.get_dial_status() {
1328 Some(status) => {
1329 let complete_state = match status {
1330 SIPStatus::Ok => ConnectState::complete(self.on_complete.as_str()),
1331 SIPStatus::RequestTerminated => {
1332 ConnectState::no_answer(self.on_no_answer.as_str())
1333 }
1334 SIPStatus::BusyHere | SIPStatus::BusyEverywhere => {
1335 ConnectState::busy(self.on_busy.as_str())
1336 }
1337 (st) => ConnectState::fail(self.on_fail.as_str()),
1338 };
1339 state.add_state(complete_state);
1340 state.clone()
1341 }
1342 None => {
1343 state.add_state(ConnectState::dialling());
1344 state.clone()
1345 }
1346 }
1347 }
1348}
1349
1350#[derive(Serialize, Deserialize, Clone)]
1351#[serde(rename_all = "camelCase")]
1352pub struct Plugin {
1353 pub plugin: String,
1355 pub data: String,
1356 #[serde(default = "build_present")]
1357 pub present: String,
1358 #[serde(default = "build_country_code")]
1359 pub country_code: String,
1360 #[serde(default = "build_ring_time")]
1361 pub ring_time: u8,
1362 #[serde(default = "build_call_time")]
1363 pub max_call_time: u16,
1364 #[serde(default)]
1365 pub record_options: RecordOptions,
1366 #[serde(default)]
1367 pub transcribe_options: TranscribeOptions,
1368 #[serde(default = "build_connect_to")]
1369 pub on_transfer: String,
1370 #[serde(default = "build_connect_to")]
1371 pub on_error: String,
1372 #[serde(default = "build_connect_to")]
1373 pub on_complete: String,
1374 #[serde(default = "build_connect_to")]
1375 pub on_busy: String,
1376 #[serde(default = "build_connect_to")]
1377 pub on_fail: String,
1378 #[serde(default = "build_connect_to")]
1379 pub on_no_answer: String,
1380}
1381
1382impl Connector for Plugin {
1383 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
1384 match &state.get_dial_status() {
1385 Some(status) => {
1386 let complete_state = match status {
1387 SIPStatus::Ok => ConnectState::complete(self.on_complete.as_str()),
1388 SIPStatus::RequestTerminated => {
1389 ConnectState::no_answer(self.on_no_answer.as_str())
1390 }
1391 SIPStatus::BusyHere | SIPStatus::BusyEverywhere => {
1392 ConnectState::busy(self.on_busy.as_str())
1393 }
1394 st => ConnectState::fail(self.on_fail.as_str()),
1395 };
1396 state.add_state(complete_state);
1397 state.clone()
1398 }
1399 None => {
1400 state.add_state(ConnectState::dialling());
1401 state.clone()
1402 }
1403 }
1404 }
1405}
1406
1407#[derive(Serialize, Deserialize, Clone)]
1408#[serde(rename_all = "camelCase")]
1409pub struct Play {
1410 pub url: String,
1411 pub connect_to: String,
1412}
1413
1414impl Connector for Play {
1415 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
1416 let connect_state = ConnectState::default(&self.connect_to, None);
1417 state.add_state(connect_state);
1418 state.clone()
1419 }
1420}
1421
1422#[derive(Serialize, Deserialize, Clone)]
1423#[serde(rename_all = "camelCase")]
1424pub struct Say {
1425 pub text: String,
1426 #[serde(rename = "ttsLanguage")]
1427 #[serde(default = "build_tts_voice")]
1428 pub tts_voice: String,
1429 #[serde(default = "build_connect_to")]
1430 pub connect_to: String,
1431}
1432
1433impl Connector for Say {
1434 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
1435 let connect_state = ConnectState::default(&self.connect_to, None);
1436 state.add_state(connect_state);
1437 state.clone()
1438 }
1439}
1440
1441#[derive(Serialize, Deserialize, Clone)]
1442#[serde(rename_all = "camelCase")]
1443pub struct VoiceMail {
1444 pub text: String,
1445 #[serde(rename = "ttsLanguage")]
1446 #[serde(default = "build_tts_voice")]
1447 pub tts_voice: String,
1448 #[serde(default = "build_vm_finish_key")]
1449 pub finish_on_key: String,
1450 #[serde(default)]
1451 pub email_recipients: Vec<String>,
1452 #[serde(default = "build_vm_timeout")]
1453 pub timeout: u8,
1454 #[serde(default = "build_vm_max_length")]
1455 pub max_length: u8,
1456 #[serde(default)]
1457 pub transcribe_options: TranscribeOptions,
1458 #[serde(default)]
1459 pub record_options: RecordOptions,
1460 #[serde(default)]
1461 pub play_beep: bool,
1462 #[serde(default = "build_connect_to")]
1463 pub connect_to: String,
1464}
1465
1466impl Connector for VoiceMail {
1467 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
1468 let connect_state = ConnectState::default(&self.connect_to, None);
1469 state.add_state(connect_state);
1470 state.clone()
1471 }
1472}
1473
1474#[derive(Serialize, Deserialize, Clone)]
1475#[serde(rename_all = "camelCase")]
1476pub struct TimeRangeRouter {
1477 start: String,
1478 end: String,
1479 #[serde(default = "build_default_timezone")]
1480 pub timezone: String,
1481 #[serde(default = "build_connect_to")]
1482 pub on_match: String,
1483 #[serde(default = "build_connect_to")]
1484 pub connect_to: String,
1485}
1486
1487impl TimeRangeRouter {
1488 pub fn get_start_time(&self) -> NaiveTime {
1489 NaiveTime::parse_from_str(self.start.as_str(), "YYYY-mm-ddTHH:MM:ssZ")
1490 .unwrap_or_else(|_| Local::now().naive_local().time())
1491 }
1492 pub fn get_end_time(&self) -> NaiveTime {
1493 NaiveTime::parse_from_str(self.end.as_str(), "YYYY-mm-ddTHH:MM:ssZ")
1494 .unwrap_or_else(|_| Local::now().naive_local().time())
1495 }
1496}
1497impl Connector for TimeRangeRouter {
1498 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
1499 let now = Local::now().naive_local().time();
1500 let within = now < self.get_end_time() && now > self.get_start_time();
1501 if within {
1502 let connect_state =
1503 ConnectState::matched(self.on_match.as_str(), Some(now.to_string()), None);
1504 state.add_state(connect_state);
1505 state.clone()
1506 } else {
1507 let connect_state =
1508 ConnectState::default(self.on_match.as_str(), Some(now.to_string()));
1509 state.add_state(connect_state);
1510 state.clone()
1511 }
1512 }
1513}
1514
1515#[derive(Serialize, Deserialize, Clone)]
1516#[serde(rename_all = "camelCase")]
1517pub struct DayOfWeekRouter {
1518 #[serde(default)]
1519 pub days: Vec<u32>,
1520 #[serde(default = "build_default_timezone")]
1521 pub timezone: String,
1522 #[serde(default = "build_connect_to")]
1523 pub on_match: String,
1524 #[serde(default = "build_connect_to")]
1525 pub connect_to: String,
1526}
1527
1528impl Connector for DayOfWeekRouter {
1529 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
1530 let now = Local::now().naive_local();
1531 let within = self.days.contains(&now.day());
1532 if within {
1533 let connect_state =
1534 ConnectState::matched(self.on_match.as_str(), Some(now.to_string()), None);
1535 state.add_state(connect_state);
1536 state.clone()
1537 } else {
1538 let connect_state =
1539 ConnectState::default(self.connect_to.as_str(), Some(now.to_string()));
1540 state.add_state(connect_state);
1541 state.clone()
1542 }
1543 }
1544}
1545
1546#[derive(Serialize, Deserialize, Clone)]
1547#[serde(rename_all = "camelCase")]
1548pub struct DateRangeRouter {
1549 start: String,
1550 end: String,
1551 #[serde(default = "build_default_timezone")]
1552 pub timezone: String,
1553 #[serde(default = "build_connect_to")]
1554 pub on_match: String,
1555 #[serde(default = "build_connect_to")]
1556 pub connect_to: String,
1557}
1558
1559impl DateRangeRouter {
1560 fn get_start_time(&self) -> NaiveDateTime {
1561 NaiveDateTime::parse_from_str(self.start.as_str(), "YYYY-mm-ddTHH:MM:ssZ")
1562 .unwrap_or_else(|_| Local::now().naive_local())
1563 }
1564 fn get_end_time(&self) -> NaiveDateTime {
1565 NaiveDateTime::parse_from_str(self.end.as_str(), "YYYY-mm-ddTHH:MM:ssZ")
1566 .unwrap_or_else(|_| Local::now().naive_local())
1567 }
1568}
1569impl Connector for DateRangeRouter {
1570 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
1571 let now = Local::now().naive_local();
1572 let within = now < self.get_end_time() && now > self.get_start_time();
1573 if within {
1574 let connect_state =
1575 ConnectState::matched(self.on_match.as_str(), Some(now.to_string()), None);
1576 state.add_state(connect_state);
1577 state.clone()
1578 } else {
1579 let connect_state =
1580 ConnectState::default(self.connect_to.as_str(), Some(now.to_string()));
1581 state.add_state(connect_state);
1582 state.clone()
1583 }
1584 }
1585}
1586
1587#[derive(Serialize, Deserialize, Clone)]
1588#[serde(rename_all = "camelCase")]
1589pub struct Script {
1590 pub code: String,
1591 #[serde(default = "build_connect_to")]
1592 pub connect_to: String,
1593}
1594
1595impl Connector for Script {
1596 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
1597 let connect_state = ConnectState::default(&self.connect_to, None);
1598 state.add_state(connect_state);
1599 state.clone()
1600 }
1601}
1602
1603#[derive(Serialize, Deserialize, Clone)]
1604#[serde(rename_all = "camelCase")]
1605pub struct Queue {
1606 #[serde(default = "build_connect_to")]
1607 pub connect_to: String,
1608 }
1617
1618impl Connector for Queue {
1620 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
1621 let connect_state = ConnectState::default(&self.connect_to, None);
1622 state.add_state(connect_state);
1623 state.clone()
1624 }
1625}
1626
1627#[derive(Serialize, Deserialize, Clone)]
1628#[serde(rename_all = "camelCase")]
1629pub struct QueueItem {
1630 pub text: String,
1631 #[serde(rename = "type")]
1632 pub item_type: QueueItemType,
1633}
1634
1635#[derive(Serialize, Deserialize, Clone)]
1636#[serde(rename_all = "camelCase")]
1637pub struct Email {
1638 #[serde(default = "build_connect_to")]
1639 pub connect_to: String,
1640}
1641
1642impl Connector for Email {
1643 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
1644 let connect_state = ConnectState::default(&self.connect_to, None);
1645 state.add_state(connect_state);
1646 state.clone()
1647 }
1648}
1649
1650#[derive(Serialize, Deserialize, Clone)]
1651#[serde(rename_all = "camelCase")]
1652pub struct Sms {
1653 #[serde(default = "build_connect_to")]
1654 pub connect_to: String,
1655}
1656
1657impl Connector for Sms {
1658 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
1659 let connect_state = ConnectState::default(&self.connect_to, None);
1660 state.add_state(connect_state);
1661 state.clone()
1662 }
1663}
1664
1665#[derive(Serialize, Deserialize, Clone)]
1666#[serde(rename_all = "camelCase")]
1667pub struct Tag {
1668 #[serde(default = "build_connect_to")]
1669 pub connect_to: String,
1670}
1671
1672impl Connector for Tag {
1673 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
1674 let connect_state = ConnectState::default(&self.connect_to, None);
1675 state.add_state(connect_state);
1676 state.clone()
1677 }
1678}
1679
1680#[derive(Serialize, Deserialize, Clone)]
1681#[serde(rename_all = "camelCase")]
1682pub struct TagRouter {
1683 #[serde(default = "build_connect_to")]
1684 pub connect_to: String,
1685}
1686
1687impl Connector for TagRouter {
1688 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
1689 let connect_state = ConnectState::default(&self.connect_to, None);
1690 state.add_state(connect_state);
1691 state.clone()
1692 }
1693}
1694
1695#[derive(Serialize, Deserialize, Clone)]
1696#[serde(rename_all = "camelCase")]
1697pub struct Service {
1698 #[serde(default = "build_connect_to")]
1699 pub connect_to: String,
1700}
1701
1702impl Connector for Service {
1703 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
1704 let connect_state = ConnectState::default(&self.connect_to, None);
1705 state.add_state(connect_state);
1706 state.clone()
1707 }
1708}
1709
1710#[derive(Serialize, Deserialize, Clone)]
1711#[serde(rename_all = "camelCase")]
1712pub struct MessagePlugin {
1713 #[serde(default = "build_connect_to")]
1714 pub connect_to: String,
1715}
1716
1717impl Connector for MessagePlugin {
1718 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
1719 let connect_state = ConnectState::default(&self.connect_to, None);
1720 state.add_state(connect_state);
1721 state.clone()
1722 }
1723}
1724
1725#[derive(Serialize, Deserialize, Clone)]
1726#[serde(rename_all = "camelCase")]
1727pub struct MessageText {
1728 #[serde(default = "build_connect_to")]
1729 pub connect_to: String,
1730}
1731
1732impl Connector for MessageText {
1733 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
1734 let connect_state = ConnectState::default(&self.connect_to, None);
1735 state.add_state(connect_state);
1736 state.clone()
1737 }
1738}
1739#[derive(Serialize, Deserialize, Clone)]
1740#[serde(rename_all = "camelCase")]
1741pub struct Event {
1742 #[serde(default = "build_connect_to")]
1743 pub connect_to: String,
1744}
1745impl Connector for Event {
1746 fn get_connect_to(&mut self, state: &mut FlowState) -> FlowState {
1747 let connect_state = ConnectState::default(&self.connect_to, None);
1748 state.add_state(connect_state);
1749 state.clone()
1750 }
1751}
1752
1753#[derive(Serialize, Deserialize, Clone)]
1754#[serde(rename_all = "camelCase")]
1755pub struct MapBox {
1756 #[serde(default)]
1757 pub bounds: MapBoxBoundary,
1758 #[serde(default)]
1759 pub features: Vec<MapBoxFeature>,
1760}
1761
1762#[derive(Serialize, Deserialize, Clone)]
1763#[serde(rename_all = "camelCase")]
1764pub struct MapBoxBoundary {
1765 pub xmin: f32,
1766 pub ymin: f32,
1767 pub xmax: f32,
1768 pub ymax: f32,
1769}
1770
1771impl Default for MapBoxBoundary {
1772 fn default() -> Self {
1773 Self {
1774 xmin: 0.00,
1775 ymin: 1.00,
1776 xmax: 0.01,
1777 ymax: 1.01,
1778 }
1779 }
1780}
1781
1782#[derive(Serialize, Deserialize, Clone)]
1783#[serde(rename_all = "camelCase")]
1784pub struct MapBoxFeature {
1785 pub id: String,
1786 #[serde(rename = "type")]
1787 pub feature_type: String,
1788 pub geometry: MapBoxGeometry,
1789}
1790
1791#[derive(Serialize, Deserialize, Clone)]
1792#[serde(rename_all = "camelCase")]
1793pub struct MapBoxGeometry {
1794 #[serde(rename = "type")]
1795 pub geometry_type: String,
1796 pub coordinates: Vec<Vec<(f32, f32)>>,
1797}
1798
1799#[derive(Serialize, Deserialize, Clone)]
1800#[serde(rename_all = "camelCase")]
1801pub struct RouterOption {
1802 pub option: String,
1803 #[serde(default = "build_connect_to")]
1804 pub connect_to: String,
1805}
1806
1807#[derive(Serialize, Deserialize, Clone)]
1808pub struct TranscribeOptions {
1809 pub enabled: bool,
1810 pub language: String,
1811}
1812
1813impl Default for TranscribeOptions {
1814 fn default() -> Self {
1815 Self {
1816 enabled: false,
1817 language: String::from(DEFAULT_ASR_LANGUAGE),
1818 }
1819 }
1820}
1821
1822#[derive(Serialize, Deserialize, Clone)]
1823pub struct RecordOptions {
1824 #[serde(default = "build_record")]
1825 pub enabled: bool,
1826 #[serde(default = "build_record_retention")]
1827 pub retention: String,
1828}
1829
1830impl Default for RecordOptions {
1831 fn default() -> Self {
1832 Self {
1833 enabled: false,
1834 retention: String::from(DEFAULT_RECORDING_RETENTION),
1835 }
1836 }
1837}
1838
1839fn build_record() -> bool {
1840 false
1841}
1842
1843fn build_record_retention() -> String {
1844 String::from(DEFAULT_RECORDING_RETENTION)
1845}
1846
1847fn build_connect_to() -> String {
1848 String::from(HANG_UP_CONNECT)
1849}
1850
1851fn build_tts_voice() -> String {
1852 String::from(DEFAULT_TTS_VOICE)
1853}
1854
1855fn build_vm_finish_key() -> String {
1856 String::from(DEFAULT_VM_FINISH_KEY)
1857}
1858
1859fn build_default_timezone() -> String {
1860 String::from(DEFAULT_TIMEZONE)
1861}
1862
1863fn build_vm_timeout() -> u8 {
1864 DEFAULT_VM_TIMEOUT
1865}
1866
1867fn build_vm_max_length() -> u8 {
1868 DEFAULT_VM_MAX_LENGTH
1869}
1870
1871fn build_present() -> String {
1872 String::from(DEFAULT_ENDPOINT_PRESENT)
1873}
1874
1875fn build_format() -> String {
1876 String::from(DEFAULT_ENDPOINT_FORMAT)
1877}
1878
1879fn build_client_profile() -> String {
1880 String::from(DEFAULT_CLIENT_PROFILE)
1881}
1882
1883fn build_country_code() -> String {
1884 String::from(DEFAULT_COUNTRY_CODE)
1885}
1886
1887fn build_finish_key() -> String {
1888 String::from(DEFAULT_DIGITS_FINISH_KEY)
1889}
1890
1891fn build_call_time() -> u16 {
1892 DEFAULT_CALL_TIME
1893}
1894
1895fn build_ring_time() -> u8 {
1896 DEFAULT_RING_TIME
1897}
1898
1899fn build_digit_timeout() -> u8 {
1900 DEFAULT_DIGIT_TIMEOUT
1901}
1902
1903fn build_max_digits() -> u8 {
1904 DEFAULT_MAX_DIGITS
1905}