Merge pull request #16 from gwinn/master

add product & order to message send
This commit is contained in:
Alex Lushpai 2018-09-13 11:39:12 +03:00 committed by GitHub
commit 1387691d4c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 5 deletions

View File

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

View File

@ -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,7 +142,10 @@ type (
}
MessageSendRequest struct {
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"`
@ -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"`