mirror of
https://github.com/retailcrm/mg-bot-api-client-go.git
synced 2024-11-21 12:26:06 +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()
|
||||
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,
|
||||
|
18
v1/types.go
18
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"`
|
||||
|
Loading…
Reference in New Issue
Block a user