diff --git a/go.sum b/go.sum index f1857ba..8bed425 100644 --- a/go.sum +++ b/go.sum @@ -95,8 +95,6 @@ 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/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/mg-transport-api-client-go v1.1.17 h1:8L0meFJFZwr3TyiF/xypI+g0xRXIGkWhyQ6qiCfojqw= -github.com/retailcrm/mg-transport-api-client-go v1.1.17/go.mod h1:AWV6BueE28/6SCoyfKURTo4lF0oXYoOKmHTzehd5vAI= github.com/retailcrm/mg-transport-api-client-go v1.1.18 h1:V59Ai79N1jrS1kAnQggNoRYsoAdr2RUV7Hf0xbw9r9Q= github.com/retailcrm/mg-transport-api-client-go v1.1.18/go.mod h1:AWV6BueE28/6SCoyfKURTo4lF0oXYoOKmHTzehd5vAI= github.com/smartystreets/assertions v0.0.0-20180820201707-7c9eb446e3cf h1:6V1qxN6Usn4jy8unvggSJz/NC790tefw8Zdy6OZS5co= diff --git a/src/routing.go b/src/routing.go index fea45a5..723179c 100644 --- a/src/routing.go +++ b/src/routing.go @@ -75,6 +75,14 @@ func addBotHandler(c *gin.Context) { } b.Channel = data.ChannelID + b.Lang = "en" + + hashSettings, err := getChannelSettingsHash() + if err != nil { + logger.Errorf("addBotHandler hashSettings apiURl: %s, err: %s", conn.APIURL, err.Error()) + } else { + b.ChannelSettingsHash = hashSettings + } err = conn.createBot(b) if err != nil { @@ -253,6 +261,13 @@ func activityHandler(c *gin.Context) { conn.APIURL = systemUrl } + hashSettings, err := getChannelSettingsHash() + if err != nil { + logger.Errorf("activityHandler hashSettings apiURl: %s, err: %s", conn.APIURL, err.Error()) + } else { + updateBots(conn, hashSettings) + } + if err := conn.saveConnection(); err != nil { c.Error(err) return diff --git a/src/routing_test.go b/src/routing_test.go index c7b1a41..79b5aa7 100644 --- a/src/routing_test.go +++ b/src/routing_test.go @@ -13,12 +13,12 @@ import ( "github.com/gin-gonic/gin" "github.com/h2non/gock" - "github.com/retailcrm/mg-transport-api-client-go/v1" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) var router *gin.Engine +var ch = getChannelSettings() func init() { os.Chdir("../") @@ -56,48 +56,9 @@ func TestRouting_connectHandler(t *testing.T) { func TestRouting_addBotHandler(t *testing.T) { defer gock.Off() - ch := v1.Channel{ - Type: "telegram", - Name: "@TestBot", - Settings: v1.ChannelSettings{ - SpamAllowed: false, - Status: v1.Status{ - Delivered: v1.ChannelFeatureSend, - Read: v1.ChannelFeatureNone, - }, - Text: v1.ChannelSettingsText{ - Creating: v1.ChannelFeatureBoth, - Editing: v1.ChannelFeatureBoth, - Quoting: v1.ChannelFeatureBoth, - Deleting: v1.ChannelFeatureReceive, - MaxCharsCount: MaxCharsCount, - }, - Product: v1.Product{ - Creating: v1.ChannelFeatureReceive, - Editing: v1.ChannelFeatureReceive, - }, - Order: v1.Order{ - Creating: v1.ChannelFeatureReceive, - Editing: v1.ChannelFeatureReceive, - }, - File: v1.ChannelSettingsFilesBase{ - Creating: v1.ChannelFeatureBoth, - Editing: v1.ChannelFeatureBoth, - Quoting: v1.ChannelFeatureBoth, - Deleting: v1.ChannelFeatureReceive, - Max: 1, - }, - Image: v1.ChannelSettingsFilesBase{ - Creating: v1.ChannelFeatureBoth, - Editing: v1.ChannelFeatureBoth, - Quoting: v1.ChannelFeatureBoth, - Deleting: v1.ChannelFeatureReceive, - Max: 10, - }, - }, - } + ch.Name = "@TestBot" - outgoing, _ := json.Marshal(&ch) + outgoing, _ := json.Marshal(ch) p := url.Values{"url": {"https://" + config.HTTPServer.Host + "/telegram/123123:Qwerty"}} gock.New("https://api.telegram.org").