-
Notifications
You must be signed in to change notification settings - Fork 3
/
callscore.go
173 lines (142 loc) · 4.79 KB
/
callscore.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
// Copyright 2022 Symbl.ai SDK contributors. All Rights Reserved.
// Use of this source code is governed by an Apache-2.0 license that can be found in the LICENSE file.
// SPDX-License-Identifier: Apache-2.0
/*
Async package for processing Async conversations
*/
package async
import (
"context"
"fmt"
"net/http"
klog "k8s.io/klog/v2"
asyncinterfaces "github.com/symblai/symbl-go-sdk/pkg/api/async/v1/interfaces"
version "github.com/symblai/symbl-go-sdk/pkg/api/version"
interfaces "github.com/symblai/symbl-go-sdk/pkg/client/interfaces"
)
// Get Call Score Status By Id
func (c *Client) GetCallScoreStatusById(ctx context.Context, conversationId string) (*asyncinterfaces.CallScoreStatusResult, error) {
klog.V(6).Infof("async.GetCallScoreStatusById ENTER\n")
// checks
if ctx == nil {
ctx = context.Background()
}
if conversationId == "" {
klog.V(1).Infof("conversationId is empty\n")
klog.V(6).Infof("async.GetCallScoreStatusById LEAVE\n")
return nil, ErrInvalidInput
}
// request
URI := fmt.Sprintf("%s%s",
version.GetAsyncAPI(version.CallScoreStatusURI, conversationId),
c.getQueryParamFromContext(ctx))
klog.V(6).Infof("Calling %s\n", URI)
req, err := http.NewRequestWithContext(ctx, "GET", URI, nil)
if err != nil {
klog.V(1).Infof("http.NewRequestWithContext failed. Err: %v\n", err)
klog.V(6).Infof("async.GetCallScoreStatusById LEAVE\n")
return nil, err
}
// check the status
var result asyncinterfaces.CallScoreStatusResult
err = c.Client.Do(ctx, req, &result)
if err != nil {
if e, ok := err.(*interfaces.StatusError); ok {
if e.Resp.StatusCode != http.StatusOK {
klog.V(1).Infof("HTTP Code: %v\n", e.Resp.StatusCode)
klog.V(6).Infof("async.GetCallScoreStatusById LEAVE\n")
return nil, err
}
}
klog.V(1).Infof("Platform Supplied Err: %v\n", err)
klog.V(6).Infof("async.GetCallScoreStatusById LEAVE\n")
return nil, err
}
klog.V(3).Infof("GET CallScoreStatus succeeded\n")
klog.V(6).Infof("async.GetCallScoreStatusById LEAVE\n")
return &result, nil
}
// Get Insight Status By Id
func (c *Client) GetInsightStatusById(ctx context.Context, conversationId string) (*asyncinterfaces.InsightStatusResult, error) {
klog.V(6).Infof("async.GetInsightStatusById ENTER\n")
// checks
if ctx == nil {
ctx = context.Background()
}
if conversationId == "" {
klog.V(1).Infof("conversationId is empty\n")
klog.V(6).Infof("async.GetInsightStatusById LEAVE\n")
return nil, ErrInvalidInput
}
// request
URI := fmt.Sprintf("%s%s",
version.GetAsyncAPI(version.InsightStatusURI, conversationId),
c.getQueryParamFromContext(ctx))
klog.V(6).Infof("Calling %s\n", URI)
req, err := http.NewRequestWithContext(ctx, "GET", URI, nil)
if err != nil {
klog.V(1).Infof("http.NewRequestWithContext failed. Err: %v\n", err)
klog.V(6).Infof("async.GetInsightStatusById LEAVE\n")
return nil, err
}
// check the status
var result asyncinterfaces.InsightStatusResult
err = c.Client.Do(ctx, req, &result)
if err != nil {
if e, ok := err.(*interfaces.StatusError); ok {
if e.Resp.StatusCode != http.StatusOK {
klog.V(1).Infof("HTTP Code: %v\n", e.Resp.StatusCode)
klog.V(6).Infof("async.GetInsightStatusById LEAVE\n")
return nil, err
}
}
klog.V(1).Infof("Platform Supplied Err: %v\n", err)
klog.V(6).Infof("async.GetInsightStatusById LEAVE\n")
return nil, err
}
klog.V(3).Infof("GET InsightStatus succeeded\n")
klog.V(6).Infof("async.GetInsightStatusById LEAVE\n")
return &result, nil
}
// Get Call Score
func (c *Client) GetCallScore(ctx context.Context, conversationId string) (*asyncinterfaces.CallScoreResult, error) {
klog.V(6).Infof("async.GetCallScore ENTER\n")
// checks
if ctx == nil {
ctx = context.Background()
}
if conversationId == "" {
klog.V(1).Infof("conversationId is empty\n")
klog.V(6).Infof("async.GetCallScore LEAVE\n")
return nil, ErrInvalidInput
}
// request
URI := fmt.Sprintf("%s%s",
version.GetAsyncAPI(version.CallScoreURI, conversationId),
c.getQueryParamFromContext(ctx))
klog.V(6).Infof("Calling %s\n", URI)
req, err := http.NewRequestWithContext(ctx, "GET", URI, nil)
if err != nil {
klog.V(1).Infof("http.NewRequestWithContext failed. Err: %v\n", err)
klog.V(6).Infof("async.GetCallScore LEAVE\n")
return nil, err
}
// check the status
var result asyncinterfaces.CallScoreResult
err = c.Client.Do(ctx, req, &result)
if err != nil {
if e, ok := err.(*interfaces.StatusError); ok {
if e.Resp.StatusCode != http.StatusOK {
klog.V(1).Infof("HTTP Code: %v\n", e.Resp.StatusCode)
klog.V(6).Infof("async.GetCallScore LEAVE\n")
return nil, err
}
}
klog.V(1).Infof("Platform Supplied Err: %v\n", err)
klog.V(6).Infof("async.GetCallScore LEAVE\n")
return nil, err
}
klog.V(3).Infof("GET CallScore succeeded\n")
klog.V(6).Infof("async.GetCallScore LEAVE\n")
return &result, nil
}