-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathacw_settings.go
41 lines (35 loc) · 1.02 KB
/
acw_settings.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
package gcloudcx
import (
"encoding/json"
"time"
"github.com/gildas/go-errors"
)
// ACWSettings defines the After Call Work settings of a Queue
type ACWSettings struct {
WrapupPrompt string
Timeout time.Duration
}
// MarshalJSON marshals this into JSON
func (settings ACWSettings) MarshalJSON() ([]byte, error) {
data, err := json.Marshal(struct {
Timeout int64 `json:"timeoutMs"`
WrapupPrompt string `json:"wrapupPrompt"`
}{
Timeout: settings.Timeout.Milliseconds(),
WrapupPrompt: settings.WrapupPrompt,
})
return data, errors.JSONMarshalError.Wrap(err)
}
// UnmarshalJSON unmarshals JSON into this
func (settings *ACWSettings) UnmarshalJSON(payload []byte) (err error) {
var inner struct {
Timeout int64 `json:"timeoutMs"`
WrapupPrompt string `json:"wrapupPrompt"`
}
if err = json.Unmarshal(payload, &inner); err != nil {
return errors.JSONUnmarshalError.Wrap(err)
}
settings.Timeout = time.Duration(inner.Timeout) * time.Millisecond
settings.WrapupPrompt = inner.WrapupPrompt
return
}