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
use crate::verbs::auth::WSAuth;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
#[derive(Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
#[serde(tag = "type")]
pub enum Target {
Phone(Phone),
Sip(Sip),
User(User),
Teams(Teams),
}
#[derive(Serialize, Deserialize, Clone)]
pub struct Phone {
/// A telephone number in E.164 format.
pub number: String,
/// A webhook for an application to run on the callee’s end after
/// the dialed number answers but before the call is connected.
/// This will override the confirmHook property set on the parent dial verb,
/// if any.
#[serde(rename = "confirmHook")]
#[serde(skip_serializing_if = "Option::is_none")]
pub confirm_hook: Option<String>,
/// If provided, this should be the name of a Carrier
/// that you created in the jambonz portal or API,
/// which you want to use to complete this call.
/// If not provided, jambonz will selectone of your
/// configured Carriers that has an outbound trunk.
#[serde(skip_serializing_if = "Option::is_none")]
pub trunk: Option<String>,
/// An object containing arbitrary SIP headers
/// to apply to the outbound call attempt(s).
#[serde(skip_serializing_if = "HashMap::is_empty")]
pub headers: HashMap<String, String>,
}
impl Into<Target> for Phone {
fn into(self) -> Target {
Target::Phone(self)
}
}
impl Into<Vec<Target>> for Phone {
fn into(self) -> Vec<Target> {
vec![self.into()]
}
}
impl Phone {
pub fn new(number: &str) -> Phone {
Phone {
number: number.to_string(),
confirm_hook: None,
trunk: None,
headers: HashMap::new(),
}
}
pub fn confirm_hook(&mut self, confirm_hook: &str) -> &mut Phone {
self.confirm_hook = Some(confirm_hook.to_string());
self
}
pub fn trunk(&mut self, trunk: &str) -> &mut Phone {
self.trunk = Some(trunk.to_string());
self
}
pub fn header(&mut self, key: &str, value: &str) -> &mut Phone {
self.headers.insert(key.to_string(), value.to_string());
self
}
pub fn replace_headers(&mut self, headers: HashMap<String, String>) -> &mut Phone {
self.headers = headers;
self
}
pub fn add_headers(&mut self, headers: HashMap<String, String>) -> &mut Phone {
self.headers.extend(headers);
self
}
}
#[derive(Serialize, Deserialize, Clone)]
pub struct Sip {
/// Sip uri to send call to
/// e.g. (sip:+441234567890:5060)
#[serde(rename = "sipUri")]
pub sip_uri: String,
/// A webhook for an application to run on the callee’s end after
/// the dialed number answers but before the call is connected.
/// This will override the confirmHook property set on the parent dial verb,
/// if any.
#[serde(rename = "confirmHook")]
#[serde(skip_serializing_if = "Option::is_none")]
pub confirm_hook: Option<String>,
/// Authentication credentials
#[serde(skip_serializing_if = "Option::is_none")]
pub auth: Option<WSAuth>,
/// An object containing arbitrary SIP headers
/// to apply to the outbound call attempt(s).
#[serde(skip_serializing_if = "HashMap::is_empty")]
pub headers: HashMap<String, String>,
}
impl Into<Target> for Sip {
fn into(self) -> Target {
Target::Sip(self)
}
}
impl Into<Vec<Target>> for Sip {
fn into(self) -> Vec<Target> {
vec![self.into()]
}
}
impl Sip {
pub fn new(sip_uri: &str) -> Sip {
Sip {
sip_uri: sip_uri.to_string(),
confirm_hook: None,
auth: None,
headers: HashMap::new(),
}
}
pub fn from_parts(phone_number: &str, ip_address: &str, port: u16) -> Sip {
Sip {
sip_uri: format!("sip:{}@{}:{}", phone_number, ip_address, port),
confirm_hook: None,
auth: None,
headers: HashMap::new(),
}
}
pub fn confirm_hook(&mut self, confirm_hook: &str) -> &mut Sip {
self.confirm_hook = Some(confirm_hook.to_string());
self
}
pub fn auth(&mut self, auth: WSAuth) -> &mut Sip {
self.auth = Some(auth);
self
}
pub fn header(&mut self, key: &str, value: &str) -> &mut Sip {
self.headers.insert(key.to_string(), value.to_string());
self
}
pub fn replace_headers(&mut self, headers: HashMap<String, String>) -> &mut Sip {
self.headers = headers;
self
}
pub fn add_headers(&mut self, headers: HashMap<String, String>) -> &mut Sip {
self.headers.extend(headers);
self
}
}
#[derive(Serialize, Deserialize, Clone)]
pub struct User {
/// Registered sip user, including domain
/// (e.g. "joeb@sip.jambonz.org")
pub name: String,
/// A webhook for an application to run on the callee’s end after
/// the dialed number answers but before the call is connected.
/// This will override the confirmHook property set on the parent dial verb,
/// if any.
#[serde(rename = "confirmHook")]
#[serde(skip_serializing_if = "Option::is_none")]
pub confirm_hook: Option<String>,
/// An object containing arbitrary SIP headers
/// to apply to the outbound call attempt(s).
#[serde(skip_serializing_if = "HashMap::is_empty")]
pub headers: HashMap<String, String>,
/// Adds X-Override-To: +441234567890 INVITE from FS
/// This is then translated to outbound INVITE URI on SBC:
/// (e.g. INVITE sip:+441234567890@1.1.1.1:5060;transport=udp SIP/2.0)
#[serde(rename = "overrideTo")]
#[serde(skip_serializing_if = "Option::is_none")]
pub override_to: Option<String>,
}
impl Into<Target> for User {
fn into(self) -> Target {
Target::User(self)
}
}
impl Into<Vec<Target>> for User {
fn into(self) -> Vec<Target> {
vec![self.into()]
}
}
impl User {
pub fn new(sip_uri: &str) -> User {
User {
name: sip_uri.to_string(),
confirm_hook: None,
override_to: None,
headers: HashMap::new(),
}
}
pub fn from_parts(username: &str, domain: &str) -> User {
User {
name: format!("{}@{}", username, domain),
confirm_hook: None,
override_to: None,
headers: HashMap::new(),
}
}
pub fn confirm_hook(&mut self, confirm_hook: &str) -> &mut User {
self.confirm_hook = Some(confirm_hook.to_string());
self
}
pub fn override_to(&mut self, override_to: &str) -> &mut User {
self.override_to = Some(override_to.to_string());
self
}
pub fn header(&mut self, key: &str, value: &str) -> &mut User {
self.headers.insert(key.to_string(), value.to_string());
self
}
pub fn replace_headers(&mut self, headers: HashMap<String, String>) -> &mut User {
self.headers = headers;
self
}
pub fn add_headers(&mut self, headers: HashMap<String, String>) -> &mut User {
self.headers.extend(headers);
self
}
}
#[derive(Serialize, Deserialize, Clone)]
pub struct Teams {
/// The phone number that has been mapped to the
/// teams user by the Microsoft Teams administrator
pub number: String,
/// A webhook for an application to run on the callee’s end after
/// the dialed number answers but before the call is connected.
/// This will override the confirmHook property set on the parent dial verb,
/// if any.
#[serde(rename = "confirmHook")]
#[serde(skip_serializing_if = "Option::is_none")]
pub confirm_hook: Option<String>,
/// Microsoft Teams customer tenant domain name.
/// Will default to the Microsoft Teams tenant
/// associated with the account of the calling party.
#[serde(skip_serializing_if = "Option::is_none")]
pub tenant: Option<String>,
/// if true, dial directly into user’s
/// voicemail to leave a message
#[serde(skip_serializing_if = "Option::is_none")]
pub voicemail: Option<bool>,
/// An object containing arbitrary SIP headers
/// to apply to the outbound call attempt(s).
#[serde(skip_serializing_if = "HashMap::is_empty")]
pub headers: HashMap<String, String>,
}
impl Into<Target> for Teams {
fn into(self) -> Target {
Target::Teams(self)
}
}
impl Into<Vec<Target>> for Teams {
fn into(self) -> Vec<Target> {
vec![self.into()]
}
}
impl Teams {
pub fn new(number: &str) -> Teams {
Teams {
number: number.to_string(),
confirm_hook: None,
tenant: None,
voicemail: None,
headers: HashMap::new(),
}
}
pub fn from_parts(number: &str, tenant: &str) -> Teams {
Teams {
number: number.to_string(),
confirm_hook: None,
tenant: Some(tenant.to_string()),
voicemail: None,
headers: HashMap::new(),
}
}
pub fn tenant(&mut self, tenant: &str) -> &mut Teams {
self.tenant = Some(tenant.to_string());
self
}
pub fn voicemail(&mut self, tenant: bool) -> &mut Teams {
self.tenant = Some(tenant.to_string());
self
}
pub fn confirm_hook(&mut self, confirm_hook: &str) -> &mut Teams {
self.confirm_hook = Some(confirm_hook.to_string());
self
}
pub fn header(&mut self, key: &str, value: &str) -> &mut Teams {
self.headers.insert(key.to_string(), value.to_string());
self
}
pub fn replace_headers(&mut self, headers: HashMap<String, String>) -> &mut Teams {
self.headers = headers;
self
}
pub fn add_headers(&mut self, headers: HashMap<String, String>) -> &mut Teams {
self.headers.extend(headers);
self
}
}