asterisk-ari 0.3.0

Asterisk ARI client
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
use crate::apis::concat_option_str;
use crate::apis::params::{Direction, IfExists, TerminateOn};
use derive_new::new;
use derive_setters::Setters;
use serde::Serialize;

#[derive(Clone, Debug, Default, PartialEq, Serialize, new, Setters)]
#[setters(prefix = "with_")]
#[setters(into, strip_option)]
#[serde(rename_all = "camelCase")]
pub struct OriginateRequest {
    /// Endpoint to call.
    #[setters(skip)]
    #[new(into)]
    endpoint: String,

    /// The extension to dial after the endpoint answers. Mutually exclusive with 'app'.
    #[serde(flatten, skip_serializing_if = "Option::is_none")]
    #[new(default)]
    extension: Option<Extension>,

    /// The application that is subscribed to the originated channel.
    ///
    /// When the channel is answered, it will be passed to this Stasis application.
    /// Mutually exclusive with  'extension'.
    #[serde(flatten, skip_serializing_if = "Option::is_none")]
    #[new(default)]
    app: Option<App>,

    /// CallerID to use when dialing the endpoint or extension.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[new(default)]
    caller_id: Option<String>,

    /// The timeout (in seconds) before giving up dialing, or -1 for no timeout.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[new(value = "Some(30)")]
    timeout: Option<i32>,

    /// The unique id to assign the channel on creation.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[new(default)]
    channel_id: Option<String>,

    /// The unique id to assign the second channel when using local channels.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[new(default)]
    other_channel_id: Option<String>,

    /// The unique id of the channel which is originating this one.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[new(default)]
    originator: Option<String>,

    /// The format name capability list to use if originator is not specified.
    /// Ex. "ulaw,slin16".
    ///
    /// Format names can be found with "core show codecs".
    #[serde(skip_serializing_if = "Option::is_none")]
    #[new(default)]
    #[serde(serialize_with = "concat_option_str")]
    formats: Option<Vec<String>>,

    /// The "variables" key in the body object holds variable key/value pairs to set on the channel on creation.
    ///
    /// Other keys in the body object are interpreted as query parameters.
    /// Ex. { "endpoint": "SIP/Alice", "variables": { "CALLERID(name)": "Alice" } }
    #[serde(skip_serializing)]
    #[new(default)]
    pub(crate) variables: Option<serde_json::Value>,
}

#[derive(Clone, Debug, PartialEq, Serialize, new, Setters)]
#[setters(prefix = "with_")]
#[setters(into, strip_option)]
pub struct Extension {
    /// The extension to dial after the endpoint answers.
    #[setters(skip)]
    extension: String,

    /// The context to dial after the endpoint answers.
    /// If omitted, uses 'default'.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[new(default)]
    context: Option<String>,

    /// The priority to dial after the endpoint answers.
    /// If omitted, uses 1.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[new(default)]
    priority: Option<String>,

    /// The label to dial after the endpoint answers.
    /// Will supersede 'priority' if provided.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[new(default)]
    label: Option<String>,
}

#[derive(Clone, Debug, Default, PartialEq, Serialize, new, Setters)]
#[setters(prefix = "with_")]
#[setters(into, strip_option)]
pub struct App {
    /// Stasis Application to place channel into
    #[serde(rename = "app")]
    #[setters(skip)]
    #[new(into)]
    name: String,
    /// The application arguments to pass to the Stasis application provided by 'app'.
    #[serde(rename = "appArgs", skip_serializing_if = "Option::is_none")]
    #[new(default)]
    args: Option<String>,
}

#[derive(Clone, Debug, Default, PartialEq, Serialize, new, Setters)]
#[setters(prefix = "with_")]
#[setters(into, strip_option)]
#[serde(rename_all = "camelCase")]
pub struct CreateRequest {
    /// Endpoint for channel communication
    #[setters(skip)]
    #[new(into)]
    endpoint: String,

    /// Stasis Application to place channel into
    #[serde(flatten)]
    #[setters(skip)]
    app: App,

    /// The unique id to assign the channel on creation.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[new(default)]
    channel_id: Option<String>,

