mirror of
https://github.com/retailcrm/mg-bot-api-client-go.git
synced 2024-11-21 20:36:05 +03:00
Merge pull request #16 from gwinn/master
add product & order to message send
This commit is contained in:
commit
1387691d4c
@ -191,10 +191,11 @@ func TestMgClient_Messages(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMgClient_MessageSend(t *testing.T) {
|
func TestMgClient_MessageSendText(t *testing.T) {
|
||||||
c := client()
|
c := client()
|
||||||
i, err := strconv.ParseUint(os.Getenv("MG_BOT_CHAT"), 10, 64)
|
i, err := strconv.ParseUint(os.Getenv("MG_BOT_CHAT"), 10, 64)
|
||||||
message := MessageSendRequest{
|
message := MessageSendRequest{
|
||||||
|
Type: MsgTypeText,
|
||||||
Scope: "public",
|
Scope: "public",
|
||||||
Content: "test",
|
Content: "test",
|
||||||
ChatID: i,
|
ChatID: i,
|
||||||
@ -208,11 +209,42 @@ func TestMgClient_MessageSend(t *testing.T) {
|
|||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.NotEmpty(t, data.MessageID)
|
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) {
|
func TestMgClient_MessageEdit(t *testing.T) {
|
||||||
c := client()
|
c := client()
|
||||||
i, err := strconv.ParseUint(os.Getenv("MG_BOT_CHAT"), 10, 64)
|
i, err := strconv.ParseUint(os.Getenv("MG_BOT_CHAT"), 10, 64)
|
||||||
message := MessageSendRequest{
|
message := MessageSendRequest{
|
||||||
|
Type: MsgTypeText,
|
||||||
Scope: "public",
|
Scope: "public",
|
||||||
Content: "test",
|
Content: "test",
|
||||||
ChatID: i,
|
ChatID: i,
|
||||||
@ -243,6 +275,7 @@ func TestMgClient_MessageDelete(t *testing.T) {
|
|||||||
c := client()
|
c := client()
|
||||||
i, err := strconv.ParseUint(os.Getenv("MG_BOT_CHAT"), 10, 64)
|
i, err := strconv.ParseUint(os.Getenv("MG_BOT_CHAT"), 10, 64)
|
||||||
message := MessageSendRequest{
|
message := MessageSendRequest{
|
||||||
|
Type: MsgTypeText,
|
||||||
Scope: "public",
|
Scope: "public",
|
||||||
Content: "test",
|
Content: "test",
|
||||||
ChatID: i,
|
ChatID: i,
|
||||||
|
18
v1/types.go
18
v1/types.go
@ -42,6 +42,12 @@ const (
|
|||||||
|
|
||||||
BotRoleDistributor string = "distributor"
|
BotRoleDistributor string = "distributor"
|
||||||
BotRoleResponsible string = "responsible"
|
BotRoleResponsible string = "responsible"
|
||||||
|
|
||||||
|
MsgTypeText string = "text"
|
||||||
|
MsgTypeSystem string = "system"
|
||||||
|
MsgTypeCommand string = "command"
|
||||||
|
MsgTypeOrder string = "order"
|
||||||
|
MsgTypeProduct string = "product"
|
||||||
)
|
)
|
||||||
|
|
||||||
// MgClient type
|
// MgClient type
|
||||||
@ -136,10 +142,13 @@ type (
|
|||||||
}
|
}
|
||||||
|
|
||||||
MessageSendRequest struct {
|
MessageSendRequest struct {
|
||||||
Content string `url:"content,omitempty" json:"content"`
|
Type string `url:"type,omitempty" json:"type"`
|
||||||
Scope string `url:"scope,omitempty" json:"scope"`
|
Content string `url:"content,omitempty" json:"content"`
|
||||||
ChatID uint64 `url:"chat_id,omitempty" json:"chat_id"`
|
Product *MessageProduct `url:"product,omitempty" json:"product"`
|
||||||
QuoteMessageId uint64 `url:"quote_message_id,omitempty" json:"quote_message_id"`
|
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 {
|
MessageEditRequest struct {
|
||||||
@ -391,6 +400,7 @@ type (
|
|||||||
ID uint64 `json:"id"`
|
ID uint64 `json:"id"`
|
||||||
Avatar string `json:"avatar"`
|
Avatar string `json:"avatar"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
|
Name string `json:"name"`
|
||||||
FirstName string `json:"first_name,omitempty"`
|
FirstName string `json:"first_name,omitempty"`
|
||||||
LastName string `json:"last_name,omitempty"`
|
LastName string `json:"last_name,omitempty"`
|
||||||
Phone string `json:"phone,omitempty"`
|
Phone string `json:"phone,omitempty"`
|
||||||
|
Loading…
Reference in New Issue
Block a user