Merge pull request #69 from DmitryZagorulko/master
file caption in text field
This commit is contained in:
commit
9c82beba79
4
go.mod
4
go.mod
@ -44,8 +44,8 @@ require (
|
|||||||
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7
|
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7
|
||||||
github.com/pkg/errors v0.8.0
|
github.com/pkg/errors v0.8.0
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
github.com/retailcrm/api-client-go v1.1.0
|
github.com/retailcrm/api-client-go v1.1.1
|
||||||
github.com/retailcrm/mg-transport-api-client-go v1.1.24
|
github.com/retailcrm/mg-transport-api-client-go v1.1.26
|
||||||
github.com/smartystreets/assertions v0.0.0-20180820201707-7c9eb446e3cf // indirect
|
github.com/smartystreets/assertions v0.0.0-20180820201707-7c9eb446e3cf // indirect
|
||||||
github.com/smartystreets/goconvey v0.0.0-20180222194500-ef6db91d284a // indirect
|
github.com/smartystreets/goconvey v0.0.0-20180222194500-ef6db91d284a // indirect
|
||||||
github.com/stevvooe/resumable v0.0.0-20180830230917-22b14a53ba50 // indirect
|
github.com/stevvooe/resumable v0.0.0-20180830230917-22b14a53ba50 // indirect
|
||||||
|
4
go.sum
4
go.sum
@ -95,8 +95,12 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
|
|||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/retailcrm/api-client-go v1.1.0 h1:APPO6ccJAeMV7Jz7BhrtDKSOm2r1j5Ft6fuEXNP2ij4=
|
github.com/retailcrm/api-client-go v1.1.0 h1:APPO6ccJAeMV7Jz7BhrtDKSOm2r1j5Ft6fuEXNP2ij4=
|
||||||
github.com/retailcrm/api-client-go v1.1.0/go.mod h1:QRoPE2SM6ST7i2g0yEdqm7Iw98y7cYuq3q14Ot+6N8c=
|
github.com/retailcrm/api-client-go v1.1.0/go.mod h1:QRoPE2SM6ST7i2g0yEdqm7Iw98y7cYuq3q14Ot+6N8c=
|
||||||
|
github.com/retailcrm/api-client-go v1.1.1 h1:yqsyYjBDdmDwExVlTdGucY9/IpEokXpkfTfA6z5AZ7M=
|
||||||
|
github.com/retailcrm/api-client-go v1.1.1/go.mod h1:QRoPE2SM6ST7i2g0yEdqm7Iw98y7cYuq3q14Ot+6N8c=
|
||||||
github.com/retailcrm/mg-transport-api-client-go v1.1.24 h1:8VdiyhCYgEhKwlXvvuJdsOMquNXEcqtHBVzDojNHxNg=
|
github.com/retailcrm/mg-transport-api-client-go v1.1.24 h1:8VdiyhCYgEhKwlXvvuJdsOMquNXEcqtHBVzDojNHxNg=
|
||||||
github.com/retailcrm/mg-transport-api-client-go v1.1.24/go.mod h1:AWV6BueE28/6SCoyfKURTo4lF0oXYoOKmHTzehd5vAI=
|
github.com/retailcrm/mg-transport-api-client-go v1.1.24/go.mod h1:AWV6BueE28/6SCoyfKURTo4lF0oXYoOKmHTzehd5vAI=
|
||||||
|
github.com/retailcrm/mg-transport-api-client-go v1.1.26 h1:eZJOg7jKbsp1Mo8zSPx+XSWLYJ654jsl4zyHstk4DkQ=
|
||||||
|
github.com/retailcrm/mg-transport-api-client-go v1.1.26/go.mod h1:AWV6BueE28/6SCoyfKURTo4lF0oXYoOKmHTzehd5vAI=
|
||||||
github.com/smartystreets/assertions v0.0.0-20180820201707-7c9eb446e3cf h1:6V1qxN6Usn4jy8unvggSJz/NC790tefw8Zdy6OZS5co=
|
github.com/smartystreets/assertions v0.0.0-20180820201707-7c9eb446e3cf h1:6V1qxN6Usn4jy8unvggSJz/NC790tefw8Zdy6OZS5co=
|
||||||
github.com/smartystreets/assertions v0.0.0-20180820201707-7c9eb446e3cf/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
|
github.com/smartystreets/assertions v0.0.0-20180820201707-7c9eb446e3cf/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
|
||||||
github.com/smartystreets/goconvey v0.0.0-20180222194500-ef6db91d284a h1:JSvGDIbmil4Ui/dDdFBExb7/cmkNjyX5F97oglmvCDo=
|
github.com/smartystreets/goconvey v0.0.0-20180222194500-ef6db91d284a h1:JSvGDIbmil4Ui/dDdFBExb7/cmkNjyX5F97oglmvCDo=
|
||||||
|
@ -705,7 +705,7 @@ func mgWebhookHandler(c *gin.Context) {
|
|||||||
case v1.MsgTypeText:
|
case v1.MsgTypeText:
|
||||||
mb = replaceMarkdownSymbols(msg.Data.Content)
|
mb = replaceMarkdownSymbols(msg.Data.Content)
|
||||||
case v1.MsgTypeImage:
|
case v1.MsgTypeImage:
|
||||||
m, err = photoMessage(*msg.Data.Items, mgClient, cid)
|
m, err = photoMessage(msg.Data, mgClient, cid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Errorf(
|
logger.Errorf(
|
||||||
"GetFile request apiURL: %s, clientID: %s, err: %s",
|
"GetFile request apiURL: %s, clientID: %s, err: %s",
|
||||||
@ -911,7 +911,9 @@ func getOrderMessage(dataOrder *v1.MessageDataOrder) string {
|
|||||||
return mb
|
return mb
|
||||||
}
|
}
|
||||||
|
|
||||||
func photoMessage(items []v1.FileItem, mgClient *v1.MgClient, cid int64) (chattable tgbotapi.Chattable, err error) {
|
func photoMessage(webhookData v1.WebhookData, mgClient *v1.MgClient, cid int64) (chattable tgbotapi.Chattable, err error) {
|
||||||
|
items := *webhookData.Items
|
||||||
|
|
||||||
if len(items) == 1 {
|
if len(items) == 1 {
|
||||||
v := items
|
v := items
|
||||||
|
|
||||||
@ -923,7 +925,7 @@ func photoMessage(items []v1.FileItem, mgClient *v1.MgClient, cid int64) (chatta
|
|||||||
msg := tgbotapi.NewPhotoUpload(cid, nil)
|
msg := tgbotapi.NewPhotoUpload(cid, nil)
|
||||||
msg.FileID = file.Url
|
msg.FileID = file.Url
|
||||||
msg.UseExisting = true
|
msg.UseExisting = true
|
||||||
msg.Caption = v[0].Caption
|
msg.Caption = webhookData.Content
|
||||||
|
|
||||||
chattable = msg
|
chattable = msg
|
||||||
} else if len(items) > 1 {
|
} else if len(items) > 1 {
|
||||||
@ -940,7 +942,7 @@ func photoMessage(items []v1.FileItem, mgClient *v1.MgClient, cid int64) (chatta
|
|||||||
}
|
}
|
||||||
|
|
||||||
ip := tgbotapi.NewInputMediaPhoto(file.Url)
|
ip := tgbotapi.NewInputMediaPhoto(file.Url)
|
||||||
ip.Caption = v.Caption
|
ip.Caption = webhookData.Content
|
||||||
it = append(it, ip)
|
it = append(it, ip)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -993,7 +995,6 @@ func setAttachment(attachments *tgbotapi.Message, client *v1.MgClient, snd *v1.S
|
|||||||
var (
|
var (
|
||||||
items []v1.Item
|
items []v1.Item
|
||||||
fileID string
|
fileID string
|
||||||
caption string
|
|
||||||
)
|
)
|
||||||
|
|
||||||
t := getMessageID(attachments)
|
t := getMessageID(attachments)
|
||||||
@ -1002,6 +1003,8 @@ func setAttachment(attachments *tgbotapi.Message, client *v1.MgClient, snd *v1.S
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
caption := getLocalizedMessage(t)
|
||||||
|
|
||||||
switch t {
|
switch t {
|
||||||
case "photo":
|
case "photo":
|
||||||
for _, v := range *attachments.Photo {
|
for _, v := range *attachments.Photo {
|
||||||
@ -1009,7 +1012,6 @@ func setAttachment(attachments *tgbotapi.Message, client *v1.MgClient, snd *v1.S
|
|||||||
}
|
}
|
||||||
|
|
||||||
snd.Message.Type = v1.MsgTypeImage
|
snd.Message.Type = v1.MsgTypeImage
|
||||||
caption = attachments.Caption
|
|
||||||
case "document":
|
case "document":
|
||||||
fileID = attachments.Document.FileID
|
fileID = attachments.Document.FileID
|
||||||
snd.Message.Type = v1.MsgTypeFile
|
snd.Message.Type = v1.MsgTypeFile
|
||||||
@ -1017,7 +1019,6 @@ func setAttachment(attachments *tgbotapi.Message, client *v1.MgClient, snd *v1.S
|
|||||||
case "sticker":
|
case "sticker":
|
||||||
fileID = attachments.Sticker.FileID
|
fileID = attachments.Sticker.FileID
|
||||||
snd.Message.Type = v1.MsgTypeImage
|
snd.Message.Type = v1.MsgTypeImage
|
||||||
caption = attachments.Caption
|
|
||||||
default:
|
default:
|
||||||
snd.Message.Text = getLocalizedMessage(t)
|
snd.Message.Text = getLocalizedMessage(t)
|
||||||
}
|
}
|
||||||
@ -1054,6 +1055,7 @@ func setAttachment(attachments *tgbotapi.Message, client *v1.MgClient, snd *v1.S
|
|||||||
|
|
||||||
if len(items) > 0 {
|
if len(items) > 0 {
|
||||||
snd.Message.Items = items
|
snd.Message.Items = items
|
||||||
|
snd.Message.Text = attachments.Caption
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user