mirror of
https://github.com/retailcrm/mg-bot-api-client-go.git
synced 2024-11-21 20:36:05 +03:00
Add request DialogsTagsAdd
and DialogTagsDelete
This commit is contained in:
commit
9ee3653827
44
v1/client.go
44
v1/client.go
@ -427,6 +427,50 @@ func (c *MgClient) DialogClose(request uint64) (map[string]interface{}, int, err
|
|||||||
return resp, status, err
|
return resp, status, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DialogsTagsAdd allows to assign dialog to Bot or User
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
//
|
||||||
|
// var client = v1.New("https://demo.url", "09jIJ")
|
||||||
|
//
|
||||||
|
// data, status, err := client.DialogsTagsAdd(DialogTagsAddRequest{DialogID: uint64(1),Tags: []TagsAdd{{Name: "foo"}}})
|
||||||
|
func (c *MgClient) DialogsTagsAdd(request DialogTagsAddRequest) (int, error) {
|
||||||
|
outgoing, _ := json.Marshal(&request)
|
||||||
|
|
||||||
|
data, status, err := c.PatchRequest(fmt.Sprintf("/dialogs/%d/tags/add", request.DialogID), outgoing)
|
||||||
|
if err != nil {
|
||||||
|
return status, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if status != http.StatusOK {
|
||||||
|
return status, c.Error(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
return status, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// DialogTagsDelete allows to assign dialog to Bot or User
|
||||||
|
//
|
||||||
|
// Example:
|
||||||
|
//
|
||||||
|
// var client = v1.New("https://demo.url", "09jIJ")
|
||||||
|
//
|
||||||
|
// data, status, err := client.DialogsTagsAdd(DialogTagsDelete{DialogID: uint64(1),Tags: []TagsDelete{{Name: "foo"}}})
|
||||||
|
func (c *MgClient) DialogTagsDelete(request DialogTagsDeleteRequest) (int, error) {
|
||||||
|
outgoing, _ := json.Marshal(&request)
|
||||||
|
|
||||||
|
data, status, err := c.PatchRequest(fmt.Sprintf("/dialogs/%d/tags/delete", request.DialogID), outgoing)
|
||||||
|
if err != nil {
|
||||||
|
return status, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if status != http.StatusOK {
|
||||||
|
return status, c.Error(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
return status, err
|
||||||
|
}
|
||||||
|
|
||||||
// Messages get all available messages
|
// Messages get all available messages
|
||||||
//
|
//
|
||||||
// Example:
|
// Example:
|
||||||
|
@ -473,6 +473,59 @@ func TestMgClient_DialogClose(t *testing.T) {
|
|||||||
assert.Equal(t, http.StatusBadRequest, status)
|
assert.Equal(t, http.StatusBadRequest, status)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMgClient_DialogsTagsAdd(t *testing.T) {
|
||||||
|
c := client()
|
||||||
|
|
||||||
|
color := ColorBlue
|
||||||
|
req := DialogTagsAddRequest{
|
||||||
|
DialogID: uint64(1),
|
||||||
|
Tags: []TagsAdd{
|
||||||
|
{Name: "foo", ColorCode: nil},
|
||||||
|
{Name: "bar", ColorCode: &color},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
r, _ := json.Marshal(req)
|
||||||
|
|
||||||
|
defer gock.Off()
|
||||||
|
|
||||||
|
gock.New(mgURL).
|
||||||
|
Patch("/api/bot/v1/dialogs/1/tags/add").
|
||||||
|
JSON(r).
|
||||||
|
Reply(200).
|
||||||
|
BodyString(`{}`)
|
||||||
|
|
||||||
|
status, err := c.DialogsTagsAdd(req)
|
||||||
|
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, http.StatusOK, status)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMgClient_DialogsTagsDelete(t *testing.T) {
|
||||||
|
c := client()
|
||||||
|
|
||||||
|
req := DialogTagsDeleteRequest{
|
||||||
|
DialogID: uint64(1),
|
||||||
|
Tags: []TagsDelete{
|
||||||
|
{Name: "foo"},
|
||||||
|
{Name: "bar"},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
r, _ := json.Marshal(req)
|
||||||
|
|
||||||
|
defer gock.Off()
|
||||||
|
|
||||||
|
gock.New(mgURL).
|
||||||
|
Patch("/api/bot/v1/dialogs/1/tags/delete").
|
||||||
|
JSON(r).
|
||||||
|
Reply(200).
|
||||||
|
BodyString(`{}`)
|
||||||
|
|
||||||
|
status, err := c.DialogTagsDelete(req)
|
||||||
|
|
||||||
|
assert.NoError(t, err)
|
||||||
|
assert.Equal(t, http.StatusOK, status)
|
||||||
|
}
|
||||||
|
|
||||||
func TestMgClient_Messages(t *testing.T) {
|
func TestMgClient_Messages(t *testing.T) {
|
||||||
c := client()
|
c := client()
|
||||||
|
|
||||||
|
32
v1/types.go
32
v1/types.go
@ -76,6 +76,19 @@ const (
|
|||||||
SuggestionTypeText = "text"
|
SuggestionTypeText = "text"
|
||||||
SuggestionTypeEmail = "email"
|
SuggestionTypeEmail = "email"
|
||||||
SuggestionTypePhone = "phone"
|
SuggestionTypePhone = "phone"
|
||||||
|
|
||||||
|
ColorLightRed = "light-red"
|
||||||
|
ColorLightBlue = "light-blue"
|
||||||
|
ColorLightGreen = "light-green"
|
||||||
|
ColorLightOrange = "light-orange"
|
||||||
|
ColorLightGray = "light-gray"
|
||||||
|
ColorLightGrayishBlue = "light-grayish-blue"
|
||||||
|
ColorRed = "red"
|
||||||
|
ColorBlue = "blue"
|
||||||
|
ColorGreen = "green"
|
||||||
|
ColorOrange = "orange"
|
||||||
|
ColorGray = "gray"
|
||||||
|
ColorGrayishBlue = "grayish-blue"
|
||||||
)
|
)
|
||||||
|
|
||||||
// MgClient type
|
// MgClient type
|
||||||
@ -166,6 +179,25 @@ type (
|
|||||||
BotID uint64 `url:"bot_id,omitempty" json:"bot_id"`
|
BotID uint64 `url:"bot_id,omitempty" json:"bot_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DialogTagsAddRequest struct {
|
||||||
|
DialogID uint64 `url:"dialog_id,omitempty"`
|
||||||
|
Tags []TagsAdd `json:"tags"`
|
||||||
|
}
|
||||||
|
|
||||||
|
TagsAdd struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
ColorCode *string `json:"color_code"`
|
||||||
|
}
|
||||||
|
|
||||||
|
DialogTagsDeleteRequest struct {
|
||||||
|
DialogID uint64 `url:"dialog_id,omitempty"`
|
||||||
|
Tags []TagsDelete `json:"tags"`
|
||||||
|
}
|
||||||
|
|
||||||
|
TagsDelete struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
}
|
||||||
|
|
||||||
MessagesRequest struct {
|
MessagesRequest struct {
|
||||||
ID []int `url:"id,omitempty"`
|
ID []int `url:"id,omitempty"`
|
||||||
ChatID uint64 `url:"chat_id,omitempty" json:"chat_id"`
|
ChatID uint64 `url:"chat_id,omitempty" json:"chat_id"`
|
||||||
|
Loading…
Reference in New Issue
Block a user