add feature, parse mod for product
This commit is contained in:
parent
4ffebf56fb
commit
883d606edc
2
go.mod
2
go.mod
@ -44,7 +44,7 @@ require (
|
||||
github.com/pkg/errors v0.8.0
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/retailcrm/api-client-go v1.0.6
|
||||
github.com/retailcrm/mg-transport-api-client-go v1.1.7
|
||||
github.com/retailcrm/mg-transport-api-client-go v1.1.8
|
||||
github.com/smartystreets/assertions v0.0.0-20180820201707-7c9eb446e3cf // indirect
|
||||
github.com/smartystreets/goconvey v0.0.0-20180222194500-ef6db91d284a // indirect
|
||||
github.com/stevvooe/resumable v0.0.0-20180830230917-22b14a53ba50 // indirect
|
||||
|
2
go.sum
2
go.sum
@ -97,6 +97,8 @@ github.com/retailcrm/mg-transport-api-client-go v1.1.6 h1:bwBs+iJbJzTAUFbkz+LmOh
|
||||
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/retailcrm/mg-transport-api-client-go v1.1.8 h1:xLfy9j0VrAoAQUUtB5LllIqPFDvJ9H1xuri34kfZPPY=
|
||||
github.com/retailcrm/mg-transport-api-client-go v1.1.8/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/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
|
||||
github.com/smartystreets/goconvey v0.0.0-20180222194500-ef6db91d284a h1:JSvGDIbmil4Ui/dDdFBExb7/cmkNjyX5F97oglmvCDo=
|
||||
|
@ -21,6 +21,14 @@ var (
|
||||
options Options
|
||||
parser = flags.NewParser(&options, flags.Default)
|
||||
rx = regexp.MustCompile(`/+$`)
|
||||
currency = map[string]string{
|
||||
"rub": "₽",
|
||||
"uah": "₴",
|
||||
"byr": "Br",
|
||||
"kzt": "₸",
|
||||
"usd": "$",
|
||||
"eur": "€",
|
||||
}
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@ -72,6 +73,10 @@ func addBotHandler(c *gin.Context) {
|
||||
Quoting: v1.ChannelFeatureBoth,
|
||||
Deleting: v1.ChannelFeatureReceive,
|
||||
},
|
||||
Product: v1.Product{
|
||||
Creating: v1.ChannelFeatureReceive,
|
||||
Editing: v1.ChannelFeatureReceive,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@ -488,12 +493,16 @@ func mgWebhookHandler(c *gin.Context) {
|
||||
case "message_sent":
|
||||
var mb string
|
||||
if msg.Data.Type == v1.MsgTypeProduct {
|
||||
mb = msg.Data.Product.Name
|
||||
mb = fmt.Sprintf(
|
||||
"[%s](%s)",
|
||||
msg.Data.Product.Name,
|
||||
msg.Data.Product.Url,
|
||||
)
|
||||
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,
|
||||
currency[strings.ToLower(msg.Data.Product.Cost.Currency)],
|
||||
)
|
||||
}
|
||||
|
||||
@ -506,6 +515,9 @@ func mgWebhookHandler(c *gin.Context) {
|
||||
}
|
||||
|
||||
m := tgbotapi.NewMessage(cid, mb)
|
||||
if msg.Data.Type == v1.MsgTypeProduct {
|
||||
m.ParseMode = "Markdown"
|
||||
}
|
||||
|
||||
if msg.Data.QuoteExternalID != "" {
|
||||
qid, err := strconv.Atoi(msg.Data.QuoteExternalID)
|
||||
|
Loading…
Reference in New Issue
Block a user