1
0
mirror of synced 2024-11-26 21:56:02 +03:00

Merge pull request #35 from gwinn/release

Release
This commit is contained in:
Alex Lushpai 2018-09-13 21:59:02 +03:00 committed by GitHub
commit 8a1915165b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 59 additions and 16 deletions

2
go.mod
View File

@ -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.5 github.com/retailcrm/mg-transport-api-client-go v1.1.8
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

8
go.sum
View File

@ -93,8 +93,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.0.6 h1:4Q3e4ve8GOOHIQdq3/wTGqgWuWa1cKMKqmgrTv4FoDU= github.com/retailcrm/api-client-go v1.0.6 h1:4Q3e4ve8GOOHIQdq3/wTGqgWuWa1cKMKqmgrTv4FoDU=
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.5 h1:UCotZ5ONR/jvRf+QqjId6GPgByX1N5FvhPGHhTCAIvg= 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.5/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/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 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=

View File

@ -15,12 +15,20 @@ type Options struct {
} }
var ( var (
config *TransportConfig config *TransportConfig
orm *Orm orm *Orm
logger *logging.Logger logger *logging.Logger
options Options options Options
parser = flags.NewParser(&options, flags.Default) parser = flags.NewParser(&options, flags.Default)
rx = regexp.MustCompile(`/+$`) rx = regexp.MustCompile(`/+$`)
currency = map[string]string{
"rub": "₽",
"uah": "₴",
"byr": "Br",
"kzt": "₸",
"usd": "$",
"eur": "€",
}
) )
func main() { func main() {

View File

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"net/http" "net/http"
"strconv" "strconv"
"strings"
"time" "time"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
@ -72,6 +73,10 @@ func addBotHandler(c *gin.Context) {
Quoting: v1.ChannelFeatureBoth, Quoting: v1.ChannelFeatureBoth,
Deleting: v1.ChannelFeatureReceive, Deleting: v1.ChannelFeatureReceive,
}, },
Product: v1.Product{
Creating: v1.ChannelFeatureReceive,
Editing: v1.ChannelFeatureReceive,
},
}, },
} }
@ -484,8 +489,35 @@ func mgWebhookHandler(c *gin.Context) {
return return
} }
if msg.Type == "message_sent" { switch msg.Type {
m := tgbotapi.NewMessage(cid, msg.Data.Content) case "message_sent":
var mb string
if msg.Data.Type == v1.MsgTypeProduct {
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,
currency[strings.ToLower(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.Type == v1.MsgTypeProduct {
m.ParseMode = "Markdown"
}
if msg.Data.QuoteExternalID != "" { if msg.Data.QuoteExternalID != "" {
qid, err := strconv.Atoi(msg.Data.QuoteExternalID) qid, err := strconv.Atoi(msg.Data.QuoteExternalID)
@ -508,9 +540,8 @@ func mgWebhookHandler(c *gin.Context) {
} }
c.JSON(http.StatusOK, gin.H{"external_message_id": strconv.Itoa(msgSend.MessageID)}) c.JSON(http.StatusOK, gin.H{"external_message_id": strconv.Itoa(msgSend.MessageID)})
}
if msg.Type == "message_updated" { case "message_updated":
msgSend, err := bot.Send(tgbotapi.NewEditMessageText(cid, uid, msg.Data.Content)) msgSend, err := bot.Send(tgbotapi.NewEditMessageText(cid, uid, msg.Data.Content))
if err != nil { if err != nil {
logger.Error(err) logger.Error(err)
@ -523,9 +554,8 @@ func mgWebhookHandler(c *gin.Context) {
} }
c.AbortWithStatus(http.StatusOK) c.AbortWithStatus(http.StatusOK)
}
if msg.Type == "message_deleted" { case "message_deleted":
msgSend, err := bot.Send(tgbotapi.NewDeleteMessage(cid, uid)) msgSend, err := bot.Send(tgbotapi.NewDeleteMessage(cid, uid))
if err != nil { if err != nil {
logger.Error(err) logger.Error(err)
@ -538,5 +568,6 @@ func mgWebhookHandler(c *gin.Context) {
} }
c.JSON(http.StatusOK, gin.H{}) c.JSON(http.StatusOK, gin.H{})
} }
} }

View File

@ -18,7 +18,7 @@ import (
) )
var ( var (
tokenCounter uint32 tokenCounter uint32
credentialsTransport = []string{ credentialsTransport = []string{
"/api/integration-modules/{code}", "/api/integration-modules/{code}",
"/api/integration-modules/{code}/edit", "/api/integration-modules/{code}/edit",