    /// The unique id to assign the second channel when using local channels.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[new(default)]
    other_channel_id: Option<String>,

    /// Unique ID of the calling channel
    #[serde(skip_serializing_if = "Option::is_none")]
    #[new(default)]
    originator: Option<String>,

    /// The format name capability list to use if originator is not specified.
    /// Ex. "ulaw,slin16".
    ///
    /// Format names can be found with "core show codecs".
    #[serde(skip_serializing_if = "Option::is_none")]
    #[serde(serialize_with = "concat_option_str")]
    #[new(default)]
    formats: Option<Vec<String>>,

    /// The "variables" key in the body object holds variable key/value pairs to set on the channel on creation.
    ///
    /// Other keys in the body object are interpreted as query parameters.
    /// Ex. { "endpoint": "SIP/Alice", "variables": { "CALLERID(name)": "Alice" } }
    #[serde(skip_serializing)]
    #[new(default)]
    pub(crate) variables: Option<serde_json::Value>,
}

#[derive(Clone, Debug, Default, PartialEq, Serialize, new, Setters)]
#[setters(prefix = "with_")]
#[setters(into, strip_option)]
#[serde(rename_all = "camelCase")]
pub struct OriginateWithIdRequest {
    /// The unique id to assign the channel on creation.
    #[serde(skip_serializing)]
    #[setters(skip)]
    #[new(into)]
    pub(crate) channel_id: String,

    /// Endpoint to call.
    #[setters(skip)]
    #[new(into)]
    endpoint: String,

    /// The extension to dial after the endpoint answers. Mutually exclusive with 'app'.
    #[serde(flatten, skip_serializing_if = "Option::is_none")]
    #[new(default)]
    extension: Option<Extension>,

    /// The application that is subscribed to the originated channel.
    ///
    /// When the channel is answered, it will be passed to this Stasis application.
    /// Mutually exclusive with  'extension'.
    #[serde(flatten, skip_serializing_if = "Option::is_none")]
    #[new(default)]
    app: Option<App>,

    /// CallerID to use when dialing the endpoint or extension.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[new(default)]
    caller_id: Option<String>,

    /// The timeout (in seconds) before giving up dialing, or -1 for no timeout.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[new(value = "Some(30)")]
    timeout: Option<i32>,

    /// The unique id to assign the second channel when using local channels.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[new(default)]
    other_channel_id: Option<String>,

    /// The unique id of the channel which is originating this one.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[new(default)]
    originator: Option<String>,

    /// The format name capability list to use if originator is not specified.
    /// Ex. "ulaw,slin16".
    ///
    /// Format names can be found with "core show codecs".
    #[serde(skip_serializing_if = "Option::is_none")]
    #[new(default)]
    #[serde(serialize_with = "concat_option_str")]
    formats: Option<Vec<String>>,

    /// The "variables" key in the body object holds variable key/value pairs to set on the channel on creation.
    ///
    /// Other keys in the body object are interpreted as query parameters.
    /// Ex. { "endpoint": "SIP/Alice", "variables": { "CALLERID(name)": "Alice" } }
    #[serde(skip_serializing)]
    #[new(default)]
    pub(crate) variables: Option<serde_json::Value>,
}

#[derive(Clone, Debug, PartialEq, Serialize, Default)]
pub enum CancelReason {
    #[serde(rename = "normal")]
    #[default]
    Normal,
    #[serde(rename = "busy")]
    Busy,
    #[serde(rename = "congestion")]
    Congestion,
    #[serde(rename = "no_answer")]
    NoAnswer,
    #[serde(rename = "timeout")]
    Timeout,
    #[serde(rename = "rejected")]
    Rejected,
    #[serde(rename = "unallocated")]
    Unallocated,
    #[serde(rename = "normal_unspecified")]
    NormalUnspecified,
    #[serde(rename = "number_incomplete")]
    NumberIncomplete,
    #[serde(rename = "codec_mismatch")]
    CodecMismatch,
    #[serde(rename = "interworking")]
    Interworking,
    #[serde(rename = "failure")]
    Failure,
    #[serde(rename = "answered_elsewhere")]
    AnsweredElsewhere,
}

