-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueue.go
96 lines (83 loc) · 2.62 KB
/
queue.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
package telphin
import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"log"
"net/http"
"strings"
)
//
type Queue struct {
Sound uint64 `json:"sound"`
TierRulesApply bool `json:"tier_rules_apply"`
ExitKey string `json:"exit_key"`
TimeoutTransferDst string `json:"timeout_transfer_dst"`
MaxWaitTime uint64 `json:"max_wait_time"`
RecordEnabled bool `json:"record_enabled"`
MaxWaitTimeWithNoAgent uint64 `json:"max_wait_time_with_no_agent"`
Strategy string `json:"strategy"`
TierRuleWaitMultiplyLevel bool `json:"tier_rule_wait_multiply_level"`
ExtensionID uint64 `json:"extension_id"`
AnnounceFrequency uint64 `json:"announce_frequency"`
ExitTransferDst string `json:"exit_transfer_dst"`
SoundType string `json:"sound_type"`
TierRuleWaitSecond uint64 `json:"tier_rule_wait_second"`
AnnounceSound uint64 `json:"announce_sound"`
StartSound uint64 `json:"start_sound"`
}
//
func (oauth *OAuth) GetQueue(extensionId uint32) (*Queue, error) {
client := &http.Client{}
req, err := http.NewRequest("GET", API+"/extension/"+fmt.Sprint(extensionId)+"/queue/", nil)
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
req.Header.Add("Authorization", "Bearer "+oauth.AccessToken)
resp, err := client.Do(req)
if err != nil {
log.Println(err)
return nil, err
}
defer resp.Body.Close()
queue, err := ioutil.ReadAll(resp.Body)
if err != nil || resp.StatusCode > 201 {
log.Println(err)
fmt.Println(resp.StatusCode)
return nil, errors.New(string(queue))
}
var queueConfig *Queue
err = json.Unmarshal(queue, &queueConfig)
if err != nil {
log.Println(err)
}
return queueConfig, nil
}
//
func (oauth *OAuth) UpdateQueue(extensionId uint32, object ...interface{}) (*IVR, error) {
jsonPayload, err := json.Marshal(object)
if err != nil {
log.Println(err)
}
client := &http.Client{}
req, err := http.NewRequest("PUT", API+"/extension/"+fmt.Sprint(extensionId)+"/queue/", strings.NewReader(string(jsonPayload)))
req.Header.Add("Content-Type", "application/json")
req.Header.Add("Authorization", "Bearer "+oauth.AccessToken)
resp, err := client.Do(req)
if err != nil {
log.Println(err)
return nil, err
}
defer resp.Body.Close()
ivr, err := ioutil.ReadAll(resp.Body)
if err != nil || resp.StatusCode > 201 {
log.Println(err)
fmt.Println(resp.StatusCode)
return nil, errors.New(string(ivr))
}
var ivrConfig *IVR
err = json.Unmarshal(ivr, &ivrConfig)
if err != nil {
log.Println(err)
}
return ivrConfig, nil
}