-
Notifications
You must be signed in to change notification settings - Fork 23
/
call_feedback.go
60 lines (54 loc) · 1.6 KB
/
call_feedback.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
package plivo
import (
"bytes"
"encoding/json"
"errors"
"fmt"
)
const CallInsightsParams = "call_insights_params"
const CallInsightsBaseURL = "stats.plivo.com"
const CallInsightsFeedbackPath = "v1/Call/%s/Feedback/"
const CallInsightsRequestPath = "call_insights_feedback_path"
type CallFeedbackService struct {
client *Client
}
type CallFeedbackParams struct {
CallUUID string `json:"call_uuid"`
Notes string `json:"notes"`
Rating interface{} `json:"rating"`
Issues []string `json:"issues"`
}
type CallFeedbackCreateResponse struct {
ApiID string `json:"api_id"`
Message string `json:"message"`
Status string `json:"status"`
}
func (service *CallFeedbackService) Create(params CallFeedbackParams) (response *CallFeedbackCreateResponse, err error) {
if service.client == nil {
err = errors.New("client cannot be nil")
return
}
if params.CallUUID == "" {
err = errors.New("CallUUID cannot be nil")
return
}
if params.Rating == nil {
err = errors.New("rating cannot be nil")
return
}
var buffer = new(bytes.Buffer)
if err = json.NewEncoder(buffer).Encode(params); err != nil {
return
}
formatParams := map[string]interface{}{}
formatParams[CallInsightsParams] = make(map[string]interface{})
feedbackPath := fmt.Sprintf(CallInsightsFeedbackPath, params.CallUUID)
formatParams[CallInsightsParams].(map[string]interface{})[CallInsightsRequestPath] = feedbackPath
req, err := service.client.NewRequest("POST", params, "Call", formatParams)
if err != nil {
return
}
response = &CallFeedbackCreateResponse{}
err = service.client.ExecuteRequest(req, response)
return
}