-
Notifications
You must be signed in to change notification settings - Fork 0
/
restxq.xqm
120 lines (111 loc) · 2.88 KB
/
restxq.xqm
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
(:~
: This module uses RESTXQ annotations to direct Twilio calls
: @author Clifford Anderson
:)
module namespace page = 'http://cliffordanderson.info/modules/twilio/restxq';
import module namespace twilio = 'http://cliffordanderson.info/modules/twilio/twiml' at 'twilio.xqy';
(:~
: This function returns the result of a form request.
: @param $message message to be included in the response
: @param $agent user agent string
: @return response element
:)
declare
%rest:path("/twilio/text/{$name}")
%rest:POST
%rest:form-param("TranscriptionText","{$message}", "No message!")
function page:send-text(
$message as xs:string?, $name as xs:string?)
{
twilio:send-text($message, $name)
};
(:~
: This function handles digits gathered by Twilio calls.
: @param $number phone number string provided by Caller ID
: @return Response element
:)
declare
%rest:path("/twilio/pickup")
%rest:query-param("From", "{$from}")
%rest:GET
function page:answer-call(
$from as xs:string?)
as element(Response)
{
twilio:get-callerId($from)
};
(:~
: This function answers Twilio calls.
: @param $name string to be included in the welcome message
: @return Response element
:)
declare
%rest:path("/twilio/answer/{$name}")
%rest:GET
function page:answer-phone(
$name as xs:string?)
as element(Response)
{
twilio:answer-phone($name)
};
(:~
: This function handles digits gathered by Twilio calls.
: @param $digits integer(s) provided by caller
: @return Response element
:)
declare
%rest:path("/twilio/gather")
%rest:query-param("Digits", "{$digits}")
%rest:GET
function page:gather-digits(
$digits as xs:string?)
as element(Response)
{
twilio:direct-outbound($digits)
};
(:~
: This function handles call options gathered by Twilio calls.
: @param $name string provided by caller
: @param $digits integer(s) provided by caller
: @return Response element
:)
declare
%rest:path("/twilio/gather/{$name}")
%rest:query-param("Digits", "{$digits}")
%rest:GET
function page:direct-choices(
$digits as xs:string?, $name as xs:string?)
as element(Response)
{
twilio:direct-choices($digits, $name)
};
(:~
: This function returns the result of a form request.
: @param $RecordingUrl link to recorded message
: @param $name name of mailbox owner string
: @return response element
:)
declare
%rest:path("/twilio/record/{$name}")
%rest:query-param("RecordingURl", "{$url}")
%rest:GET
function page:record-url(
$url as xs:string?, $name as xs:string?)
{
<Response><Say>Goodbye {$name}</Say></Response>
(: Add function to associate URL with appropriate mailbox :)
};
(:~
: This function concludes Twilio calls.
: @return Response element
:)
declare
%rest:path("/twilio/goodbye")
%rest:POST
function page:goodbye()
as element(Response)
{
<Response>
<Say>Goodbye! I hope you have a lovely day.</Say>
</Response>
};