-
Notifications
You must be signed in to change notification settings - Fork 6
/
telephony_easyhunting.go
194 lines (160 loc) · 7.17 KB
/
telephony_easyhunting.go
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
package ovh
import (
"fmt"
"net/url"
)
// TelephonyEasyHunting struct
type TelephonyEasyHunting struct {
//Max wait time when caller is in queue (in seconds)
MaxWaitTime float64 `json:"maxWaitTime,omitempty"`
// FeatureType
FeatureType string `json:"featureType,omitempty"`
// Strategy : The calls dispatching strategy
Strategy string `json:"strategy,omitempty"`
// QueueSize Max number of callers in queue
QueueSize float64 `json:"queueSize,omitempty"`
// ToneOnHold: Tone played when caller is put on hold
ToneOnHold float64 `json:"toneOnHold,omitempty"`
// ServiceName containers service Name
ServiceName string `json:"serviceName,omitempty"`
// ShowCallerNumber: The presented number when bridging calls
ShowCallerNumber string `json:"showCallerNumber,omitempty"`
// Description ...
Description string `json:"description,omitempty"`
// AnonymousRejection: Reject (hangup) anonymous calls
AnonymousRejection bool `json:"anonymousRejection,omitempty"`
//ToneOnOpening: Tone played when call is picked up
ToneOnOpening float64 `json:"toneOnOpening,omitempty"`
// serviceType
ServiceType string `json:"serviceType,omitempty"`
// Voicemail: The voicemail used by the EasyPABX
Voicemail string `json:"voicemail,omitempty"`
//ToneOnClosing: Tone played just before call is hang up
ToneOnClosing float64 `json:"toneOnClosing,omitempty"`
}
// TelephonyOvhPabxHunting struct
type TelephonyOvhPabxHunting struct {
// CrmUrlTemplate: The templated url of your CRM, opened by the banner application of your cloudpabx
CRMUrlTemplate string `json:"crmUrlTemplate,omitempty"`
// The name of your callcenter offer
Name string `json:"name,omitempty"`
// Enable G729 codec on your callcenter
G729 bool `json:"g729,omitempty"`
}
// TelephonyOvhPabxHuntingAgent ...
type TelephonyOvhPabxHuntingAgent struct {
// ID of agent
AgentID int64 `json:"agentId,omitempty"`
// The wrap up time (in seconds) after the calls
WrapUpTime int64 `json:"wrapUpTime,omitempty"`
// The number of the agent
Number string `json:"number,omitempty"`
// The waiting timeout (in seconds) before hangup an assigned called
Timeout int64 `json:"timeout,omitempty"`
// The current status of the agent
Status string `json:"status,omitempty"`
// The maximum of simultaneous calls that the agent will receive from the hunting
SimultaneousLines int64 `json:"simultaneousLines,omitempty"`
// The id of the current break status of the agent
BreakStatus int64 `json:"breakStatus,omitempty"`
}
// TelephonyEasyHuntingList list all OVH easy calls queues associated with this billing account
// GET /telephony/{billingAccount}/easyHunting
func (c *Client) TelephonyEasyHuntingList(billingAccount string, withDetails bool) ([]TelephonyEasyHunting, error) {
var names []string
if err := c.OVHClient.Get(fmt.Sprintf("/telephony/%s/easyHunting", url.QueryEscape(billingAccount)), &names); err != nil {
return nil, err
}
services := []TelephonyEasyHunting{}
for _, name := range names {
services = append(services, TelephonyEasyHunting{ServiceName: name})
}
if !withDetails {
return services, nil
}
servicesChan, errChan := make(chan TelephonyEasyHunting), make(chan error)
for _, telephonyEasyHunting := range services {
go func(billingAccount, serviceName string) {
d, err := c.TelephonyEasyHuntingInfo(billingAccount, serviceName)
if err != nil {
errChan <- err
return
}
servicesChan <- *d
}(billingAccount, telephonyEasyHunting.ServiceName)
}
servicesComplete := []TelephonyEasyHunting{}
for i := 0; i < len(services); i++ {
select {
case services := <-servicesChan:
servicesComplete = append(servicesComplete, services)
case err := <-errChan:
return nil, err
}
}
return servicesComplete, nil
}
// TelephonyEasyHuntingInfo retrieve all infos of one easy hunting service
// GET /telephony/{billingAccount}/easyHunting/{serviceName}
func (c *Client) TelephonyEasyHuntingInfo(billingAccount, serviceName string) (*TelephonyEasyHunting, error) {
telephonyEasyHunting := &TelephonyEasyHunting{}
err := c.OVHClient.Get(fmt.Sprintf("/telephony/%s/easyHunting/%s", url.QueryEscape(billingAccount), url.QueryEscape(serviceName)), telephonyEasyHunting)
return telephonyEasyHunting, err
}
// TelephonyOvhPabxHunting retrieves info on OVH Pabx Hunting
// GET /telephony/{billingAccount}/easyHunting/{serviceName}/hunting
func (c *Client) TelephonyOvhPabxHunting(billingAccount, serviceName string) (*TelephonyOvhPabxHunting, error) {
telephonyOvhPabxHunting := &TelephonyOvhPabxHunting{}
err := c.OVHClient.Get(fmt.Sprintf("/telephony/%s/easyHunting/%s/hunting", url.QueryEscape(billingAccount), url.QueryEscape(serviceName)), telephonyOvhPabxHunting)
return telephonyOvhPabxHunting, err
}
// TelephonyOvhPabxHuntingAgentList list all OVH easy calls queues associated with this billing account
// GET /telephony/{billingAccount}/easyHunting/{serviceName}/hunting/agent
func (c *Client) TelephonyOvhPabxHuntingAgentList(billingAccount, serviceName string, withDetails bool) ([]TelephonyOvhPabxHuntingAgent, error) {
var names []int64
if err := c.OVHClient.Get(fmt.Sprintf("/telephony/%s/easyHunting/%s/hunting/agent", url.QueryEscape(billingAccount), url.QueryEscape(serviceName)), &names); err != nil {
return nil, err
}
agents := []TelephonyOvhPabxHuntingAgent{}
for _, agentID := range names {
agents = append(agents, TelephonyOvhPabxHuntingAgent{AgentID: agentID})
}
if !withDetails {
return agents, nil
}
agentsChan, errChan := make(chan TelephonyOvhPabxHuntingAgent), make(chan error)
for _, agent := range agents {
go func(billingAccount, serviceName string, agentID int64) {
d, err := c.TelephonyOvhPabxHuntingAgentInfo(billingAccount, serviceName, agentID)
if err != nil {
errChan <- err
return
}
agentsChan <- *d
}(billingAccount, serviceName, agent.AgentID)
}
agentsComplete := []TelephonyOvhPabxHuntingAgent{}
for i := 0; i < len(agents); i++ {
select {
case agents := <-agentsChan:
agentsComplete = append(agentsComplete, agents)
case err := <-errChan:
return nil, err
}
}
return agentsComplete, nil
}
// TelephonyOvhPabxHuntingAgentInfo gets info from OVH Pabx Hunting Agent
// GET /telephony/{billingAccount}/easyHunting/{serviceName}/hunting/agent
func (c *Client) TelephonyOvhPabxHuntingAgentInfo(billingAccount, serviceName string, agentID int64) (*TelephonyOvhPabxHuntingAgent, error) {
telephonyOvhPabxHuntingAgent := &TelephonyOvhPabxHuntingAgent{}
err := c.OVHClient.Get(fmt.Sprintf("/telephony/%s/easyHunting/%s/hunting/agent/%d", url.QueryEscape(billingAccount), url.QueryEscape(serviceName), agentID), telephonyOvhPabxHuntingAgent)
return telephonyOvhPabxHuntingAgent, err
}
// TelephonyOvhPabxHuntingAgentUpdate update OVH Pabx Hunting Agent
// PUT /telephony/{billingAccount}/easyHunting/{serviceName}/hunting/agent/{agentId}
func (c *Client) TelephonyOvhPabxHuntingAgentUpdate(billingAccount, serviceName string, agentID int64, telephonyOvhPabxHuntingAgent TelephonyOvhPabxHuntingAgent) (*TelephonyOvhPabxHuntingAgent, error) {
r := &TelephonyOvhPabxHuntingAgent{}
err := c.OVHClient.Put(fmt.Sprintf("/telephony/%s/easyHunting/%s/hunting/agent/%d", url.QueryEscape(billingAccount), url.QueryEscape(serviceName), agentID), telephonyOvhPabxHuntingAgent, r)
return r, err
}