Add request DialogsTagsAdd and DialogTagsDelete

This commit is contained in:
Vragov Roman 2024-02-20 19:00:54 +03:00
parent 4058284e32
commit ae8c5793dc
3 changed files with 129 additions and 0 deletions

View File

@ -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:

View File

@ -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()

View File

@ -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
@ -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"`