asterisk_ari/apis/channels/
params.rs

1use crate::apis::concat_option_str;
2use crate::apis::params::{Direction, IfExists, TerminateOn};
3use derive_new::new;
4use derive_setters::Setters;
5use serde::Serialize;
6
7#[derive(Clone, Debug, Default, PartialEq, Serialize, new, Setters)]
8#[setters(prefix = "with_")]
9#[setters(into, strip_option)]
10#[serde(rename_all = "camelCase")]
11pub struct OriginateRequest {
12    /// Endpoint to call.
13    #[setters(skip)]
14    #[new(into)]
15    endpoint: String,
16
17    /// The extension to dial after the endpoint answers. Mutually exclusive with 'app'.
18    #[serde(flatten, skip_serializing_if = "Option::is_none")]
19    #[new(default)]
20    extension: Option<Extension>,
21
22    /// The application that is subscribed to the originated channel.
23    ///
24    /// When the channel is answered, it will be passed to this Stasis application.
25    /// Mutually exclusive with  'extension'.
26    #[serde(flatten, skip_serializing_if = "Option::is_none")]
27    #[new(default)]
28    app: Option<App>,
29
30    /// CallerID to use when dialing the endpoint or extension.
31    #[serde(skip_serializing_if = "Option::is_none")]
32    #[new(default)]
33    caller_id: Option<String>,
34
35    /// The timeout (in seconds) before giving up dialing, or -1 for no timeout.
36    #[serde(skip_serializing_if = "Option::is_none")]
37    #[new(value = "Some(30)")]
38    timeout: Option<i32>,
39
40    /// The unique id to assign the channel on creation.
41    #[serde(skip_serializing_if = "Option::is_none")]
42    #[new(default)]
43    channel_id: Option<String>,
44
45    /// The unique id to assign the second channel when using local channels.
46    #[serde(skip_serializing_if = "Option::is_none")]
47    #[new(default)]
48    other_channel_id: Option<String>,
49
50    /// The unique id of the channel which is originating this one.
51    #[serde(skip_serializing_if = "Option::is_none")]
52    #[new(default)]
53    originator: Option<String>,
54
55    /// The format name capability list to use if originator is not specified.
56    /// Ex. "ulaw,slin16".
57    ///
58    /// Format names can be found with "core show codecs".
59    #[serde(skip_serializing_if = "Option::is_none")]
60    #[new(default)]
61    #[serde(serialize_with = "concat_option_str")]
62    formats: Option<Vec<String>>,
63
64    /// The "variables" key in the body object holds variable key/value pairs to set on the channel on creation.
65    ///
66    /// Other keys in the body object are interpreted as query parameters.
67    /// Ex. { "endpoint": "SIP/Alice", "variables": { "CALLERID(name)": "Alice" } }
68    #[serde(skip_serializing)]
69    #[new(default)]
70    pub(crate) variables: Option<serde_json::Value>,
71}
72
73#[derive(Clone, Debug, PartialEq, Serialize, new, Setters)]
74#[setters(prefix = "with_")]
75#[setters(into, strip_option)]
76pub struct Extension {
77    /// The extension to dial after the endpoint answers.
78    #[setters(skip)]
79    extension: String,
80
81    /// The context to dial after the endpoint answers.
82    /// If omitted, uses 'default'.
83    #[serde(skip_serializing_if = "Option::is_none")]
84    #[new(default)]
85    context: Option<String>,
86
87    /// The priority to dial after the endpoint answers.
88    /// If omitted, uses 1.
89    #[serde(skip_serializing_if = "Option::is_none")]
90    #[new(default)]
91    priority: Option<String>,
92
93    /// The label to dial after the endpoint answers.
94    /// Will supersede 'priority' if provided.
95    #[serde(skip_serializing_if = "Option::is_none")]
96    #[new(default)]
97    label: Option<String>,
98}
99
100#[derive(Clone, Debug, Default, PartialEq, Serialize, new, Setters)]
101#[setters(prefix = "with_")]
102#[setters(into, strip_option)]
103pub struct App {
104    /// Stasis Application to place channel into
105    #[serde(rename = "app")]
106    #[setters(skip)]
107    #[new(into)]
108    name: String,
109    /// The application arguments to pass to the Stasis application provided by 'app'.
110    #[serde(rename = "appArgs", skip_serializing_if = "Option::is_none")]
111    #[new(default)]
112    args: Option<String>,
113}
114
115#[derive(Clone, Debug, Default, PartialEq, Serialize, new, Setters)]
116#[setters(prefix = "with_")]
117#[setters(into, strip_option)]
118#[serde(rename_all = "camelCase")]
119pub struct CreateRequest {
120    /// Endpoint for channel communication
121    #[setters(skip)]
122    #[new(into)]
123    endpoint: String,
124
125    /// Stasis Application to place channel into
126    #[serde(flatten)]
127    #[setters(skip)]
128    app: App,
129
130    /// The unique id to assign the channel on creation.
131    #[serde(skip_serializing_if = "Option::is_none")]
132    #[new(default)]
133    channel_id: Option<String>,
134
135    /// The unique id to assign the second channel when using local channels.
136    #[serde(skip_serializing_if = "Option::is_none")]
137    #[new(default)]
138    other_channel_id: Option<String>,
139
140    /// Unique ID of the calling channel
141    #[serde(skip_serializing_if = "Option::is_none")]
142    #[new(default)]
143    originator: Option<String>,
144
145    /// The format name capability list to use if originator is not specified.
146    /// Ex. "ulaw,slin16".
147    ///
148    /// Format names can be found with "core show codecs".
149    #[serde(skip_serializing_if = "Option::is_none")]
150    #[serde(serialize_with = "concat_option_str")]
151    #[new(default)]
152    formats: Option<Vec<String>>,
153
154    /// The "variables" key in the body object holds variable key/value pairs to set on the channel on creation.
155    ///
156    /// Other keys in the body object are interpreted as query parameters.
157    /// Ex. { "endpoint": "SIP/Alice", "variables": { "CALLERID(name)": "Alice" } }
158    #[serde(skip_serializing)]
159    #[new(default)]
160    pub(crate) variables: Option<serde_json::Value>,
161}
162
163#[derive(Clone, Debug, Default, PartialEq, Serialize, new, Setters)]
164#[setters(prefix = "with_")]
165#[setters(into, strip_option)]
166#[serde(rename_all = "camelCase")]
167pub struct OriginateWithIdRequest {
168    /// The unique id to assign the channel on creation.
169    #[serde(skip_serializing)]
170    #[setters(skip)]
171    #[new(into)]
172    pub(crate) channel_id: String,
173
174    /// Endpoint to call.
175    #[setters(skip)]
176    #[new(into)]
177    endpoint: String,
178
179    /// The extension to dial after the endpoint answers. Mutually exclusive with 'app'.
180    #[serde(flatten, skip_serializing_if = "Option::is_none")]
181    #[new(default)]
182    extension: Option<Extension>,
183
184    /// The application that is subscribed to the originated channel.
185    ///
186    /// When the channel is answered, it will be passed to this Stasis application.
187    /// Mutually exclusive with  'extension'.
188    #[serde(flatten, skip_serializing_if = "Option::is_none")]
189    #[new(default)]
190    app: Option<App>,
191
192    /// CallerID to use when dialing the endpoint or extension.
193    #[serde(skip_serializing_if = "Option::is_none")]
194    #[new(default)]
195    caller_id: Option<String>,
196
197    /// The timeout (in seconds) before giving up dialing, or -1 for no timeout.
198    #[serde(skip_serializing_if = "Option::is_none")]
199    #[new(value = "Some(30)")]
200    timeout: Option<i32>,
201
202    /// The unique id to assign the second channel when using local channels.
203    #[serde(skip_serializing_if = "Option::is_none")]
204    #[new(default)]
205    other_channel_id: Option<String>,
206
207    /// The unique id of the channel which is originating this one.
208    #[serde(skip_serializing_if = "Option::is_none")]
209    #[new(default)]
210    originator: Option<String>,
211
212    /// The format name capability list to use if originator is not specified.
213    /// Ex. "ulaw,slin16".
214    ///
215    /// Format names can be found with "core show codecs".
216    #[serde(skip_serializing_if = "Option::is_none")]
217    #[new(default)]
218    #[serde(serialize_with = "concat_option_str")]
219    formats: Option<Vec<String>>,
220
221    /// The "variables" key in the body object holds variable key/value pairs to set on the channel on creation.
222    ///
223    /// Other keys in the body object are interpreted as query parameters.
224    /// Ex. { "endpoint": "SIP/Alice", "variables": { "CALLERID(name)": "Alice" } }
225    #[serde(skip_serializing)]
226    #[new(default)]
227    pub(crate) variables: Option<serde_json::Value>,
228}
229
230#[derive(Clone, Debug, PartialEq, Serialize, Default)]
231pub enum CancelReason {
232    #[serde(rename = "normal")]
233    #[default]
234    Normal,
235    #[serde(rename = "busy")]
236    Busy,
237    #[serde(rename = "congestion")]
238    Congestion,
239    #[serde(rename = "no_answer")]
240    NoAnswer,
241    #[serde(rename = "timeout")]
242    Timeout,
243    #[serde(rename = "rejected")]
244    Rejected,
245    #[serde(rename = "unallocated")]
246    Unallocated,
247    #[serde(rename = "normal_unspecified")]
248    NormalUnspecified,
249    #[serde(rename = "number_incomplete")]
250    NumberIncomplete,
251    #[serde(rename = "codec_mismatch")]
252    CodecMismatch,
253    #[serde(rename = "interworking")]
254    Interworking,
255    #[serde(rename = "failure")]
256    Failure,
257    #[serde(rename = "answered_elsewhere")]
258    AnsweredElsewhere,
259}
260
261#[derive(Clone, Debug, Serialize, new, Setters)]
262#[setters(prefix = "with_")]
263#[setters(into, strip_option)]
264pub struct DeleteRequest {
265    /// Channel's id
266    #[serde(skip_serializing)]
267    #[setters(skip)]
268    #[new(into)]
269    pub(crate) channel_id: String,
270
271    /// The reason code for hanging up the channel for detail use.
272    ///
273    /// Mutually exclusive with 'reason'.
274    /// See detail hangup codes at here. <https://docs.asterisk.org/Configuration/Miscellaneous/Hangup-Cause-Mappings/>
275    #[serde(rename = "reason_code", skip_serializing_if = "Option::is_none")]
276    #[new(default)]
277    reason_code: Option<String>,
278
279    /// Reason for hanging up the channel for simple use.
280    ///
281    /// Mutually exclusive with 'reason_code'.
282    #[serde(rename = "reason", skip_serializing_if = "Option::is_none")]
283    #[new(default)]
284    reason: Option<CancelReason>,
285}
286
287#[derive(Clone, Debug, Serialize, new, Setters)]
288#[setters(prefix = "with_")]
289#[setters(into, strip_option)]
290pub struct ContinueRequest {
291    /// Channel's id
292    #[serde(skip_serializing)]
293    #[setters(skip)]
294    #[new(into)]
295    pub(crate) channel_id: String,
296
297    /// The extension to continue to.
298    #[serde(flatten, skip_serializing_if = "Option::is_none")]
299    #[new(default)]
300    extension: Option<Extension>,
301}
302
303#[derive(Clone, Debug, Serialize, new, Setters)]
304#[setters(prefix = "with_")]
305#[setters(into, strip_option)]
306pub struct MoveRequest {
307    /// Channel's id
308    #[serde(skip_serializing)]
309    #[setters(skip)]
310    #[new(into)]
311    pub(crate) channel_id: String,
312
313    /// The channel will be passed to this Stasis application.
314    #[serde(flatten, skip_serializing_if = "Option::is_none")]
315    #[new(default)]
316    app: Option<App>,
317}
318
319#[derive(Clone, Debug, Serialize, new, Setters)]
320#[setters(prefix = "with_")]
321#[setters(into, strip_option)]
322pub struct DtmfRequest {
323    /// Channel's id
324    #[serde(skip_serializing)]
325    #[setters(skip)]
326    #[new(into)]
327    pub(crate) channel_id: String,
328
329    /// DTMF To send.
330    #[setters(skip)]
331    #[new(into)]
332    dtmf: String,
333
334    /// Amount of time to wait before DTMF digits (specified in milliseconds) start.
335    #[serde(rename = "before", skip_serializing_if = "Option::is_none")]
336    #[new(default)]
337    before: Option<u32>,
338
339    /// Amount of time in between DTMF digits (specified in milliseconds).
340    #[serde(rename = "between", skip_serializing_if = "Option::is_none")]
341    #[new(value = "Some(100)")]
342    between: Option<u32>,
343
344    /// Length of each DTMF digit (specified in milliseconds).
345    #[serde(rename = "duration", skip_serializing_if = "Option::is_none")]
346    #[new(value = "Some(100)")]
347    duration: Option<u32>,
348
349    /// Amount of time to wait after DTMF digits (specified in milliseconds) end.
350    #[serde(rename = "after", skip_serializing_if = "Option::is_none")]
351    #[new(default)]
352    after: Option<u32>,
353}
354
355#[derive(Clone, Debug, Serialize, new, Setters)]
356#[setters(prefix = "with_")]
357#[setters(into, strip_option)]
358pub struct MohRequest {
359    /// Channel's id.
360    #[serde(skip_serializing)]
361    #[setters(skip)]
362    #[new(into)]
363    pub(crate) channel_id: String,
364
365    /// Music on hold class to use.
366    #[serde(rename = "mohClass", skip_serializing_if = "Option::is_none")]
367    #[new(default)]
368    moh_class: Option<String>,
369}
370
371#[derive(Clone, Debug, Serialize, new, Setters)]
372#[setters(prefix = "with_")]
373#[setters(into, strip_option)]
374pub struct PlayRequest {
375    /// Channel's id.
376    #[serde(skip_serializing)]
377    #[setters(skip)]
378    #[new(into)]
379    pub(crate) channel_id: String,
380
381    /// Media URIs to play.
382    #[setters(skip)]
383    #[new(into)]
384    pub(crate) media: String,
385
386    /// For sounds, selects language for sound.
387    #[serde(rename = "lang", skip_serializing_if = "Option::is_none")]
388    #[new(default)]
389    lang: Option<String>,
390
391    /// Number of milliseconds to skip before playing. Only applies to the first URI if multiple media URIs are specified.
392    #[serde(rename = "offsetms", skip_serializing_if = "Option::is_none")]
393    #[new(default)]
394    offset_ms: Option<u32>,
395
396    /// Number of milliseconds to skip for forward/reverse operations.
397    #[serde(rename = "skipms", skip_serializing_if = "Option::is_none")]
398    #[new(default)]
399    skip_ms: Option<u32>,
400}
401
402#[derive(Clone, Debug, Serialize, new, Setters)]
403#[setters(prefix = "with_")]
404#[setters(into, strip_option)]
405pub struct PlayWithPlaybackIdRequest {
406    /// Channel's id.
407    #[serde(skip_serializing)]
408    #[setters(skip)]
409    #[new(into)]
410    pub(crate) channel_id: String,
411
412    /// Playback ID.
413    #[serde(skip_serializing)]
414    #[setters(skip)]
415    #[new(into)]
416    pub(crate) playback_id: String,
417
418    /// Media URIs to play.
419    #[setters(skip)]
420    #[new(into)]
421    pub(crate) media: String,
422
423    /// For sounds, selects language for sound.
424    #[serde(rename = "lang", skip_serializing_if = "Option::is_none")]
425    #[new(default)]
426    lang: Option<String>,
427
428    /// Number of milliseconds to skip before playing. Only applies to the first URI if multiple media URIs are specified.
429    #[serde(rename = "offsetms", skip_serializing_if = "Option::is_none")]
430    #[new(default)]
431    offset_ms: Option<u32>,
432
433    /// Number of milliseconds to skip for forward/reverse operations.
434    #[serde(rename = "skipms", skip_serializing_if = "Option::is_none")]
435    #[new(default)]
436    skip_ms: Option<u32>,
437}
438
439#[derive(Clone, Debug, Serialize, new, Setters)]
440#[setters(prefix = "with_")]
441#[setters(into, strip_option)]
442pub struct RecordRequest {
443    /// Channel's id.
444    #[serde(skip_serializing)]
445    #[setters(skip)]
446    #[new(into)]
447    pub(crate) channel_id: String,
448
449    /// Recording's filename
450    #[setters(skip)]
451    #[new(into)]
452    pub(crate) name: String,
453
454    /// Format to encode audio in
455    #[setters(skip)]
456    #[new(into)]
457    pub(crate) format: String,
458
459    /// Maximum duration of the recording, in seconds. 0 for no limit.
460    #[serde(rename = "maxDurationSeconds", skip_serializing_if = "Option::is_none")]
461    #[new(default)]
462    max_duration_seconds: Option<u32>,
463
464    /// Maximum duration of silence, in seconds. 0 for no limit.
465    #[serde(rename = "maxSilenceSeconds", skip_serializing_if = "Option::is_none")]
466    #[new(default)]
467    max_silence_seconds: Option<u32>,
468
469    /// Action to take if a recording with the same name already exists.
470    #[serde(rename = "ifExists", skip_serializing_if = "Option::is_none")]
471    #[new(default)]
472    if_exists: Option<IfExists>,
473
474    /// Play beep when recording begins.
475    #[serde(rename = "beep", skip_serializing_if = "Option::is_none")]
476    #[new(default)]
477    beep: Option<bool>,
478
479    /// DTMF input to terminate recording.
480    #[serde(rename = "terminateOn", skip_serializing_if = "Option::is_none")]
481    #[new(default)]
482    terminate_on: Option<TerminateOn>,
483}
484
485#[derive(Clone, Debug, Serialize, new, Setters)]
486#[setters(prefix = "with_")]
487#[setters(into, strip_option)]
488pub struct SnoopRequest {
489    /// Channel's id
490    #[serde(skip_serializing)]
491    #[setters(skip)]
492    #[new(into)]
493    pub(crate) channel_id: String,
494
495    /// The channel will be passed to this Stasis application.
496    #[serde(flatten, skip_serializing_if = "Option::is_none")]
497    #[new(default)]
498    app: Option<App>,
499
500    /// Direction of audio to spy on.
501    #[serde(rename = "spy", skip_serializing_if = "Option::is_none")]
502    #[new(default)]
503    spy: Option<Direction>,
504
505    /// Direction of audio to whisper into.
506    #[serde(rename = "whisper", skip_serializing_if = "Option::is_none")]
507    #[new(default)]
508    whisper: Option<Direction>,
509}
510
511#[derive(Clone, Debug, Serialize, new, Setters)]
512#[setters(prefix = "with_")]
513#[setters(into, strip_option)]
514pub struct SnoopWithIdRequest {
515    /// Channel's id
516    #[serde(skip_serializing)]
517    #[setters(skip)]
518    #[new(into)]
519    pub(crate) channel_id: String,
520
521    /// Channel's id
522    #[serde(skip_serializing)]
523    #[setters(skip)]
524    #[new(into)]
525    pub(crate) snoop_id: String,
526
527    /// The channel will be passed to this Stasis application.
528    #[serde(flatten, skip_serializing_if = "Option::is_none")]
529    #[new(default)]
530    app: Option<App>,
531
532    /// Direction of audio to spy on.
533    #[serde(rename = "spy", skip_serializing_if = "Option::is_none")]
534    #[new(default)]
535    spy: Option<Direction>,
536
537    /// Direction of audio to whisper into.
538    #[serde(rename = "whisper", skip_serializing_if = "Option::is_none")]
539    #[new(default)]
540    whisper: Option<Direction>,
541}
542
543#[derive(Clone, Debug, Serialize, new, Setters)]
544#[setters(prefix = "with_")]
545#[setters(into, strip_option)]
546pub struct DialRequest {
547    /// Channel's id
548    #[serde(skip_serializing)]
549    #[setters(skip)]
550    #[new(into)]
551    pub(crate) channel_id: String,
552
553    /// Channel ID of caller.
554    #[serde(rename = "caller", skip_serializing_if = "Option::is_none")]
555    #[new(default)]
556    caller: Option<String>,
557
558    /// Dial timeout.
559    #[serde(rename = "timeout", skip_serializing_if = "Option::is_none")]
560    #[new(default)]
561    timeout: Option<u32>,
562}
563
564#[derive(Clone, Debug, Default, PartialEq, Serialize, new, Setters)]
565#[setters(prefix = "with_")]
566#[setters(into, strip_option)]
567pub struct ExternalMediaRequest {
568    /// Stasis Application to place channel into.
569    #[setters(skip)]
570    #[new(into)]
571    app: String,
572
573    /// Hostname/ip:port of external host.
574    #[setters(skip)]
575    #[new(into)]
576    external_host: String,
577
578    /// Format to encode audio in.
579    #[setters(skip)]
580    #[new(into)]
581    format: String,
582
583    /// The unique id to assign the channel on creation.
584    #[serde(skip_serializing_if = "Option::is_none")]
585    #[new(default)]
586    channel_id: Option<String>,
587
588    /// The "variables" key in the body object holds variable key/value pairs to set on the channel on creation.
589    ///
590    /// Other keys in the body object are interpreted as query parameters.
591    /// Ex. { "endpoint": "SIP/Alice", "variables": { "CALLERID(name)": "Alice" } }
592    #[serde(skip_serializing)]
593    #[new(default)]
594    pub(crate) variables: Option<serde_json::Value>,
595
596    /// Payload encapsulation protocol.
597    #[new(default)]
598    encapsulation: Encapsulation,
599
600    /// Transport protocol.
601    #[new(default)]
602    transport: Transport,
603
604    /// Connection type (client/server).
605    #[new(default)]
606    connection_type: ConnectionType,
607
608    /// External media direction.
609    #[new(default)]
610    direction: Direction,
611
612    /// An arbitrary data field.
613    #[serde(skip_serializing_if = "Option::is_none")]
614    #[new(default)]
615    data: Option<String>,
616}
617
618#[derive(Clone, Debug, Serialize, Default, PartialEq)]
619pub enum ConnectionType {
620    #[default]
621    #[serde(rename = "client")]
622    Client,
623
624    #[serde(rename = "server")]
625    Server,
626}
627
628#[derive(Clone, Debug, Serialize, Default, PartialEq)]
629pub enum Transport {
630    #[serde(rename = "udp")]
631    #[default]
632    Udp,
633
634    #[serde(rename = "tcp")]
635    Tcp,
636}
637
638#[derive(Clone, Debug, Serialize, Default, PartialEq)]
639pub enum Encapsulation {
640    #[serde(rename = "rtp")]
641    #[default]
642    Rtp,
643
644    #[serde(rename = "audiosocket")]
645    AudioSocket,
646}