Skip to content

Commit 9b233aa

Browse files
committed
New API version: 20240304
1 parent 7a88bf3 commit 9b233aa

14 files changed

+144
-214
lines changed

.github/workflows/test.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ jobs:
66
runs-on: ubuntu-latest
77
steps:
88
- name: Install Go
9-
uses: actions/setup-go@v2
9+
uses: actions/setup-go@v5
1010
with:
11-
go-version: 1.14
11+
go-version: 1.22
1212

1313
- name: Check out code into the Go module directory
14-
uses: actions/checkout@v2
14+
uses: actions/checkout@v4
1515

1616
- name: Run Tests
1717
run: go test -race -v .

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change Log
22

3+
July 3, 2024
4+
5+
- New default API version: 20240304. Adjusted types to new version
6+
- Switch to latest Go version 1.22
7+
- Fix integration tests
8+
39
Nov 16, 2020
410

511
- Switch to Github Actions for CI/CD

README.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
![wit.ai](https://s3.amazonaws.com/pliutau.com/wit.png)
22

3-
[![GoDoc](https://godoc.org/github.com/wit-ai/wit-go?status.svg)](https://godoc.org/github.com/wit-ai/wit-go) [![Go Report Card](https://goreportcard.com/badge/github.com/wit-ai/wit-go)](https://goreportcard.com/report/github.com/wit-ai/wit-go)
3+
[![Go Reference](https://pkg.go.dev/badge/github.com/wit-ai/wit-go)](https://pkg.go.dev/github.com/wit-ai/wit-go)
44

55
*This repository is community-maintained. We gladly accept pull requests. Please see the [Wit HTTP Reference](https://wit.ai/docs/http/latest) for all supported endpoints.*
66

77
Go client for [wit.ai](https://wit.ai/) HTTP API.
88

9+
API version: 20240304
10+
911
## Install
1012

1113
```
@@ -37,7 +39,7 @@ func main() {
3739

3840
## Testing
3941

40-
Both Unit / Integration tests are executed by Github Actions.
42+
Unit tests are executed by Github Actions, but Integration tests have to be executed manually by providing a valid token via `WITAI_INTEGRATION_TOKEN` env var.
4143

4244
### Unit tests
4345

@@ -50,8 +52,7 @@ go test -race -v
5052
Integration tests are connecting to real Wit.ai API, so you need to provide a valid token:
5153

5254
```
53-
export WITAI_INTEGRATION_TOKEN=your_secret_token_here
54-
go test -v -tags=integration
55+
WITAI_INTEGRATION_TOKEN={SERVER_ACCESS_TOKEN} go test -v -tags=integration
5556
```
5657

5758
## License

apps.go

+16-16
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const (
2424
Ongoing AppTrainingStatus = "ongoing"
2525
)
2626

27-
// App - https://wit.ai/docs/http/20200513/#get__apps_link
27+
// App - https://wit.ai/docs/http/#get__apps_link
2828
type App struct {
2929
ID string `json:"id,omitempty"`
3030
Name string `json:"name"`
@@ -60,15 +60,15 @@ func (witTime *Time) UnmarshalJSON(input []byte) error {
6060
return nil
6161
}
6262

63-
// CreatedApp - https://wit.ai/docs/http/20200513/#post__apps_link
63+
// CreatedApp - https://wit.ai/docs/http/#post__apps_link
6464
type CreatedApp struct {
6565
AccessToken string `json:"access_token"`
6666
AppID string `json:"app_id"`
6767
}
6868

6969
// GetApps - Returns an array of all apps that you own.
7070
//
71-
// https://wit.ai/docs/http/20200513/#get__apps_link
71+
// https://wit.ai/docs/http/#get__apps_link
7272
func (c *Client) GetApps(limit int, offset int) ([]App, error) {
7373
if limit <= 0 {
7474
limit = 0
@@ -92,7 +92,7 @@ func (c *Client) GetApps(limit int, offset int) ([]App, error) {
9292

9393
// GetApp - Returns an object representation of the specified app.
9494
//
95-
// https://wit.ai/docs/http/20200513/#get__apps__app_link
95+
// https://wit.ai/docs/http/#get__apps__app_link
9696
func (c *Client) GetApp(id string) (*App, error) {
9797
resp, err := c.request(http.MethodGet, fmt.Sprintf("/apps/%s", url.PathEscape(id)), "application/json", nil)
9898
if err != nil {
@@ -112,7 +112,7 @@ func (c *Client) GetApp(id string) (*App, error) {
112112

113113
// CreateApp - creates new app.
114114
//
115-
// https://wit.ai/docs/http/20200513/#post__apps_link
115+
// https://wit.ai/docs/http/#post__apps_link
116116
func (c *Client) CreateApp(app App) (*CreatedApp, error) {
117117
appJSON, err := json.Marshal(app)
118118
if err != nil {
@@ -135,7 +135,7 @@ func (c *Client) CreateApp(app App) (*CreatedApp, error) {
135135

136136
// UpdateApp - Updates an app.
137137
//
138-
// https://wit.ai/docs/http/20200513/#put__apps__app_link
138+
// https://wit.ai/docs/http/#put__apps__app_link
139139
func (c *Client) UpdateApp(id string, app App) error {
140140
appJSON, err := json.Marshal(app)
141141
if err != nil {
@@ -152,7 +152,7 @@ func (c *Client) UpdateApp(id string, app App) error {
152152

153153
// DeleteApp - deletes app by ID.
154154
//
155-
// https://wit.ai/docs/http/20200513/#delete__apps__app_link
155+
// https://wit.ai/docs/http/#delete__apps__app_link
156156
func (c *Client) DeleteApp(id string) error {
157157
resp, err := c.request(http.MethodDelete, fmt.Sprintf("/apps/%s", url.PathEscape(id)), "application/json", nil)
158158
if err == nil {
@@ -162,7 +162,7 @@ func (c *Client) DeleteApp(id string) error {
162162
return err
163163
}
164164

165-
// AppTag - https://wit.ai/docs/http/20200513/#get__apps__app_tags__tag_link
165+
// AppTag - https://wit.ai/docs/http/#get__apps__app_tags__tag_link
166166
type AppTag struct {
167167
Name string `json:"name,omitempty"`
168168
Desc string `json:"desc,omitempty"`
@@ -174,7 +174,7 @@ type AppTag struct {
174174
// GetAppTags - Returns an array of all tag groups for an app.
175175
// Within a group, all tags point to the same app state (as a result of moving tags).
176176
//
177-
// https://wit.ai/docs/http/20200513/#get__apps__app_tags_link
177+
// https://wit.ai/docs/http/#get__apps__app_tags_link
178178
func (c *Client) GetAppTags(appID string) ([][]AppTag, error) {
179179
resp, err := c.request(http.MethodGet, fmt.Sprintf("/apps/%s/tags", url.PathEscape(appID)), "application/json", nil)
180180
if err != nil {
@@ -191,7 +191,7 @@ func (c *Client) GetAppTags(appID string) ([][]AppTag, error) {
191191

192192
// GetAppTag - returns the detail of the specified tag.
193193
//
194-
// https://wit.ai/docs/http/20200513/#get__apps__app_tags__tag_link
194+
// https://wit.ai/docs/http/#get__apps__app_tags__tag_link
195195
func (c *Client) GetAppTag(appID, tagID string) (*AppTag, error) {
196196
resp, err := c.request(http.MethodGet, fmt.Sprintf("/apps/%s/tags/%s", url.PathEscape(appID), url.PathEscape(tagID)), "application/json", nil)
197197
if err != nil {
@@ -209,7 +209,7 @@ func (c *Client) GetAppTag(appID, tagID string) (*AppTag, error) {
209209
// CreateAppTag - Take a snapshot of the current app state, save it as a tag (version)
210210
// of the app. The name of the tag created will be returned in the response.
211211
//
212-
// https://wit.ai/docs/http/20200513/#post__apps__app_tags_link
212+
// https://wit.ai/docs/http/#post__apps__app_tags_link
213213
func (c *Client) CreateAppTag(appID string, tag string) (*AppTag, error) {
214214
type appTag struct {
215215
Tag string `json:"tag"`
@@ -237,14 +237,14 @@ func (c *Client) CreateAppTag(appID string, tag string) (*AppTag, error) {
237237
return &AppTag{Name: tmp.Tag}, nil
238238
}
239239

240-
// UpdateAppTagRequest - https://wit.ai/docs/http/20200513/#put__apps__app_tags__tag_link
240+
// UpdateAppTagRequest - https://wit.ai/docs/http/#put__apps__app_tags__tag_link
241241
type UpdateAppTagRequest struct {
242242
Tag string `json:"tag,omitempty"`
243243
Desc string `json:"desc,omitempty"`
244244
MoveTo string `json:"move_to,omitempty"`
245245
}
246246

247-
// UpdateAppTagResponse - https://wit.ai/docs/http/20200513/#put__apps__app_tags__tag_link
247+
// UpdateAppTagResponse - https://wit.ai/docs/http/#put__apps__app_tags__tag_link
248248
type UpdateAppTagResponse struct {
249249
Tag string `json:"tag,omitempty"`
250250
Desc string `json:"desc,omitempty"`
@@ -253,7 +253,7 @@ type UpdateAppTagResponse struct {
253253

254254
// UpdateAppTag - Update the tag's name or description
255255
//
256-
// https://wit.ai/docs/http/20200513/#put__apps__app_tags__tag_link
256+
// https://wit.ai/docs/http/#put__apps__app_tags__tag_link
257257
func (c *Client) UpdateAppTag(appID, tagID string, updated AppTag) (*AppTag, error) {
258258
type tag struct {
259259
Tag string `json:"tag,omitempty"`
@@ -286,7 +286,7 @@ type MovedAppTag struct {
286286

287287
// MoveAppTag - move the tag to point to another tag.
288288
//
289-
// https://wit.ai/docs/http/20200513/#put__apps__app_tags__tag_link
289+
// https://wit.ai/docs/http/#put__apps__app_tags__tag_link
290290
func (c *Client) MoveAppTag(appID, tagID string, to string, updated *AppTag) (*MovedAppTag, error) {
291291
type tag struct {
292292
Tag string `json:"tag,omitempty"`
@@ -320,7 +320,7 @@ func (c *Client) MoveAppTag(appID, tagID string, to string, updated *AppTag) (*M
320320

321321
// DeleteAppTag - Permanently delete the tag.
322322
//
323-
// https://wit.ai/docs/http/20200513/#delete__apps__app_tags__tag_link
323+
// https://wit.ai/docs/http/#delete__apps__app_tags__tag_link
324324
func (c *Client) DeleteAppTag(appID, tagID string) error {
325325
resp, err := c.request(http.MethodDelete, fmt.Sprintf("/apps/%s/tags/%s", url.PathEscape(appID), url.PathEscape(tagID)), "application/json", nil)
326326
if err == nil {

entity.go

+42-27
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
// Entity represents a wit-ai Entity.
1414
//
15-
// https://wit.ai/docs/http/20200513/#post__entities_link
15+
// https://wit.ai/docs/http/#post__entities_link
1616
type Entity struct {
1717
ID string `json:"id"`
1818
Name string `json:"name"`
@@ -21,17 +21,30 @@ type Entity struct {
2121
Keywords []EntityKeyword `json:"keywords,omitempty"`
2222
}
2323

24+
type CreateEntityResponse struct {
25+
ID string `json:"id"`
26+
Name string `json:"name"`
27+
Lookups []string `json:"lookups,omitempty"`
28+
Roles []EntityRole `json:"roles,omitempty"`
29+
Keywords []EntityKeyword `json:"keywords,omitempty"`
30+
}
31+
32+
type EntityRole struct {
33+
ID string `json:"id"`
34+
Name string `json:"name"`
35+
}
36+
2437
// EntityKeyword is a keyword lookup for an Entity.
2538
//
26-
// https://wit.ai/docs/http/20200513/#post__entities__entity_keywords_link
39+
// https://wit.ai/docs/http/#post__entities__entity_keywords_link
2740
type EntityKeyword struct {
2841
Keyword string `json:"keyword"`
2942
Synonyms []string `json:"synonyms"`
3043
}
3144

3245
// GetEntities - returns list of entities.
3346
//
34-
// https://wit.ai/docs/http/20200513/#get__entities_link
47+
// https://wit.ai/docs/http/#get__entities_link
3548
func (c *Client) GetEntities() ([]Entity, error) {
3649
resp, err := c.request(http.MethodGet, "/entities", "application/json", nil)
3750
if err != nil {
@@ -48,8 +61,8 @@ func (c *Client) GetEntities() ([]Entity, error) {
4861

4962
// CreateEntity - Creates a new entity with the given attributes
5063
//
51-
// https://wit.ai/docs/http/20200513/#post__entities_link
52-
func (c *Client) CreateEntity(entity Entity) (*Entity, error) {
64+
// https://wit.ai/docs/http/#post__entities_link
65+
func (c *Client) CreateEntity(entity Entity) (*CreateEntityResponse, error) {
5366
entityJSON, err := json.Marshal(entity)
5467
if err != nil {
5568
return nil, err
@@ -62,54 +75,56 @@ func (c *Client) CreateEntity(entity Entity) (*Entity, error) {
6275

6376
defer resp.Close()
6477

65-
var entityResp *Entity
78+
var entityResp *CreateEntityResponse
6679
decoder := json.NewDecoder(resp)
6780
err = decoder.Decode(&entityResp)
6881
return entityResp, err
6982
}
7083

7184
// GetEntity - returns entity by ID or name.
7285
//
73-
// https://wit.ai/docs/http/20200513/#get__entities__entity_link
74-
func (c *Client) GetEntity(entityID string) (*Entity, error) {
86+
// https://wit.ai/docs/http/#get__entities__entity_link
87+
func (c *Client) GetEntity(entityID string) (*CreateEntityResponse, error) {
7588
resp, err := c.request(http.MethodGet, fmt.Sprintf("/entities/%s", url.PathEscape(entityID)), "application/json", nil)
7689
if err != nil {
7790
return nil, err
7891
}
7992

8093
defer resp.Close()
8194

82-
var entity *Entity
95+
var entity *CreateEntityResponse
8396
decoder := json.NewDecoder(resp)
8497
err = decoder.Decode(&entity)
8598
return entity, err
8699
}
87100

88-
// UpdateEntity - Updates an entity by ID or name.
101+
// UpdateEntity - Updates an entity by name.
89102
//
90-
// https://wit.ai/docs/http/20200513/#put__entities__entity_link
91-
func (c *Client) UpdateEntity(entityID string, entity Entity) error {
103+
// https://wit.ai/docs/http/#put__entities__entity_link
104+
func (c *Client) UpdateEntity(name string, entity Entity) (*CreateEntityResponse, error) {
92105
entityJSON, err := json.Marshal(entity)
93106
if err != nil {
94-
return err
107+
return nil, err
95108
}
96109

97-
resp, err := c.request(http.MethodPut, fmt.Sprintf("/entities/%s", url.PathEscape(entityID)), "application/json", bytes.NewBuffer(entityJSON))
110+
resp, err := c.request(http.MethodPut, fmt.Sprintf("/entities/%s", url.PathEscape(name)), "application/json", bytes.NewBuffer(entityJSON))
98111
if err != nil {
99-
return err
112+
return nil, err
100113
}
101114

102115
defer resp.Close()
103116

117+
var entityResp *CreateEntityResponse
104118
decoder := json.NewDecoder(resp)
105-
return decoder.Decode(&entity)
119+
err = decoder.Decode(&entityResp)
120+
return entityResp, err
106121
}
107122

108-
// DeleteEntity - deletes entity by ID or name.
123+
// DeleteEntity - deletes entity by name
109124
//
110-
// https://wit.ai/docs/http/20200513/#delete__entities__entity_link
111-
func (c *Client) DeleteEntity(entityID string) error {
112-
resp, err := c.request(http.MethodDelete, fmt.Sprintf("/entities/%s", url.PathEscape(entityID)), "application/json", nil)
125+
// https://wit.ai/docs/http/#delete__entities__entity_link
126+
func (c *Client) DeleteEntity(name string) error {
127+
resp, err := c.request(http.MethodDelete, fmt.Sprintf("/entities/%s", url.PathEscape(name)), "application/json", nil)
113128
if err == nil {
114129
resp.Close()
115130
}
@@ -119,9 +134,9 @@ func (c *Client) DeleteEntity(entityID string) error {
119134

120135
// DeleteEntityRole - deletes entity role.
121136
//
122-
// https://wit.ai/docs/http/20200513/#delete__entities__entity_role_link
123-
func (c *Client) DeleteEntityRole(entityID string, role string) error {
124-
resp, err := c.request(http.MethodDelete, fmt.Sprintf("/entities/%s:%s", url.PathEscape(entityID), url.PathEscape(role)), "application/json", nil)
137+
// https://wit.ai/docs/http/#delete__entities__entity_role_link
138+
func (c *Client) DeleteEntityRole(name string, role string) error {
139+
resp, err := c.request(http.MethodDelete, fmt.Sprintf("/entities/%s:%s", url.PathEscape(name), url.PathEscape(role)), "application/json", nil)
125140
if err == nil {
126141
resp.Close()
127142
}
@@ -131,7 +146,7 @@ func (c *Client) DeleteEntityRole(entityID string, role string) error {
131146

132147
// AddEntityKeyword - Add a possible value into the list of values for the keyword entity.
133148
//
134-
// https://wit.ai/docs/http/20200513/#post__entities__entity_keywords_link
149+
// https://wit.ai/docs/http/#post__entities__entity_keywords_link
135150
func (c *Client) AddEntityKeyword(entityID string, keyword EntityKeyword) (*Entity, error) {
136151
valueJSON, err := json.Marshal(keyword)
137152
if err != nil {
@@ -156,7 +171,7 @@ func (c *Client) AddEntityKeyword(entityID string, keyword EntityKeyword) (*Enti
156171

157172
// DeleteEntityKeyword - Delete a keyword from the keywords entity.
158173
//
159-
// https://wit.ai/docs/http/20200513/#delete__entities__entity_keywords__keyword_link
174+
// https://wit.ai/docs/http/#delete__entities__entity_keywords__keyword_link
160175
func (c *Client) DeleteEntityKeyword(entityID string, keyword string) error {
161176
resp, err := c.request(http.MethodDelete, fmt.Sprintf("/entities/%s/keywords/%s", url.PathEscape(entityID), url.PathEscape(keyword)), "application/json", nil)
162177
if err == nil {
@@ -168,7 +183,7 @@ func (c *Client) DeleteEntityKeyword(entityID string, keyword string) error {
168183

169184
// AddEntityKeywordSynonym - Create a new synonym of the canonical value of the keywords entity.
170185
//
171-
// https://wit.ai/docs/http/20200513/#post__entities__entity_keywords__keyword_synonyms_link
186+
// https://wit.ai/docs/http/#post__entities__entity_keywords__keyword_synonyms_link
172187
func (c *Client) AddEntityKeywordSynonym(entityID string, keyword string, synonym string) (*Entity, error) {
173188
type syn struct {
174189
Synonym string `json:"synonym"`
@@ -199,7 +214,7 @@ func (c *Client) AddEntityKeywordSynonym(entityID string, keyword string, synony
199214

200215
// DeleteEntityKeywordSynonym - Delete a synonym of the keyword of the entity.
201216
//
202-
// https://wit.ai/docs/http/20200513/#delete__entities__entity_keywords__keyword_synonyms__synonym_link
217+
// https://wit.ai/docs/http/#delete__entities__entity_keywords__keyword_synonyms__synonym_link
203218
func (c *Client) DeleteEntityKeywordSynonym(entityID string, keyword string, expression string) error {
204219
resp, err := c.request(http.MethodDelete, fmt.Sprintf("/entities/%s/keywords/%s/synonyms/%s", url.PathEscape(entityID), url.PathEscape(keyword), url.PathEscape(expression)), "application/json", nil)
205220
if err == nil {

0 commit comments

Comments
 (0)