-
Notifications
You must be signed in to change notification settings - Fork 4
/
contexts.go
68 lines (56 loc) · 1.91 KB
/
contexts.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
package dialogflow
// https://dialogflow.com/docs/reference/agent/contexts
import (
"encoding/json"
"fmt"
)
// Get all contexts with given session id.
func (c *Client) AllContexts(sid string) (result []ContextObject, err error) {
var bytes []byte
if bytes, err = c.httpGet("contexts", nil, map[string]string{"sessionId": sid}); err == nil {
if err = json.Unmarshal(bytes, &result); err == nil {
return result, nil
}
}
return []ContextObject{}, err
}
// Get a context.
func (c *Client) Context(sid, contextName string) (result ContextObject, err error) {
var bytes []byte
if bytes, err = c.httpGet(fmt.Sprintf("contexts/%s", contextName), nil, map[string]string{"sessionId": sid}); err == nil {
if err = json.Unmarshal(bytes, &result); err == nil {
return result, nil
}
}
return ContextObject{}, err
}
// Create contexts.
func (c *Client) CreateContexts(sid string, contexts []ContextObject) (result ContextResponseCreated, err error) {
var bytes []byte
if bytes, err = c.httpPost("contexts", nil, map[string]string{"sessionId": sid}, contexts); err == nil {
if err = json.Unmarshal(bytes, &result); err == nil {
return result, nil
}
}
return ContextResponseCreated{}, err
}
// Delete all contexts.
func (c *Client) DeleteContexts(sid string) (result ContextResponseDeleted, err error) {
var bytes []byte
if bytes, err = c.httpDelete("contexts", nil, map[string]string{"sessionId": sid}, nil); err == nil {
if err = json.Unmarshal(bytes, &result); err == nil {
return result, nil
}
}
return ContextResponseDeleted{}, err
}
// Delete a context.
func (c *Client) DeleteContext(sid, contextName string) (result ApiResponse, err error) {
var bytes []byte
if bytes, err = c.httpDelete(fmt.Sprintf("contexts/%s", contextName), nil, map[string]string{"sessionId": sid}, nil); err == nil {
if err = json.Unmarshal(bytes, &result); err == nil {
return result, nil
}
}
return ApiResponse{}, err
}