1
0
mirror of synced 2024-11-22 04:26:01 +03:00

file caption in text field

This commit is contained in:
DmitryZagorulko 2019-01-30 15:36:15 +03:00
parent a00509d1d4
commit eb787403b5

View File

@ -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)
} }
@ -991,9 +993,8 @@ func textMessage(cid int64, mb string, quoteExternalID string) (chattable tgbota
func setAttachment(attachments *tgbotapi.Message, client *v1.MgClient, snd *v1.SendData, botToken string) error { func setAttachment(attachments *tgbotapi.Message, client *v1.MgClient, snd *v1.SendData, botToken string) error {
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