mirror of
https://github.com/retailcrm/mg-bot-api-client-go.git
synced 2025-04-07 11:07:08 +00:00
Compare commits
No commits in common. "master" and "v1.5.19" have entirely different histories.
5 changed files with 143 additions and 305 deletions
18
.github/workflows/ci.yml
vendored
18
.github/workflows/ci.yml
vendored
|
@ -19,33 +19,33 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Check out code into the Go module directory
|
||||
uses: actions/checkout@v4
|
||||
- name: Set up Go 1.24
|
||||
uses: actions/setup-go@v5
|
||||
uses: actions/checkout@v2
|
||||
- name: Set up latest Go 1.x version
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: '1.24'
|
||||
go-version: '1.17'
|
||||
- name: Get dependencies
|
||||
run: |
|
||||
go mod tidy
|
||||
cp .env.dist .env
|
||||
- name: Lint code with golangci-lint
|
||||
uses: golangci/golangci-lint-action@v6
|
||||
uses: golangci/golangci-lint-action@v3
|
||||
with:
|
||||
version: v1.62.2
|
||||
version: v1.50.1
|
||||
only-new-issues: true
|
||||
tests:
|
||||
name: Tests
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
go-version: ['1.13', '1.14', '1.15', '1.16', '1.17', '1.18', '1.19', '1.20', '1.21', '1.22', '1.23', '1.24']
|
||||
go-version: ['1.13', '1.14', '1.15', '1.16']
|
||||
steps:
|
||||
- name: Set up Go ${{ matrix.go-version }}
|
||||
uses: actions/setup-go@v5
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: ${{ matrix.go-version }}
|
||||
- name: Check out code into the Go module directory
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v2
|
||||
- name: Get dependencies
|
||||
run: |
|
||||
go mod tidy
|
||||
|
|
|
@ -1,15 +1,31 @@
|
|||
run:
|
||||
skip-dirs-use-default: true
|
||||
allow-parallel-runners: true
|
||||
modules-download-mode: readonly
|
||||
|
||||
output:
|
||||
formats:
|
||||
- format: colored-line-number
|
||||
format: colored-line-number
|
||||
sort-results: true
|
||||
|
||||
# Linters below do not support go1.18 yet because of generics.
|
||||
# See https://github.com/golangci/golangci-lint/issues/2649
|
||||
# - bodyclose
|
||||
# - sqlclosecheck
|
||||
|
||||
linters:
|
||||
disable-all: true
|
||||
enable:
|
||||
- paralleltest
|
||||
- tparallel
|
||||
- asciicheck
|
||||
- asasalint
|
||||
- varnamelen
|
||||
- reassign
|
||||
- nilnil
|
||||
- nilerr
|
||||
- nakedret
|
||||
- goprintffuncname
|
||||
- typecheck
|
||||
- errchkjson
|
||||
- errcheck
|
||||
- gosimple
|
||||
- govet
|
||||
|
@ -17,12 +33,11 @@ linters:
|
|||
- staticcheck
|
||||
- unused
|
||||
- unparam
|
||||
- bodyclose
|
||||
- dogsled
|
||||
- dupl
|
||||
- errorlint
|
||||
- exhaustive
|
||||
- copyloopvar
|
||||
- exportloopref
|
||||
- funlen
|
||||
- gocognit
|
||||
- goconst
|
||||
|
@ -31,7 +46,6 @@ linters:
|
|||
- godot
|
||||
- goimports
|
||||
- revive
|
||||
- mnd
|
||||
- gosec
|
||||
- lll
|
||||
- makezero
|
||||
|
@ -39,21 +53,22 @@ linters:
|
|||
- nestif
|
||||
- prealloc
|
||||
- predeclared
|
||||
- sqlclosecheck
|
||||
- exportloopref
|
||||
- unconvert
|
||||
- whitespace
|
||||
- unused
|
||||
- testifylint
|
||||
|
||||
linters-settings:
|
||||
govet:
|
||||
check-shadowing: false
|
||||
disable-all: true
|
||||
enable:
|
||||
- assign
|
||||
- atomic
|
||||
- atomicalign
|
||||
- bools
|
||||
- buildtag
|
||||
- copylocks
|
||||
- fieldalignment
|
||||
- httpresponse
|
||||
- loopclosure
|
||||
- lostcancel
|
||||
|
@ -113,6 +128,8 @@ linters-settings:
|
|||
- log.Printf
|
||||
- log.Println
|
||||
- runtime/trace.Logf
|
||||
unused:
|
||||
check-exported: false
|
||||
unparam:
|
||||
check-exported: false
|
||||
dogsled:
|
||||
|
@ -121,8 +138,8 @@ linters-settings:
|
|||
threshold: 200
|
||||
errorlint:
|
||||
errorf: true
|
||||
asserts: true
|
||||
comparison: true
|
||||
asserts: false
|
||||
comparison: false
|
||||
exhaustive:
|
||||
check-generated: false
|
||||
default-signifies-exhaustive: false
|
||||
|
@ -144,23 +161,25 @@ linters-settings:
|
|||
whitespace:
|
||||
multi-if: false
|
||||
multi-func: false
|
||||
|
||||
varnamelen:
|
||||
max-distance: 10
|
||||
ignore-map-index-ok: true
|
||||
ignore-type-assert-ok: true
|
||||
ignore-chan-recv-ok: true
|
||||
ignore-decls:
|
||||
- t *testing.T
|
||||
- e error
|
||||
- i int
|
||||
issues:
|
||||
exclude-rules:
|
||||
- path: _test\.go
|
||||
linters:
|
||||
- dupl
|
||||
- mnd
|
||||
- lll
|
||||
- bodyclose
|
||||
- errcheck
|
||||
- sqlclosecheck
|
||||
- misspell
|
||||
- ineffassign
|
||||
- whitespace
|
||||
- makezero
|
||||
- maligned
|
||||
- ifshort
|
||||
- errcheck
|
||||
- funlen
|
||||
- goconst
|
||||
|
@ -168,6 +187,8 @@ issues:
|
|||
- gocyclo
|
||||
- godot
|
||||
- unused
|
||||
- errchkjson
|
||||
- varnamelen
|
||||
exclude-use-default: true
|
||||
exclude-case-sensitive: false
|
||||
max-issues-per-linter: 0
|
||||
|
@ -176,4 +197,7 @@ issues:
|
|||
|
||||
severity:
|
||||
default-severity: error
|
||||
case-sensitive: false
|
||||
case-sensitive: false
|
||||
|
||||
service:
|
||||
golangci-lint-version: 1.50.x
|
||||
|
|
45
v1/client.go
45
v1/client.go
|
@ -16,21 +16,21 @@ import (
|
|||
|
||||
type Option func(*MgClient)
|
||||
|
||||
// OptionHTTPClient set custom http.Client for MgClient.
|
||||
// OptionHTTPClient set custom http.Client for MgClient
|
||||
func OptionHTTPClient(client *http.Client) func(*MgClient) {
|
||||
return func(c *MgClient) {
|
||||
c.httpClient = client
|
||||
}
|
||||
}
|
||||
|
||||
// OptionLogger sets the provided logger instance into the MgClient.
|
||||
// OptionLogger sets the provided logger instance into the MgClient
|
||||
func OptionLogger(logger BasicLogger) func(*MgClient) {
|
||||
return func(c *MgClient) {
|
||||
c.logger = logger
|
||||
}
|
||||
}
|
||||
|
||||
// OptionDebug enables debug mode for MgClient.
|
||||
// OptionDebug enables debug mode for MgClient
|
||||
func OptionDebug() func(*MgClient) {
|
||||
return func(c *MgClient) {
|
||||
c.Debug = true
|
||||
|
@ -53,7 +53,7 @@ func New(url string, token string, opts ...Option) *MgClient {
|
|||
}
|
||||
|
||||
// WithLogger sets the provided logger instance into the Client.
|
||||
// Deprecated: Use functional option OptionLogger instead.
|
||||
// Deprecated: Use functional option OptionLogger instead
|
||||
func (c *MgClient) WithLogger(logger BasicLogger) *MgClient {
|
||||
c.logger = logger
|
||||
return c
|
||||
|
@ -912,43 +912,6 @@ func (c *MgClient) UploadFileByURL(request UploadFileByUrlRequest) (UploadFileRe
|
|||
return resp, status, err
|
||||
}
|
||||
|
||||
// UpdateFileMetadata update file metadata
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// response, status, err := c.UpdateFileMetadata(UploadFileByUrlRequest{
|
||||
// ID: "e038aa39-2338-4285-be86-e2a0bb424daa"
|
||||
// Transcription: "demo transcription",
|
||||
// })
|
||||
//
|
||||
// if err != nil {
|
||||
// fmt.Printf("%v", err)
|
||||
// }
|
||||
//
|
||||
// fmt.Printf("%s\n%s", response.ID, status)
|
||||
func (c *MgClient) UpdateFileMetadata(request UpdateFileMetadataRequest) (UploadFileResponse, int, error) {
|
||||
var resp UploadFileResponse
|
||||
outgoing, err := json.Marshal(&request)
|
||||
if err != nil {
|
||||
return resp, 0, err
|
||||
}
|
||||
|
||||
data, status, err := c.PutRequest(fmt.Sprintf("/files/%s/meta", request.ID), outgoing)
|
||||
if err != nil {
|
||||
return resp, status, err
|
||||
}
|
||||
|
||||
if status != http.StatusOK {
|
||||
return resp, status, c.Error(data)
|
||||
}
|
||||
|
||||
if e := json.Unmarshal(data, &resp); e != nil {
|
||||
return resp, status, e
|
||||
}
|
||||
|
||||
return resp, status, err
|
||||
}
|
||||
|
||||
type wsParams struct {
|
||||
options []string
|
||||
}
|
||||
|
|
|
@ -2,12 +2,8 @@ package v1
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/stretchr/testify/require"
|
||||
"io"
|
||||
"log"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
|
@ -73,7 +69,7 @@ func TestMgClient_Bots(t *testing.T) {
|
|||
t.Errorf("%d %v", status, err)
|
||||
}
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.NoError(t, err)
|
||||
assert.NotEmpty(t, data)
|
||||
|
||||
for _, bot := range data {
|
||||
|
@ -152,7 +148,7 @@ func TestMgClient_Channels(t *testing.T) {
|
|||
]`)
|
||||
|
||||
channels, status, err := c.Channels(ChannelsRequest{Active: 1})
|
||||
require.NoError(t, err)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, 200, status)
|
||||
assert.Len(t, channels, 1)
|
||||
|
||||
|
@ -225,7 +221,7 @@ func TestMgClient_Users(t *testing.T) {
|
|||
t.Errorf("%d %v", status, err)
|
||||
}
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.NoError(t, err)
|
||||
assert.NotEmpty(t, data)
|
||||
|
||||
for _, user := range data {
|
||||
|
@ -235,9 +231,9 @@ func TestMgClient_Users(t *testing.T) {
|
|||
assert.Equal(t, "Test", user.FirstName)
|
||||
assert.Equal(t, "Test", user.LastName)
|
||||
assert.Equal(t, "2018-01-01T00:00:00.000000Z", user.CreatedAt)
|
||||
assert.True(t, user.IsActive)
|
||||
assert.True(t, user.IsOnline)
|
||||
assert.True(t, user.IsTechnicalAccount)
|
||||
assert.Equal(t, true, user.IsActive)
|
||||
assert.Equal(t, true, user.IsOnline)
|
||||
assert.Equal(t, true, user.IsTechnicalAccount)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -292,7 +288,7 @@ func TestMgClient_Customers(t *testing.T) {
|
|||
t.Errorf("%d %v", status, err)
|
||||
}
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.NoError(t, err)
|
||||
assert.NotEmpty(t, data)
|
||||
|
||||
for _, customer := range data {
|
||||
|
@ -328,7 +324,7 @@ func TestMgClient_Chats(t *testing.T) {
|
|||
t.Errorf("%d %v", status, err)
|
||||
}
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.NoError(t, err)
|
||||
assert.NotEmpty(t, data)
|
||||
|
||||
for _, chat := range data {
|
||||
|
@ -353,7 +349,7 @@ func TestMgClient_Members(t *testing.T) {
|
|||
t.Errorf("%d %v", status, err)
|
||||
}
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.NoError(t, err)
|
||||
|
||||
for _, member := range data {
|
||||
assert.NotEmpty(t, member.ChatID)
|
||||
|
@ -377,7 +373,7 @@ func TestMgClient_Dialogs(t *testing.T) {
|
|||
t.Errorf("%d %v", status, err)
|
||||
}
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.NoError(t, err)
|
||||
assert.NotEmpty(t, data)
|
||||
|
||||
for _, dialog := range data {
|
||||
|
@ -419,7 +415,7 @@ func TestMgClient_DialogUnassign(t *testing.T) {
|
|||
|
||||
resp, status, err := c.DialogUnassign(777)
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, http.StatusOK, status)
|
||||
|
||||
assert.Equal(t, int64(111), resp.PreviousResponsible.ID)
|
||||
|
@ -504,7 +500,7 @@ func TestMgClient_DialogsTagsAdd(t *testing.T) {
|
|||
|
||||
status, err := c.DialogsTagsAdd(req)
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, http.StatusOK, status)
|
||||
}
|
||||
|
||||
|
@ -530,7 +526,7 @@ func TestMgClient_DialogsTagsDelete(t *testing.T) {
|
|||
|
||||
status, err := c.DialogTagsDelete(req)
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, http.StatusOK, status)
|
||||
}
|
||||
|
||||
|
@ -551,7 +547,7 @@ func TestMgClient_Messages(t *testing.T) {
|
|||
t.Errorf("%d %v", status, err)
|
||||
}
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.NoError(t, err)
|
||||
assert.NotEmpty(t, data)
|
||||
|
||||
for _, message := range data {
|
||||
|
@ -559,83 +555,6 @@ func TestMgClient_Messages(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestMgClient_MessagesDialog(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
c := client()
|
||||
|
||||
defer gock.Off()
|
||||
|
||||
gock.New(mgURL).
|
||||
Get("/api/bot/v1/messages").
|
||||
Reply(200).
|
||||
BodyString(`[
|
||||
{
|
||||
"id": 1,
|
||||
"time": "2024-11-14T20:48:21Z",
|
||||
"type": "system",
|
||||
"scope": "private",
|
||||
"chat_id": 1,
|
||||
"is_read": false,
|
||||
"is_edit": false,
|
||||
"status": "received",
|
||||
"dialog": {
|
||||
"id": 2054
|
||||
},
|
||||
"action": "dialog_closed",
|
||||
"channel_id": 71,
|
||||
"created_at": "2024-11-14T20:48:21.907566Z",
|
||||
"updated_at": "2024-11-14T20:48:21.907566Z"
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"time": "2024-11-14T19:58:42Z",
|
||||
"type": "text",
|
||||
"scope": "public",
|
||||
"chat_id": 1,
|
||||
"is_read": false,
|
||||
"is_edit": false,
|
||||
"status": "failed",
|
||||
"from": {
|
||||
"id": 1,
|
||||
"external_id": "1",
|
||||
"type": "user",
|
||||
"avatar": "http://avatars-test.jpeg",
|
||||
"name": "John Smith",
|
||||
"first_name": "John",
|
||||
"last_name": "Smith",
|
||||
"available": true
|
||||
},
|
||||
"dialog": {
|
||||
"id": 2054
|
||||
},
|
||||
"error": {
|
||||
"code": "malformed_response"
|
||||
},
|
||||
"content": "Message from user John Smith",
|
||||
"quote": null,
|
||||
"channel_id": 71,
|
||||
"created_at": "2024-11-14T19:58:42.933025Z",
|
||||
"updated_at": "2024-11-14T19:58:45.01619Z"
|
||||
}
|
||||
]`)
|
||||
|
||||
req := MessagesRequest{}
|
||||
|
||||
data, status, err := c.Messages(req)
|
||||
if err != nil {
|
||||
t.Errorf("%d %v", status, err)
|
||||
}
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, data, 2)
|
||||
|
||||
for _, m := range data {
|
||||
assert.NotNil(t, m.Message.Dialog)
|
||||
assert.Equal(t, uint64(2054), m.Message.Dialog.ID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMgClient_MessageSendText(t *testing.T) {
|
||||
c := client()
|
||||
|
||||
|
@ -660,7 +579,7 @@ func TestMgClient_MessageSendText(t *testing.T) {
|
|||
t.Errorf("%d %v", status, err)
|
||||
}
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.NoError(t, err)
|
||||
assert.NotEmpty(t, data.MessageID)
|
||||
}
|
||||
|
||||
|
@ -698,7 +617,7 @@ func TestMgClient_MessageSendTextWithSuggestions(t *testing.T) {
|
|||
t.Errorf("%d %v", status, err)
|
||||
}
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.NoError(t, err)
|
||||
assert.NotEmpty(t, data.MessageID)
|
||||
}
|
||||
|
||||
|
@ -739,7 +658,7 @@ func TestMgClient_MessageSendProduct(t *testing.T) {
|
|||
t.Errorf("%v", err)
|
||||
}
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.NoError(t, err)
|
||||
t.Logf("%v", msg)
|
||||
}
|
||||
|
||||
|
@ -799,7 +718,7 @@ func TestMgClient_MessageSendOrder(t *testing.T) {
|
|||
t.Errorf("%v", err)
|
||||
}
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.NoError(t, err)
|
||||
t.Logf("%v", msg)
|
||||
}
|
||||
|
||||
|
@ -868,7 +787,7 @@ func TestMgClient_Info(t *testing.T) {
|
|||
t.Errorf("%d %v", status, err)
|
||||
}
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestMgClient_Commands(t *testing.T) {
|
||||
|
@ -888,7 +807,7 @@ func TestMgClient_Commands(t *testing.T) {
|
|||
t.Errorf("%d %v", status, err)
|
||||
}
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.NoError(t, err)
|
||||
assert.NotEmpty(t, data)
|
||||
|
||||
for _, command := range data {
|
||||
|
@ -916,7 +835,7 @@ func TestMgClient_CommandEditDelete(t *testing.T) {
|
|||
t.Errorf("%d %v", status, err)
|
||||
}
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.NoError(t, err)
|
||||
assert.NotEmpty(t, n.ID)
|
||||
|
||||
gock.New(mgURL).
|
||||
|
@ -929,7 +848,7 @@ func TestMgClient_CommandEditDelete(t *testing.T) {
|
|||
t.Errorf("%d %v", status, err)
|
||||
}
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.NoError(t, err)
|
||||
t.Logf("%v", d)
|
||||
}
|
||||
|
||||
|
@ -960,7 +879,7 @@ func TestMgClient_WsMeta(t *testing.T) {
|
|||
t.Errorf("%v", err)
|
||||
}
|
||||
|
||||
resURL := fmt.Sprintf("%s%s%s%s", strings.Replace(c.URL, "https", "wss", 1), prefix, "/ws?events=", strings.Join(events, ","))
|
||||
resURL := fmt.Sprintf("%s%s%s%s", strings.Replace(c.URL, "https", "wss", 1), prefix, "/ws?events=", strings.Join(events[:], ","))
|
||||
resToken := c.Token
|
||||
|
||||
assert.Equal(t, resURL, url)
|
||||
|
@ -970,46 +889,13 @@ func TestMgClient_WsMeta(t *testing.T) {
|
|||
func TestMgClient_UploadFile(t *testing.T) {
|
||||
c := client()
|
||||
|
||||
defer gock.Off()
|
||||
gock.New("https://via.placeholder.com").
|
||||
Get("/300").
|
||||
Reply(http.StatusOK).
|
||||
SetHeader("Content-Type", "image/jpeg").
|
||||
Body(func() io.Reader {
|
||||
res, err := base64.StdEncoding.DecodeString(`
|
||||
H4sIAAAAAAACA/t/4/8DBgEvN083BkZGBgZGIGT4f5vBmYGVmYWFhZkVSLCysrKx83CwAwE/Nzcn
|
||||
jyC/kJAgv6CgsJiMuLCIlKigoISihJSsrLy8vLC4koqSnIqMnLwcyBBGoFZ2NnY+Dg4+ORFBETmS
|
||||
wf8DDIIcDAoMCsyMSgxMgozMgoz/jzDIA93JyggGDFDAyMTMAnQlBycXN1DBVgEGJkZmZiag+4Ee
|
||||
AMrWAuUZWARZhRQNHdmEAxPZlQpFjBonLuRQdtp4UDTo4gcV46SiJk4uMXEJSSlVNXUNTS0TUzNz
|
||||
C0srZxdXN3cPT6/gkNCw8IjIqOSU1LT0jMys4pLSsvKKyqrmlta29o7OrkmTp0ydNn3GzFmLFi9Z
|
||||
umz5ipWrNm3esnXb9h07dx06fOToseMnTp66dPnK1WvXb9y89fDR4ydPnz1/8fLVx0+fv3z99v3H
|
||||
z18gfzEyMDPCAFZ/CQL9xQSMFhZ2kL8YmcpBCgRZWBUN2YQcA9kTC4WVjBo5RJwmLtx4kFPZOOiD
|
||||
aFLRRS4xFZOHqh9BXgP7jDiPNZHlM7jHEP66xcDDzAiMPGZBBnuGH/fuKWs3sItefBlWa7FqV+h8
|
||||
P+01l9b8KnQQ27Labk545NLIL49WZwLl1m322vzyKEPFu6npl7temwAlQ3O1zi8XvQaSXMBtBdcZ
|
||||
itDYYP//JgDowAia0AIAAA==`)
|
||||
if err != nil {
|
||||
t.Errorf("%v", err)
|
||||
t.FailNow()
|
||||
return nil
|
||||
}
|
||||
|
||||
unpacker, err := gzip.NewReader(bytes.NewReader(res))
|
||||
if err != nil {
|
||||
t.Errorf("%v", err)
|
||||
t.FailNow()
|
||||
return nil
|
||||
}
|
||||
|
||||
return unpacker
|
||||
}())
|
||||
|
||||
resp, err := http.Get("https://via.placeholder.com/300")
|
||||
if err != nil {
|
||||
t.Errorf("%v", err)
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
defer gock.Off()
|
||||
|
||||
gock.New(mgURL).
|
||||
Post("/api/bot/v1/files/upload").
|
||||
|
@ -1047,7 +933,7 @@ func TestMgClient_UploadFileByUrl(t *testing.T) {
|
|||
|
||||
t.Logf("File %+v is upload", uploadFileResponse.ID)
|
||||
|
||||
require.NoError(t, err)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func RandStringBytesMaskImprSrc(n int) string {
|
||||
|
@ -1110,9 +996,9 @@ func TestMgClient_SuccessChatsByCustomerId(t *testing.T) {
|
|||
}
|
||||
|
||||
resp, statusCode, err := apiClient.Chats(chatsRequest)
|
||||
require.NoError(t, err)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, http.StatusOK, statusCode)
|
||||
assert.Len(t, resp, 1)
|
||||
assert.Equal(t, 1, len(resp))
|
||||
assert.Equal(t, uint64(9000), resp[0].ID)
|
||||
assert.Equal(t, uint64(8000), resp[0].Channel.ID)
|
||||
assert.Equal(t, customerID, resp[0].Customer.ID)
|
||||
|
|
155
v1/types.go
155
v1/types.go
|
@ -52,7 +52,6 @@ const (
|
|||
|
||||
BotRoleDistributor string = "distributor"
|
||||
BotRoleResponsible string = "responsible"
|
||||
BotRoleHidden string = "hidden"
|
||||
|
||||
MsgTypeText string = "text"
|
||||
MsgTypeSystem string = "system"
|
||||
|
@ -149,16 +148,15 @@ type (
|
|||
}
|
||||
|
||||
ChatsRequest struct {
|
||||
ID uint64 `url:"id,omitempty"`
|
||||
ChannelID uint64 `url:"channel_id,omitempty" json:"channel_id"`
|
||||
ChannelType string `url:"channel_type,omitempty" json:"channel_type"`
|
||||
CustomerID uint64 `url:"customer_id,omitempty" json:"customer_id"`
|
||||
CustomerExternalID string `url:"customer_external_id,omitempty" json:"customer_external_id"`
|
||||
Since string `url:"since,omitempty"`
|
||||
Until string `url:"until,omitempty"`
|
||||
Limit int `url:"limit,omitempty"`
|
||||
SinceID int `url:"since_id,omitempty"`
|
||||
IncludeMassCommunication uint8 `url:"include_mass_communication,omitempty"`
|
||||
ID uint64 `url:"id,omitempty"`
|
||||
ChannelID uint64 `url:"channel_id,omitempty" json:"channel_id"`
|
||||
ChannelType string `url:"channel_type,omitempty" json:"channel_type"`
|
||||
CustomerID uint64 `url:"customer_id,omitempty" json:"customer_id"`
|
||||
CustomerExternalID string `url:"customer_external_id,omitempty" json:"customer_external_id"`
|
||||
Since string `url:"since,omitempty"`
|
||||
Until string `url:"until,omitempty"`
|
||||
Limit int `url:"limit,omitempty"`
|
||||
SinceID int `url:"since_id,omitempty"`
|
||||
}
|
||||
|
||||
MembersRequest struct {
|
||||
|
@ -171,17 +169,16 @@ type (
|
|||
}
|
||||
|
||||
DialogsRequest struct {
|
||||
ID uint64 `url:"id,omitempty"`
|
||||
ChatID string `url:"chat_id,omitempty" json:"chat_id"`
|
||||
UserID string `url:"user_id,omitempty" json:"user_id"`
|
||||
BotID string `url:"bot_id,omitempty" json:"bot_id"`
|
||||
Assign uint8 `url:"assign,omitempty"`
|
||||
Active uint8 `url:"active,omitempty"`
|
||||
Since string `url:"since,omitempty"`
|
||||
SinceID int `url:"since_id,omitempty"`
|
||||
Until string `url:"until,omitempty"`
|
||||
Limit int `url:"limit,omitempty"`
|
||||
IncludeMassCommunication uint8 `url:"include_mass_communication,omitempty"`
|
||||
ID uint64 `url:"id,omitempty"`
|
||||
ChatID string `url:"chat_id,omitempty" json:"chat_id"`
|
||||
UserID string `url:"user_id,omitempty" json:"user_id"`
|
||||
BotID string `url:"bot_id,omitempty" json:"bot_id"`
|
||||
Assign uint8 `url:"assign,omitempty"`
|
||||
Active uint8 `url:"active,omitempty"`
|
||||
Since string `url:"since,omitempty"`
|
||||
SinceID int `url:"since_id,omitempty"`
|
||||
Until string `url:"until,omitempty"`
|
||||
Limit int `url:"limit,omitempty"`
|
||||
}
|
||||
|
||||
DialogAssignRequest struct {
|
||||
|
@ -210,20 +207,19 @@ type (
|
|||
}
|
||||
|
||||
MessagesRequest struct {
|
||||
ID []int `url:"id,omitempty"`
|
||||
ChatID uint64 `url:"chat_id,omitempty" json:"chat_id"`
|
||||
DialogID uint64 `url:"dialog_id,omitempty" json:"dialog_id"`
|
||||
UserID uint64 `url:"user_id,omitempty" json:"user_id"`
|
||||
CustomerID uint64 `url:"customer_id,omitempty" json:"customer_id"`
|
||||
BotID uint64 `url:"bot_id,omitempty" json:"bot_id"`
|
||||
ChannelID uint64 `url:"channel_id,omitempty" json:"channel_id"`
|
||||
ChannelType string `url:"channel_type,omitempty" json:"channel_type"`
|
||||
Scope string `url:"scope,omitempty"`
|
||||
Type string `url:"type,omitempty"`
|
||||
Since string `url:"since,omitempty"`
|
||||
Until string `url:"until,omitempty"`
|
||||
Limit int `url:"limit,omitempty"`
|
||||
IncludeMassCommunication uint8 `url:"include_mass_communication,omitempty"`
|
||||
ID []int `url:"id,omitempty"`
|
||||
ChatID uint64 `url:"chat_id,omitempty" json:"chat_id"`
|
||||
DialogID uint64 `url:"dialog_id,omitempty" json:"dialog_id"`
|
||||
UserID uint64 `url:"user_id,omitempty" json:"user_id"`
|
||||
CustomerID uint64 `url:"customer_id,omitempty" json:"customer_id"`
|
||||
BotID uint64 `url:"bot_id,omitempty" json:"bot_id"`
|
||||
ChannelID uint64 `url:"channel_id,omitempty" json:"channel_id"`
|
||||
ChannelType string `url:"channel_type,omitempty" json:"channel_type"`
|
||||
Scope string `url:"scope,omitempty"`
|
||||
Type string `url:"type,omitempty"`
|
||||
Since string `url:"since,omitempty"`
|
||||
Until string `url:"until,omitempty"`
|
||||
Limit int `url:"limit,omitempty"`
|
||||
}
|
||||
|
||||
MessageSendRequest struct {
|
||||
|
@ -274,13 +270,6 @@ type (
|
|||
UploadFileByUrlRequest struct {
|
||||
Url string `json:"url"`
|
||||
}
|
||||
|
||||
UpdateFileMetadataRequest struct {
|
||||
ID string `json:"-"`
|
||||
Transcription string `json:"transcription,omitempty"`
|
||||
// Current status of transcription process. Available values: "in_progress", "ready", "error"
|
||||
TranscriptionStatus string `json:"transcription_status,omitempty"`
|
||||
}
|
||||
)
|
||||
|
||||
// Response types
|
||||
|
@ -347,18 +336,16 @@ type (
|
|||
}
|
||||
|
||||
ChatResponseItem struct {
|
||||
ID uint64 `json:"id"`
|
||||
Avatar string `json:"avatar"`
|
||||
Name string `json:"name"`
|
||||
Channel Channel `json:"channel,omitempty"`
|
||||
Customer UserRef `json:"customer"`
|
||||
AuthorID uint64 `json:"author_id"`
|
||||
LastMessage Message `json:"last_message"`
|
||||
LastUserMessage MessageID `json:"last_user_message"`
|
||||
LastActivity string `json:"last_activity"`
|
||||
LastDialog Dialog `json:"last_dialog"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
UpdatedAt string `json:"updated_at"`
|
||||
ID uint64 `json:"id"`
|
||||
Avatar string `json:"avatar"`
|
||||
Name string `json:"name"`
|
||||
Channel Channel `json:"channel,omitempty"`
|
||||
Customer UserRef `json:"customer"`
|
||||
AuthorID uint64 `json:"author_id"`
|
||||
LastMessage Message `json:"last_message"`
|
||||
LastActivity string `json:"last_activity"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
UpdatedAt string `json:"updated_at"`
|
||||
}
|
||||
|
||||
MemberResponseItem struct {
|
||||
|
@ -450,7 +437,7 @@ type (
|
|||
}
|
||||
)
|
||||
|
||||
// WS options.
|
||||
// WS options
|
||||
type (
|
||||
WsOption string
|
||||
)
|
||||
|
@ -470,16 +457,11 @@ type (
|
|||
From *UserRef `json:"from"`
|
||||
Product *MessageProduct `json:"product,omitempty"`
|
||||
Order *MessageOrder `json:"order,omitempty"`
|
||||
Dialog *MessageDialog `json:"dialog,omitempty"`
|
||||
*TextMessage
|
||||
*SystemMessage
|
||||
*AttachmentList
|
||||
}
|
||||
|
||||
MessageID struct {
|
||||
ID uint64 `json:"id"`
|
||||
}
|
||||
|
||||
TextMessage struct {
|
||||
Content string `json:"content"`
|
||||
Quote *QuoteMessage `json:"quote"`
|
||||
|
@ -487,22 +469,16 @@ type (
|
|||
}
|
||||
|
||||
SystemMessage struct {
|
||||
Action string `json:"action"`
|
||||
// Deprecated: Use Message.Dialog.ID instead.
|
||||
Action string `json:"action"`
|
||||
Dialog *SystemMessageDialog `json:"dialog,omitempty"`
|
||||
User *UserRef `json:"user,omitempty"`
|
||||
Responsible *UserRef `json:"responsible,omitempty"`
|
||||
}
|
||||
|
||||
// Deprecated: Use MessageDialog instead.
|
||||
SystemMessageDialog struct {
|
||||
ID uint64 `json:"id"`
|
||||
}
|
||||
|
||||
MessageDialog struct {
|
||||
ID uint64 `json:"id"`
|
||||
}
|
||||
|
||||
QuoteMessage struct {
|
||||
ID uint64 `json:"id"`
|
||||
Content string `json:"content"`
|
||||
|
@ -516,21 +492,13 @@ type (
|
|||
}
|
||||
|
||||
Attachment struct {
|
||||
File
|
||||
|
||||
Caption string `json:"caption"`
|
||||
}
|
||||
|
||||
File struct {
|
||||
PreviewURL *string `json:"preview_url,omitempty"`
|
||||
Height *uint64 `json:"height,omitempty"`
|
||||
Width *uint64 `json:"width,omitempty"`
|
||||
Transcription string `json:"transcription,omitempty"`
|
||||
ID string `json:"id"`
|
||||
Mime string `json:"type"`
|
||||
Type string `json:"kind"`
|
||||
Duration int `json:"duration,omitempty"`
|
||||
Size uint64 `json:"size"`
|
||||
ID string `json:"id"`
|
||||
Mime string `json:"type"`
|
||||
Caption string `json:"caption"`
|
||||
Size uint64 `json:"size"`
|
||||
PreviewURL *string `json:"preview_url,omitempty"`
|
||||
Height *uint64 `json:"height,omitempty"`
|
||||
Width *uint64 `json:"width,omitempty"`
|
||||
}
|
||||
|
||||
MessageProduct struct {
|
||||
|
@ -608,7 +576,6 @@ type (
|
|||
IsAdmin bool `json:"is_admin"`
|
||||
Available bool `json:"available"`
|
||||
IsTechnicalAccount bool `json:"is_technical_account"`
|
||||
IsSystem bool `json:"is_system"`
|
||||
}
|
||||
|
||||
Channel struct {
|
||||
|
@ -640,16 +607,15 @@ type (
|
|||
}
|
||||
|
||||
Chat struct {
|
||||
ID uint64 `json:"id"`
|
||||
Avatar string `json:"avatar"`
|
||||
Name string `json:"name"`
|
||||
Channel *Channel `json:"channel,omitempty"`
|
||||
Members []Member `json:"members"`
|
||||
Customer *UserRef `json:"customer"`
|
||||
AuthorID uint64 `json:"author_id"`
|
||||
LastMessage *Message `json:"last_message"`
|
||||
LastUserMessage *MessageID `json:"last_user_message"`
|
||||
LastActivity string `json:"last_activity"`
|
||||
ID uint64 `json:"id"`
|
||||
Avatar string `json:"avatar"`
|
||||
Name string `json:"name"`
|
||||
Channel *Channel `json:"channel,omitempty"`
|
||||
Members []Member `json:"members"`
|
||||
Customer *UserRef `json:"customer"`
|
||||
AuthorID uint64 `json:"author_id"`
|
||||
LastMessage *Message `json:"last_message"`
|
||||
LastActivity string `json:"last_activity"`
|
||||
}
|
||||
|
||||
WaitingChat struct {
|
||||
|
@ -672,7 +638,6 @@ type (
|
|||
Responsible *Responsible `json:"responsible"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
ClosedAt *string `json:"closed_at"`
|
||||
Utm *Utm `json:"utm,omitempty"`
|
||||
}
|
||||
|
||||
FileMeta struct {
|
||||
|
|
Loading…
Add table
Reference in a new issue