-
Notifications
You must be signed in to change notification settings - Fork 0
/
commands.v
300 lines (248 loc) · 7.75 KB
/
commands.v
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
module vagi
/**
* response.value = "-1" | "0"
*
* -1. channel failure
*
* 0 successful
* https://wiki.asterisk.org/wiki/display/AST/Asterisk+17+AGICommand_answer
*/
pub fn (mut a AGI) answer() {
a.send_command('ANSWER')
}
/**
* Interrupts expected flow of Async AGI commands and
* returns control to previous source (typically, the PBX dialplan).
*
* https://wiki.asterisk.org/wiki/display/AST/Asterisk+17+AGICommand_asyncagi+break
*/
pub fn (mut a AGI) async_agi_break() Response {
return a.send_command('ASYNCAGI BREAK')
}
/**
* response.value = "1" | "2" | "3" | "4" | "5" | "6" | "7" \
*
* 0 Channel is down and available.
*
* 1 Channel is down, but reserved.
*
* 2 Channel is off hook.
*
* 3 Digits (or equivalent) have been dialed.
*
* 4 Line is ringing.
*
* 5 Remote end is ringing.
*
* 6 Line is up.
*
* 7 Line is busy.
* https://wiki.asterisk.org/wiki/display/AST/Asterisk+17+AGICommand_channel+status
*/
pub fn (mut a AGI) channel_status() Response {
return a.send_command('CHANNEL STATUS')
}
/**
* Playback specified file with ability to be controlled by user
*
* filename -- filename to play (on the asterisk server)
* (don't use file-type extension!)
*
* escape_digits -- if provided default ['1', '2', '3', '4', '5', '6', '7', '8', '0'],
*
* skip_ms -- number of milliseconds to skip on FF/REW
*
* ff_char -- if provided, the set of chars that fast-forward
*
* rew_char -- if provided, the set of chars that rewind
*
* pause_char -- if provided, the set of chars that pause playback
* https://wiki.asterisk.org/wiki/display/AST/Asterisk+17+AGICommand_control+stream+file
*/
pub fn (mut a AGI) control_stream_file(filename string, escape_digits []string, skip_ms string, ff_char string, rew_char string, pause_char string, offsetms string) Response {
mut command := 'CONTROL STREAM FILE $filename "$escape_digits" $skip_ms $ff_char $rew_char'
if pause_char != '' {
command += ' $pause_char'
}
if offsetms != '' {
command += ' $offsetms'
}
return a.send_command(command)
}
/**
* Deletes an entry in the Asterisk database for a given family and key.
* response.value = "0" | "1"
*
* 0 successful
*
* 1 otherwise.
*
* https://wiki.asterisk.org/wiki/display/AST/Asterisk+17+AGICommand_database+del
*/
pub fn (mut a AGI) database_del(family string, key string) Response {
return a.send_command('DATABASE DEL $family $key')
}
/**
* Deletes a family or specific keytree within a family in the Asterisk database.
* response.result = "0" | "1"
*
* 0 if successful
*
* 1 otherwise.
*
* https://wiki.asterisk.org/wiki/display/AST/Asterisk+17+AGICommand_database+deltree
*/
pub fn (mut a AGI) database_del_tree(family string, key_tree string) Response {
return a.send_command('DATABASE DELTREE $family $key_tree')
}
/**
* Retrieves an entry in the Asterisk database for a given family and key.
* response.result = "0" | "1"
*
* 0 key is not set
*
* 1 key is set and returns the variable in response.value
*
* https://wiki.asterisk.org/wiki/display/AST/Asterisk+17+AGICommand_database+get
*/
pub fn (mut a AGI) database_get(family string, key string) Response {
return a.send_command('DATABASE GET $family $key')
}
/**
* Adds or updates an entry in the Asterisk database for a given family, key, and value.
* response.result = "0" | "1"
*
* 0 successful
*
* 1 otherwise.
*
* https://wiki.asterisk.org/wiki/display/AST/Asterisk+17+AGICommand_database+put
*/
pub fn (mut a AGI) database_put(family string, key string, value string) Response {
return a.send_command('DATABASE PUT $family $key $value')
}
/**
* Executes application with given options.
* Returns whatever the application returns, or -2 on failure to find application.
*/
pub fn (mut a AGI) exec(cmd ...string) Response {
return a.send_command(cmd.join(' '))
}
/**
* Prompts for DTMF on a channel
* Stream the given file, and receive DTMF data.
* Returns the digits received from the channel at the other end.
* https://wiki.asterisk.org/wiki/display/AST/Asterisk+17+AGICommand_get+data
*/
pub fn (mut a AGI) get_data(file string, timeout string, max_digits string) Response {
return a.send_command('GET DATA $file $timeout $max_digits')
}
pub fn (mut a AGI) get_full_variable(name string, channel_name string) Response {
return a.send_command('GET FULL VARIABLE $name $channel_name')
}
pub fn (mut a AGI) get_option(filename string, escape_digits []string, timeout string) Response {
return a.send_command('GET OPTION $filename "$escape_digits" $timeout')
}
pub fn (mut a AGI) get_variable(key string) Response {
return a.send_command('GET VARIABLE $key')
}
pub fn (mut a AGI) go_sub(context string, extension string, priority string, opt_arg string) {
a.send_command('GOSUB $context $extension $priority $opt_arg')
}
pub fn (mut a AGI) hangup() {
a.send_command('HANGUP')
}
pub fn (mut a AGI) noop() {
a.send_command('NOOP')
}
pub fn (mut a AGI) receive_char(timeout string) {
a.send_command('RECEIVE CHAR $timeout')
}
pub fn (mut a AGI) receive_text(timeout string) {
a.send_command('RECEIVE TEXT $timeout')
}
pub fn (mut a AGI) record_file(file string, format string, escape_digits []string, timeout string, offset_samples string, beep bool, silence string) Response {
mut command := 'RECORD FILE "$file" $format "$escape_digits" $timeout $offset_samples'
if beep {
command += ' 1'
}
if silence != '' {
command += ' s=$silence'
}
return a.send_command(command)
}
pub fn (mut a AGI) say_alpha(label string, escape_digits []string) Response {
return a.send_command('SAY ALPHA $label "$escape_digits"')
}
pub fn (mut a AGI) say_date(date string, escape_digits []string) {
a.send_command('SAY DATE $date "$escape_digits"')
}
pub fn (mut a AGI) say_date_time(date string, escape_digits []string, format string, timezone string) {
mut command := 'SAY DATETIME $date "$escape_digits"'
if format != '' {
command += ' $format'
}
if timezone != '' {
command += ' $timezone'
}
a.send_command(command)
}
pub fn (mut a AGI) say_digits(data string, escape_digits []string) {
a.send_command('SAY DIGITS $data "$escape_digits"')
}
pub fn (mut a AGI) say_number(data string, escape_digits []string, gender string) {
mut command := 'SAY NUMBER $data "$escape_digits"'
if gender != '' {
command += ' $gender'
}
a.send_command(command)
}
pub fn (mut a AGI) say_phonetic(data string, escape_digits []string) {
a.send_command('SAY PHONETIC "$data" "$escape_digits"')
}
pub fn (mut a AGI) say_time(date string, escape_digits []string) {
a.send_command('SAY TIME $date "$escape_digits"')
}
pub fn (mut a AGI) send_image(name string) {
a.send_command('SEND IMAGE $name')
}
pub fn (mut a AGI) send_text(text string) {
a.send_command('SEND TEXT "$text"')
}
pub fn (mut a AGI) set_auto_hangup(time string) {
a.send_command('SET AUTOHANGUP $time')
}
pub fn (mut a AGI) set_caller_id(caller_id string) {
a.send_command('SET CALLERID $caller_id')
}
pub fn (mut a AGI) set_context(context string) {
a.send_command('SET CONTEXT $context')
}
pub fn (mut a AGI) set_extension(extension string) {
a.send_command('SET EXTENSION $extension')
}
pub fn (mut a AGI) set_music(mode string, class_name string) {
a.send_command('SET MUSIC $mode $class_name')
}
pub fn (mut a AGI) set_priority(priority string) {
a.send_command('SET PRIORITY $priority')
}
pub fn (mut a AGI) set_variable(name string, value string) {
a.send_command('SET VARIABLE $name "$value"')
}
pub fn (mut a AGI) stream_file(filename string, escape_digits []string) {
a.send_command('STREAM FILE "$filename" "$escape_digits"')
}
pub fn (mut a AGI) verbose(message string, level string) {
mut command := 'VERBOSE "$message"'
if level != '' {
command += ' $level'
}
a.send_command(command)
}
pub fn (mut a AGI) wait_for_digit(timeout string) {
a.send_command('WAIT FOR DIGIT $timeout')
}
pub fn (mut a AGI) dial(target string, timeout string, params string) {
a.exec('Dial', '$target,$timeout', params)
}