diff --git a/v1/client_test.go b/v1/client_test.go index 0e61583..6781cbd 100644 --- a/v1/client_test.go +++ b/v1/client_test.go @@ -191,10 +191,11 @@ func TestMgClient_Messages(t *testing.T) { } } -func TestMgClient_MessageSend(t *testing.T) { +func TestMgClient_MessageSendText(t *testing.T) { c := client() i, err := strconv.ParseUint(os.Getenv("MG_BOT_CHAT"), 10, 64) message := MessageSendRequest{ + Type: MsgTypeText, Scope: "public", Content: "test", ChatID: i, @@ -208,11 +209,42 @@ func TestMgClient_MessageSend(t *testing.T) { assert.NoError(t, err) assert.NotEmpty(t, data.MessageID) } +func TestMgClient_MessageSendProduct(t *testing.T) { + c := client() + + msg, _, err := c.MessageSend(MessageSendRequest{ + Type: MsgTypeProduct, + ChatID: 5, + Scope: "public", + Product: &MessageProduct{ + ID: 1, + Name: "Some Product", + Article: "Art-111", + Url: "https://example.com", + Img: "http://example.com/pic.jpg", + Cost: &MessageOrderCost{ + Value: 29900, + Currency: "rub", + }, + Quantity: &MessageOrderQuantity{ + Value: 1, + }, + }, + }) + + if err != nil { + t.Errorf("%v", err) + } + + assert.NoError(t, err) + t.Logf("%v", msg) +} func TestMgClient_MessageEdit(t *testing.T) { c := client() i, err := strconv.ParseUint(os.Getenv("MG_BOT_CHAT"), 10, 64) message := MessageSendRequest{ + Type: MsgTypeText, Scope: "public", Content: "test", ChatID: i, @@ -243,6 +275,7 @@ func TestMgClient_MessageDelete(t *testing.T) { c := client() i, err := strconv.ParseUint(os.Getenv("MG_BOT_CHAT"), 10, 64) message := MessageSendRequest{ + Type: MsgTypeText, Scope: "public", Content: "test", ChatID: i, diff --git a/v1/types.go b/v1/types.go index 1df5a2c..8bcd12e 100644 --- a/v1/types.go +++ b/v1/types.go @@ -42,6 +42,12 @@ const ( BotRoleDistributor string = "distributor" BotRoleResponsible string = "responsible" + + MsgTypeText string = "text" + MsgTypeSystem string = "system" + MsgTypeCommand string = "command" + MsgTypeOrder string = "order" + MsgTypeProduct string = "product" ) // MgClient type @@ -136,10 +142,13 @@ type ( } MessageSendRequest struct { - Content string `url:"content,omitempty" json:"content"` - Scope string `url:"scope,omitempty" json:"scope"` - ChatID uint64 `url:"chat_id,omitempty" json:"chat_id"` - QuoteMessageId uint64 `url:"quote_message_id,omitempty" json:"quote_message_id"` + Type string `url:"type,omitempty" json:"type"` + Content string `url:"content,omitempty" json:"content"` + Product *MessageProduct `url:"product,omitempty" json:"product"` + Order *MessageOrder `url:"order,omitempty" json:"order"` + Scope string `url:"scope,omitempty" json:"scope"` + ChatID uint64 `url:"chat_id,omitempty" json:"chat_id"` + QuoteMessageId uint64 `url:"quote_message_id,omitempty" json:"quote_message_id"` } MessageEditRequest struct { @@ -391,6 +400,7 @@ type ( ID uint64 `json:"id"` Avatar string `json:"avatar"` Type string `json:"type"` + Name string `json:"name"` FirstName string `json:"first_name,omitempty"` LastName string `json:"last_name,omitempty"` Phone string `json:"phone,omitempty"`