#[derive(Clone, Debug, Serialize, new, Setters)]
#[setters(prefix = "with_")]
#[setters(into, strip_option)]
pub struct DeleteRequest {
    /// Channel's id
    #[serde(skip_serializing)]
    #[setters(skip)]
    #[new(into)]
    pub(crate) channel_id: String,

    /// The reason code for hanging up the channel for detail use.
    ///
    /// Mutually exclusive with 'reason'.
    /// See detail hangup codes at here. <https://docs.asterisk.org/Configuration/Miscellaneous/Hangup-Cause-Mappings/>
    #[serde(rename = "reason_code", skip_serializing_if = "Option::is_none")]
    #[new(default)]
    reason_code: Option<String>,

    /// Reason for hanging up the channel for simple use.
    ///
    /// Mutually exclusive with 'reason_code'.
    #[serde(rename = "reason", skip_serializing_if = "Option::is_none")]
    #[new(default)]
    reason: Option<CancelReason>,
}

#[derive(Clone, Debug, Serialize, new, Setters)]
#[setters(prefix = "with_")]
#[setters(into, strip_option)]
pub struct ContinueRequest {
    /// Channel's id
    #[serde(skip_serializing)]
    #[setters(skip)]
    #[new(into)]
    pub(crate) channel_id: String,

    /// The extension to continue to.
    #[serde(flatten, skip_serializing_if = "Option::is_none")]
    #[new(default)]
    extension: Option<Extension>,
}

#[derive(Clone, Debug, Serialize, new, Setters)]
#[setters(prefix = "with_")]
#[setters(into, strip_option)]
pub struct MoveRequest {
    /// Channel's id
    #[serde(skip_serializing)]
    #[setters(skip)]
    #[new(into)]
    pub(crate) channel_id: String,

    /// The channel will be passed to this Stasis application.
    #[serde(flatten, skip_serializing_if = "Option::is_none")]
    #[new(default)]
    app: Option<App>,
}

#[derive(Clone, Debug, Serialize, new, Setters)]
#[setters(prefix = "with_")]
#[setters(into, strip_option)]
pub struct DtmfRequest {
    /// Channel's id
    #[serde(skip_serializing)]
    #[setters(skip)]
    #[new(into)]
    pub(crate) channel_id: String,

    /// DTMF To send.
    #[setters(skip)]
    #[new(into)]
    dtmf: String,

    /// Amount of time to wait before DTMF digits (specified in milliseconds) start.
    #[serde(rename = "before", skip_serializing_if = "Option::is_none")]
    #[new(default)]
    before: Option<u32>,

    /// Amount of time in between DTMF digits (specified in milliseconds).
    #[serde(rename = "between", skip_serializing_if = "Option::is_none")]
    #[new(value = "Some(100)")]
    between: Option<u32>,

    /// Length of each DTMF digit (specified in milliseconds).
    #[serde(rename = "duration", skip_serializing_if = "Option::is_none")]
    #[new(value = "Some(100)")]
    duration: Option<u32>,

    /// Amount of time to wait after DTMF digits (specified in milliseconds) end.
    #[serde(rename = "after", skip_serializing_if = "Option::is_none")]
    #[new(default)]
    after: Option<u32>,
}

#[derive(Clone, Debug, Serialize, new, Setters)]
#[setters(prefix = "with_")]
#[setters(into, strip_option)]
pub struct MohRequest {
    /// Channel's id.
    #[serde(skip_serializing)]
    #[setters(skip)]
    #[new(into)]
    pub(crate) channel_id: String,

    /// Music on hold class to use.
    #[serde(rename = "mohClass", skip_serializing_if = "Option::is_none")]
    #[new(default)]
    moh_class: Option<String>,
}

#[derive(Clone, Debug, Serialize, new, Setters)]
#[setters(prefix = "with_")]
#[setters(into, strip_option)]
pub struct PlayRequest {
    /// Channel's id.
    #[serde(skip_serializing)]
    #[setters(skip)]
    #[new(into)]
    pub(crate) channel_id: String,

