improve product transfer
This commit is contained in:
parent
8343a606ff
commit
4ffebf56fb
2
go.mod
2
go.mod
@ -44,7 +44,7 @@ require (
|
|||||||
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.0.6
|
github.com/retailcrm/api-client-go v1.0.6
|
||||||
github.com/retailcrm/mg-transport-api-client-go v1.1.6
|
github.com/retailcrm/mg-transport-api-client-go v1.1.7
|
||||||
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
|
||||||
|
2
go.sum
2
go.sum
@ -95,6 +95,8 @@ github.com/retailcrm/api-client-go v1.0.6 h1:4Q3e4ve8GOOHIQdq3/wTGqgWuWa1cKMKqmg
|
|||||||
github.com/retailcrm/api-client-go v1.0.6/go.mod h1:QRoPE2SM6ST7i2g0yEdqm7Iw98y7cYuq3q14Ot+6N8c=
|
github.com/retailcrm/api-client-go v1.0.6/go.mod h1:QRoPE2SM6ST7i2g0yEdqm7Iw98y7cYuq3q14Ot+6N8c=
|
||||||
github.com/retailcrm/mg-transport-api-client-go v1.1.6 h1:bwBs+iJbJzTAUFbkz+LmOhpruYebrI26haPPzBlZaRU=
|
github.com/retailcrm/mg-transport-api-client-go v1.1.6 h1:bwBs+iJbJzTAUFbkz+LmOhpruYebrI26haPPzBlZaRU=
|
||||||
github.com/retailcrm/mg-transport-api-client-go v1.1.6/go.mod h1:AWV6BueE28/6SCoyfKURTo4lF0oXYoOKmHTzehd5vAI=
|
github.com/retailcrm/mg-transport-api-client-go v1.1.6/go.mod h1:AWV6BueE28/6SCoyfKURTo4lF0oXYoOKmHTzehd5vAI=
|
||||||
|
github.com/retailcrm/mg-transport-api-client-go v1.1.7 h1:dKm2hhR6l1kQvYKjD50C4/W9EzfV6t6YVdhLxSExooU=
|
||||||
|
github.com/retailcrm/mg-transport-api-client-go v1.1.7/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=
|
||||||
|
@ -3,7 +3,6 @@ package main
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/nicksnyder/go-i18n/v2/i18n"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
@ -487,7 +486,26 @@ func mgWebhookHandler(c *gin.Context) {
|
|||||||
|
|
||||||
switch msg.Type {
|
switch msg.Type {
|
||||||
case "message_sent":
|
case "message_sent":
|
||||||
m := tgbotapi.NewMessage(cid, msg.Data.Content)
|
var mb string
|
||||||
|
if msg.Data.Type == v1.MsgTypeProduct {
|
||||||
|
mb = msg.Data.Product.Name
|
||||||
|
if msg.Data.Product.Cost != nil && msg.Data.Product.Cost.Value != 0 {
|
||||||
|
mb += fmt.Sprintf(
|
||||||
|
"\n%v %s",
|
||||||
|
msg.Data.Product.Cost.Value,
|
||||||
|
msg.Data.Product.Cost.Currency,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if msg.Data.Product.Img != "" {
|
||||||
|
mb = fmt.Sprintf("\n%s", msg.Data.Product.Img)
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
mb = msg.Data.Content
|
||||||
|
}
|
||||||
|
|
||||||
|
m := tgbotapi.NewMessage(cid, mb)
|
||||||
|
|
||||||
if msg.Data.QuoteExternalID != "" {
|
if msg.Data.QuoteExternalID != "" {
|
||||||
qid, err := strconv.Atoi(msg.Data.QuoteExternalID)
|
qid, err := strconv.Atoi(msg.Data.QuoteExternalID)
|
||||||
@ -538,41 +556,6 @@ func mgWebhookHandler(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
c.JSON(http.StatusOK, gin.H{})
|
c.JSON(http.StatusOK, gin.H{})
|
||||||
case "product":
|
|
||||||
mb := msg.Data.Product.Url
|
|
||||||
mb += "\n" + msg.Data.Product.Name
|
|
||||||
|
|
||||||
if msg.Data.Product.Cost != nil && msg.Data.Product.Cost.Value != 0 {
|
|
||||||
mb += "\n" + localizer.MustLocalize(&i18n.LocalizeConfig{
|
|
||||||
MessageID: "missing_credentials",
|
|
||||||
TemplateData: map[string]interface{}{
|
|
||||||
"Value": msg.Data.Product.Cost.Value,
|
|
||||||
"Currency": msg.Data.Product.Cost.Currency,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
m := tgbotapi.NewMessage(cid, msg.Data.Content)
|
|
||||||
|
|
||||||
if msg.Data.QuoteExternalID != "" {
|
|
||||||
qid, err := strconv.Atoi(msg.Data.QuoteExternalID)
|
|
||||||
if err != nil {
|
|
||||||
c.Error(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
m.ReplyToMessageID = qid
|
|
||||||
}
|
|
||||||
|
|
||||||
msgSend, err := bot.Send(m)
|
|
||||||
if err != nil {
|
|
||||||
logger.Error(err)
|
|
||||||
c.AbortWithStatus(http.StatusBadRequest)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if config.Debug {
|
|
||||||
logger.Debugf("mgWebhookHandler sent %v", msgSend)
|
|
||||||
}
|
|
||||||
|
|
||||||
c.JSON(http.StatusOK, gin.H{"external_message_id": strconv.Itoa(msgSend.MessageID)})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,5 +41,3 @@ video: "[video]"
|
|||||||
voice: "[voice message]"
|
voice: "[voice message]"
|
||||||
photo: "[photo]"
|
photo: "[photo]"
|
||||||
undefined: "[undefined format of a message]"
|
undefined: "[undefined format of a message]"
|
||||||
|
|
||||||
cost: "Cost: {{.Value}} {{.Currency}}"
|
|
||||||
|
@ -41,5 +41,3 @@ video: "[video]"
|
|||||||
voice: "[mensaje de voz]"
|
voice: "[mensaje de voz]"
|
||||||
photo: "[foto]"
|
photo: "[foto]"
|
||||||
other: "[formato indefinido de mensaje]"
|
other: "[formato indefinido de mensaje]"
|
||||||
|
|
||||||
cost: "Costo: {{.Value}} {{.Currency}}"
|
|
||||||
|
@ -41,5 +41,3 @@ video: "[видео]"
|
|||||||
voice: "[голосовое сообщение]"
|
voice: "[голосовое сообщение]"
|
||||||
photo: "[изображение]"
|
photo: "[изображение]"
|
||||||
undefined: "[неопределенный формат сообщения]"
|
undefined: "[неопределенный формат сообщения]"
|
||||||
|
|
||||||
cost: "Цена: {{.Value}} {{.Currency}}"
|
|
||||||
|
Loading…
Reference in New Issue
Block a user