Skip to content

Commit

Permalink
Add request DialogsTagsAdd and DialogTagsDelete
Browse files Browse the repository at this point in the history
  • Loading branch information
Neur0toxine authored Feb 27, 2024
2 parents 4058284 + ae8c579 commit 9ee3653
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 0 deletions.
44 changes: 44 additions & 0 deletions v1/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,50 @@ func (c *MgClient) DialogClose(request uint64) (map[string]interface{}, int, 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
//
// Example:
Expand Down
53 changes: 53 additions & 0 deletions v1/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,59 @@ func TestMgClient_DialogClose(t *testing.T) {
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) {
c := client()

Expand Down
32 changes: 32 additions & 0 deletions v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,19 @@ const (
SuggestionTypeText = "text"
SuggestionTypeEmail = "email"
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
Expand Down Expand Up @@ -166,6 +179,25 @@ type (
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 {
ID []int `url:"id,omitempty"`
ChatID uint64 `url:"chat_id,omitempty" json:"chat_id"`
Expand Down

0 comments on commit 9ee3653

Please sign in to comment.