    /// Media URIs to play.
    #[setters(skip)]
    #[new(into)]
    pub(crate) media: String,

    /// For sounds, selects language for sound.
    #[serde(rename = "lang", skip_serializing_if = "Option::is_none")]
    #[new(default)]
    lang: Option<String>,

    /// Number of milliseconds to skip before playing. Only applies to the first URI if multiple media URIs are specified.
    #[serde(rename = "offsetms", skip_serializing_if = "Option::is_none")]
    #[new(default)]
    offset_ms: Option<u32>,

    /// Number of milliseconds to skip for forward/reverse operations.
    #[serde(rename = "skipms", skip_serializing_if = "Option::is_none")]
    #[new(default)]
    skip_ms: Option<u32>,
}

#[derive(Clone, Debug, Serialize, new, Setters)]
#[setters(prefix = "with_")]
#[setters(into, strip_option)]
pub struct PlayWithPlaybackIdRequest {
    /// Channel's id.
    #[serde(skip_serializing)]
    #[setters(skip)]
    #[new(into)]
    pub(crate) channel_id: String,

    /// Playback ID.
    #[serde(skip_serializing)]
    #[setters(skip)]
    #[new(into)]
    pub(crate) playback_id: String,

    /// Media URIs to play.
    #[setters(skip)]
    #[new(into)]
    pub(crate) media: String,

    /// For sounds, selects language for sound.
    #[serde(rename = "lang", skip_serializing_if = "Option::is_none")]
    #[new(default)]
    lang: Option<String>,

    /// Number of milliseconds to skip before playing. Only applies to the first URI if multiple media URIs are specified.
    #[serde(rename = "offsetms", skip_serializing_if = "Option::is_none")]
    #[new(default)]
    offset_ms: Option<u32>,

    /// Number of milliseconds to skip for forward/reverse operations.
    #[serde(rename = "skipms", skip_serializing_if = "Option::is_none")]
    #[new(default)]
    skip_ms: Option<u32>,
}

#[derive(Clone, Debug, Serialize, new, Setters)]
#[setters(prefix = "with_")]
#[setters(into, strip_option)]
pub struct RecordRequest {
    /// Channel's id.
    #[serde(skip_serializing)]
    #[setters(skip)]
    #[new(into)]
    pub(crate) channel_id: String,

    /// Recording's filename
    #[setters(skip)]
    #[new(into)]
    pub(crate) name: String,

    /// Format to encode audio in
    #[setters(skip)]
    #[new(into)]
    pub(crate) format: String,

    /// Maximum duration of the recording, in seconds. 0 for no limit.
    #[serde(rename = "maxDurationSeconds", skip_serializing_if = "Option::is_none")]
    #[new(default)]
    max_duration_seconds: Option<u32>,

    /// Maximum duration of silence, in seconds. 0 for no limit.
    #[serde(rename = "maxSilenceSeconds", skip_serializing_if = "Option::is_none")]
    #[new(default)]
    max_silence_seconds: Option<u32>,

    /// Action to take if a recording with the same name already exists.
    #[serde(rename = "ifExists", skip_serializing_if = "Option::is_none")]
    #[new(default)]
    if_exists: Option<IfExists>,

    /// Play beep when recording begins.
    #[serde(rename = "beep", skip_serializing_if = "Option::is_none")]
    #[new(default)]
    beep: Option<bool>,

    /// DTMF input to terminate recording.
    #[serde(rename = "terminateOn", skip_serializing_if = "Option::is_none")]
    #[new(default)]
    terminate_on: Option<TerminateOn>,
}

#[derive(Clone, Debug, Serialize, new, Setters)]
#[setters(prefix = "with_")]
#[setters(into, strip_option)]
pub struct SnoopRequest {
    /// Channel's id
    #[serde(skip_serializing)]
    #[setters(skip)]
    #[new(into)]
    pub(crate) channel_id: String,

    /// The channel will be passed to this Stasis application.
    #[serde(flatten, skip_serializing_if = "Option::is_none")]
    #[new(default)]
    app: Option<App>,

    /// Direction of audio to spy on.
    #[serde(rename = "spy", skip_serializing_if = "Option::is_none")]
    #[new(default)]
    spy: Option<Direction>,

    /// Direction of audio to whisper into.
    #[serde(rename = "whisper", skip_serializing_if = "Option::is_none")]
    #[new(default)]
    whisper: Option<Direction>,
}

#[derive(Clone, Debug, Serialize, new, Setters)]
#[setters(prefix = "with_")]
#[setters(into, strip_option)]
pub struct SnoopWithIdRequest {
    /// Channel's id
    #[serde(skip_serializing)]
    #[setters(skip)]
    #[new(into)]
    pub(crate) channel_id: String,

    /// Channel's id
    #[serde(skip_serializing)]
    #[setters(skip)]
    #[new(into)]
    pub(crate) snoop_id: String,

    /// The channel will be passed to this Stasis application.
    #[serde(flatten, skip_serializing_if = "Option::is_none")]
    #[new(default)]
    app: Option<App>,

    /// Direction of audio to spy on.
    #[serde(rename = "spy", skip_serializing_if = "Option::is_none")]
    #[new(default)]
    spy: Option<Direction>,

    /// Direction of audio to whisper into.
    #[serde(rename = "whisper", skip_serializing_if = "Option::is_none")]
    #[new(default)]
    whisper: Option<Direction>,
}

#[derive(Clone, Debug, Serialize, new, Setters)]
#[setters(prefix = "with_")]
#[setters(into, strip_option)]
pub struct DialRequest {
    /// Channel's id
    #[serde(skip_serializing)]
    #[setters(skip)]
    #[new(into)]
    pub(crate) channel_id: String,

    /// Channel ID of caller.
    #[serde(rename = "caller", skip_serializing_if = "Option::is_none")]
    #[new(default)]
    caller: Option<String>,

    /// Dial timeout.
    #[serde(rename = "timeout", skip_serializing_if = "Option::is_none")]
    #[new(default)]
    timeout: Option<u32>,
}

#[derive(Clone, Debug, Default, PartialEq, Serialize, new, Setters)]
#[setters(prefix = "with_")]
#[setters(into, strip_option)]
pub struct ExternalMediaRequest {
    /// Stasis Application to place channel into.
    #[setters(skip)]
    #[new(into)]
    app: String,

    /// Hostname/ip:port of external host.
    #[setters(skip)]
    #[new(into)]
    external_host: String,

    /// Format to encode audio in.
    #[setters(skip)]
    #[new(into)]
    format: String,

    /// The unique id to assign the channel on creation.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[new(default)]
    channel_id: Option<String>,

    /// The "variables" key in the body object holds variable key/value pairs to set on the channel on creation.
    ///
    /// Other keys in the body object are interpreted as query parameters.
    /// Ex. { "endpoint": "SIP/Alice", "variables": { "CALLERID(name)": "Alice" } }
    #[serde(skip_serializing)]
    #[new(default)]
    pub(crate) variables: Option<serde_json::Value>,

    /// Payload encapsulation protocol.
    #[new(default)]
    encapsulation: Encapsulation,

    /// Transport protocol.
    #[new(default)]
    transport: Transport,

    /// Connection type (client/server).
    #[new(default)]
    connection_type: ConnectionType,

    /// External media direction.
    #[new(default)]
    direction: Direction,

    /// An arbitrary data field.
    #[serde(skip_serializing_if = "Option::is_none")]
    #[new(default)]
    data: Option<String>,
}

#[derive(Clone, Debug, Serialize, Default, PartialEq)]
pub enum ConnectionType {
    #[default]
    #[serde(rename = "client")]
    Client,

    #[serde(rename = "server")]
    Server,
}

#[derive(Clone, Debug, Serialize, Default, PartialEq)]
pub enum Transport {
    #[serde(rename = "udp")]
    #[default]
    Udp,

    #[serde(rename = "tcp")]
    Tcp,
}

#[derive(Clone, Debug, Serialize, Default, PartialEq)]
pub enum Encapsulation {
    #[serde(rename = "rtp")]
    #[default]
    Rtp,

    #[serde(rename = "audiosocket")]
    AudioSocket,
}