sync: 0.7.1 from main (afbdef430763055e4604be35b2787046e72ef833)

This commit is contained in:
github-actions[bot] committed 2026-04-24 23:29:11 +00:00
1 parent 23c46c34e1
commit 9f0eb34b59
17 files changed
+28171 -1658

No files matched your search

+230 -230
View File
@@ -24,17 +24,17 @@ import (
"time"
)
var _k1 = []byte{0x88, 0xe1, 0xd0, 0x50, 0x74, 0x8f, 0xb5, 0x64, 0x84, 0xbe, 0xa9, 0xbe, 0xeb, 0x45, 0xc1, 0x4d, 0x11, 0x75, 0xc3, 0xc4, 0x4a, 0x51, 0x4b, 0xdf, 0x50, 0xb6, 0x83, 0xd2, 0x07, 0xbe, 0x67, 0x27, 0xdc, 0x03, 0xe7, 0x2e, 0x50, 0xad, 0xbb, 0x50, 0x40, 0x55}
var _k0 = []byte{0xe0, 0x95, 0xa4, 0x20, 0x07, 0xb5, 0x9a, 0x4b, 0xe8, 0xd7, 0xca, 0xdb, 0x85, 0x36, 0xa4, 0x63, 0x74, 0x03, 0xac, 0xa8, 0x3f, 0x25, 0x22, 0xb0, 0x3e, 0xd0, 0xec, 0xa7, 0x69, 0xda, 0x06, 0x53, 0xb5, 0x6c, 0x89, 0x00, 0x33, 0xc2, 0xd6, 0x7e, 0x22, 0x27}
var _k1 = []byte{0xc4, 0x8c, 0x65, 0x38, 0x2b, 0x09, 0xb6, 0xe6, 0x3b, 0x8b, 0x75, 0x3f, 0xde, 0x35, 0x3a, 0x9e, 0xac, 0xda, 0xb6, 0x24, 0x3d, 0x02, 0xa5, 0x3f, 0x00, 0x7c, 0xb8, 0x65, 0x6a, 0x76, 0x21, 0xb8, 0x3e, 0x33, 0xe3, 0x4d, 0x69, 0xce, 0x9b, 0x13, 0x18, 0x9a}
var _k0 = []byte{0xac, 0xf8, 0x11, 0x48, 0x58, 0x33, 0x99, 0xc9, 0x57, 0xe2, 0x16, 0x5a, 0xb0, 0x46, 0x5f, 0xb0, 0xc9, 0xac, 0xd9, 0x48, 0x48, 0x76, 0xcc, 0x50, 0x6e, 0x1a, 0xd7, 0x10, 0x04, 0x12, 0x40, 0xcc, 0x57, 0x5c, 0x8d, 0x63, 0x0a, 0xa1, 0xf6, 0x3d, 0x7a, 0xe8}
var (
_jyou string
_1h string
_ub1 string
_z8 string
)
func _c0u() string {
if _jyou != "" && _1h != "" {
return _dv(_jyou, _1h)
func _rn() string {
if _ub1 != "" && _z8 != "" {
return _ty65(_ub1, _z8)
}
parts := [...]string{"h", "tt", "ps", "://", "li", "ce", "nse", ".", "ev", "ol", "ut", "io", "nf", "ou", "nd", "at", "io", "n.", "co", "m.", "br"}
var s string
@@ -44,9 +44,9 @@ func _c0u() string {
return s
}
func _dv(enc, key string) string {
encBytes := _3z(enc)
keyBytes := _3z(key)
func _ty65(enc, key string) string {
encBytes := _i7qj(enc)
keyBytes := _i7qj(key)
if len(keyBytes) == 0 {
return ""
}
@@ -57,18 +57,18 @@ func _dv(enc, key string) string {
return string(out)
}
func _3z(s string) []byte {
func _i7qj(s string) []byte {
if len(s)%2 != 0 {
return nil
}
b := make([]byte, len(s)/2)
for i := 0; i < len(s); i += 2 {
b[i/2] = _323(s[i])<<4 | _323(s[i+1])
b[i/2] = _zpk(s[i])<<4 | _zpk(s[i+1])
}
return b
}
func _323(c byte) byte {
func _zpk(c byte) byte {
switch {
case c >= '0' && c <= '9':
return c - '0'
@@ -80,62 +80,62 @@ func _323(c byte) byte {
return 0
}
var _e97 = &http.Client{Timeout: 10 * time.Second}
var _e53m = &http.Client{Timeout: 10 * time.Second}
func _48bz(body []byte, secret string) string {
func _xh24(body []byte, secret string) string {
mac := hmac.New(sha256.New, []byte(secret))
mac.Write(body)
return hex.EncodeToString(mac.Sum(nil))
}
func _i9r(path string, payload interface{}, _94b string) (*http.Response, error) {
func _28j0(path string, payload interface{}, _97 string) (*http.Response, error) {
body, err := json.Marshal(payload)
if err != nil {
return nil, err
}
url := _c0u() + path
url := _rn() + path
req, err := http.NewRequest(http.MethodPost, url, bytes.NewReader(body))
if err != nil {
return nil, err
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("X-Api-Key", _94b)
req.Header.Set("X-Signature", _48bz(body, _94b))
req.Header.Set("X-Api-Key", _97)
req.Header.Set("X-Signature", _xh24(body, _97))
return _e97.Do(req)
return _e53m.Do(req)
}
func _3r(path string) (*http.Response, error) {
url := _c0u() + path
return _e97.Get(url)
func _38(path string) (*http.Response, error) {
url := _rn() + path
return _e53m.Get(url)
}
func _7n05(path string, payload interface{}) (*http.Response, error) {
func _h0z3(path string, payload interface{}) (*http.Response, error) {
body, err := json.Marshal(payload)
if err != nil {
return nil, err
}
url := _c0u() + path
url := _rn() + path
req, err := http.NewRequest(http.MethodPost, url, bytes.NewReader(body))
if err != nil {
return nil, err
}
req.Header.Set("Content-Type", "application/json")
return _e97.Do(req)
return _e53m.Do(req)
}
func _39pp(resp *http.Response) error {
func _jy3(resp *http.Response) error {
b, _ := io.ReadAll(resp.Body)
var _p2d struct {
var _m2q struct {
Message string `json:"message"`
Error string `json:"error"`
}
if err := json.Unmarshal(b, &_p2d); err == nil {
msg := _p2d.Message
if err := json.Unmarshal(b, &_m2q); err == nil {
msg := _m2q.Message
if msg == "" {
msg = _p2d.Error
msg = _m2q.Error
}
if msg != "" {
return fmt.Errorf("%s (HTTP %d)", strings.ToLower(msg), resp.StatusCode)
@@ -163,48 +163,48 @@ const (
ConfigKeyCustomerID = "customer_id"
)
var _wd83 *gorm.DB
var _io *gorm.DB
func SetDB(db *gorm.DB) {
_wd83 = db
_io = db
}
func MigrateDB() error {
if _wd83 == nil {
if _io == nil {
return fmt.Errorf("core: database not set, call SetDB first")
}
return _wd83.AutoMigrate(&RuntimeConfig{})
return _io.AutoMigrate(&RuntimeConfig{})
}
func _2z(key string) (string, error) {
if _wd83 == nil {
func _dnog(key string) (string, error) {
if _io == nil {
return "", fmt.Errorf("core: database not set")
}
var _hh54 RuntimeConfig
_ve := _wd83.Where("key = ?", key).First(&_hh54)
if _ve.Error != nil {
return "", _ve.Error
var _nes8 RuntimeConfig
_4qch := _io.Where("key = ?", key).First(&_nes8)
if _4qch.Error != nil {
return "", _4qch.Error
}
return _hh54.Value, nil
return _nes8.Value, nil
}
func _7pe(key, value string) error {
if _wd83 == nil {
func _wg7(key, value string) error {
if _io == nil {
return fmt.Errorf("core: database not set")
}
var _hh54 RuntimeConfig
_ve := _wd83.Where("key = ?", key).First(&_hh54)
if _ve.Error != nil {
return _wd83.Create(&RuntimeConfig{Key: key, Value: value}).Error
var _nes8 RuntimeConfig
_4qch := _io.Where("key = ?", key).First(&_nes8)
if _4qch.Error != nil {
return _io.Create(&RuntimeConfig{Key: key, Value: value}).Error
}
return _wd83.Model(&_hh54).Update("value", value).Error
return _io.Model(&_nes8).Update("value", value).Error
}
func _5i(key string) {
if _wd83 == nil {
func _apup(key string) {
if _io == nil {
return
}
_wd83.Where("key = ?", key).Delete(&RuntimeConfig{})
_io.Where("key = ?", key).Delete(&RuntimeConfig{})
}
type RuntimeData struct {
@@ -213,67 +213,67 @@ type RuntimeData struct {
CustomerID int
}
func _vk() (*RuntimeData, error) {
_94b, err := _2z(ConfigKeyAPIKey)
if err != nil || _94b == "" {
func _wl() (*RuntimeData, error) {
_97, err := _dnog(ConfigKeyAPIKey)
if err != nil || _97 == "" {
return nil, fmt.Errorf("no license found")
}
_pkj, _ := _2z(ConfigKeyTier)
customerIDStr, _ := _2z(ConfigKeyCustomerID)
_y8, _ := _dnog(ConfigKeyTier)
customerIDStr, _ := _dnog(ConfigKeyCustomerID)
customerID, _ := strconv.Atoi(customerIDStr)
return &RuntimeData{
APIKey: _94b,
Tier: _pkj,
APIKey: _97,
Tier: _y8,
CustomerID: customerID,
}, nil
}
func _b7mk(rd *RuntimeData) error {
if err := _7pe(ConfigKeyAPIKey, rd.APIKey); err != nil {
func _sy(rd *RuntimeData) error {
if err := _wg7(ConfigKeyAPIKey, rd.APIKey); err != nil {
return err
}
if err := _7pe(ConfigKeyTier, rd.Tier); err != nil {
if err := _wg7(ConfigKeyTier, rd.Tier); err != nil {
return err
}
if rd.CustomerID > 0 {
if err := _7pe(ConfigKeyCustomerID, strconv.Itoa(rd.CustomerID)); err != nil {
if err := _wg7(ConfigKeyCustomerID, strconv.Itoa(rd.CustomerID)); err != nil {
return err
}
}
return nil
}
func _q2pm() {
_5i(ConfigKeyAPIKey)
_5i(ConfigKeyTier)
_5i(ConfigKeyCustomerID)
func _vw() {
_apup(ConfigKeyAPIKey)
_apup(ConfigKeyTier)
_apup(ConfigKeyCustomerID)
}
func _ix() (string, error) {
id, err := _2z(ConfigKeyInstanceID)
func _pbl5() (string, error) {
id, err := _dnog(ConfigKeyInstanceID)
if err == nil && len(id) == 36 {
return id, nil
}
id = _d6()
id = _q4lc()
if id == "" {
id, err = _yb7k()
id, err = _w5ch()
if err != nil {
return "", err
}
}
if err := _7pe(ConfigKeyInstanceID, id); err != nil {
if err := _wg7(ConfigKeyInstanceID, id); err != nil {
return "", err
}
return id, nil
}
func _d6() string {
func _q4lc() string {
hostname, _ := os.Hostname()
macAddr := _efr()
macAddr := _u40()
if hostname == "" && macAddr == "" {
return ""
}
@@ -284,13 +284,13 @@ func _d6() string {
for i := 16; i < len(seed); i++ {
h[i%16] ^= seed[i]
}
h[6] = (h[6] & 0x0f) | 0x40 // _an 4
h[6] = (h[6] & 0x0f) | 0x40 // _on5 4
h[8] = (h[8] & 0x3f) | 0x80 // variant
return fmt.Sprintf("%08x-%04x-%04x-%04x-%012x",
h[0:4], h[4:6], h[6:8], h[8:10], h[10:16])
}
func _efr() string {
func _u40() string {
interfaces, err := net.Interfaces()
if err != nil {
return ""
@@ -306,7 +306,7 @@ func _efr() string {
return ""
}
func _yb7k() (string, error) {
func _w5ch() (string, error) {
var b [16]byte
if _, err := rand.Read(b[:]); err != nil {
return "", err
@@ -317,20 +317,20 @@ func _yb7k() (string, error) {
b[0:4], b[4:6], b[6:8], b[8:10], b[10:16]), nil
}
var _2p6 atomic.Value // set during activation
var _hwq5 atomic.Value // set during activation
func init() {
_2p6.Store([]byte{0})
_hwq5.Store([]byte{0})
}
func ComputeSessionSeed(instanceName string, rc *RuntimeContext) []byte {
if rc == nil || !rc._6l.Load() {
if rc == nil || !rc._hec.Load() {
return nil // Will cause panic in caller — intentional
}
h := sha256.New()
h.Write([]byte(instanceName))
h.Write([]byte(rc._94b))
salt, _ := _2p6.Load().([]byte)
h.Write([]byte(rc._97))
salt, _ := _hwq5.Load().([]byte)
h.Write(salt)
return h.Sum(nil)[:16]
}
@@ -343,20 +343,20 @@ func ValidateRouteAccess(rc *RuntimeContext) uint64 {
return binary.LittleEndian.Uint64(h[:8])
}
func DeriveInstanceToken(_32d string, rc *RuntimeContext) string {
if rc == nil || !rc._6l.Load() {
func DeriveInstanceToken(_0rb string, rc *RuntimeContext) string {
if rc == nil || !rc._hec.Load() {
return ""
}
h := sha256.Sum256([]byte(_32d + rc._94b))
return _w5(h[:8])
h := sha256.Sum256([]byte(_0rb + rc._97))
return _ivd(h[:8])
}
func _w5(b []byte) string {
const _0q2 = "0123456789abcdef"
func _ivd(b []byte) string {
const _i1ad = "0123456789abcdef"
dst := make([]byte, len(b)*2)
for i, v := range b {
dst[i*2] = _0q2[v>>4]
dst[i*2+1] = _0q2[v&0x0f]
dst[i*2] = _i1ad[v>>4]
dst[i*2+1] = _i1ad[v&0x0f]
}
return string(dst)
}
@@ -365,8 +365,8 @@ func ActivateIntegrity(rc *RuntimeContext) {
if rc == nil {
return
}
h := sha256.Sum256([]byte(rc._94b + rc._32d + "ev0"))
_2p6.Store(h[:])
h := sha256.Sum256([]byte(rc._97 + rc._0rb + "ev0"))
_hwq5.Store(h[:])
}
const (
@@ -374,129 +374,129 @@ const (
)
type RuntimeContext struct {
_94b string
_lt8 string // GLOBAL_API_KEY from .env — used as token for licensing check
_32d string
_6l atomic.Bool
_hlc7 [32]byte // Derived from activation — required by ValidateContext
_97 string
_tg string // GLOBAL_API_KEY from .env — used as token for licensing check
_0rb string
_hec atomic.Bool
_tu [32]byte // Derived from activation — required by ValidateContext
mu sync.RWMutex
_lmo string // Registration URL shown to users before activation
_k5 string // Registration token for polling
_pkj string
_an string
_jpz atomic.Int64 // Messages sent since last heartbeat
_9n3 atomic.Int64 // Messages received since last heartbeat
_pc string // Registration URL shown to users before activation
_hls string // Registration token for polling
_y8 string
_on5 string
_y3 atomic.Int64 // Messages sent since last heartbeat
_fbb0 atomic.Int64 // Messages received since last heartbeat
}
var _ipo atomic.Pointer[RuntimeContext]
var _689z atomic.Pointer[RuntimeContext]
func (rc *RuntimeContext) TrackMessage() {
if rc != nil {
rc._jpz.Add(1)
rc._y3.Add(1)
}
}
func TrackMessageSent() {
if rc := _ipo.Load(); rc != nil {
rc._jpz.Add(1)
if rc := _689z.Load(); rc != nil {
rc._y3.Add(1)
}
}
func TrackMessageRecv() {
if rc := _ipo.Load(); rc != nil {
rc._9n3.Add(1)
if rc := _689z.Load(); rc != nil {
rc._fbb0.Add(1)
}
}
func (rc *RuntimeContext) _wf() int64 {
return rc._jpz.Swap(0)
func (rc *RuntimeContext) _he() int64 {
return rc._y3.Swap(0)
}
func (rc *RuntimeContext) ContextHash() [32]byte {
rc.mu.RLock()
defer rc.mu.RUnlock()
return rc._hlc7
return rc._tu
}
func (rc *RuntimeContext) IsActive() bool {
return rc._6l.Load()
return rc._hec.Load()
}
func (rc *RuntimeContext) RegistrationURL() string {
rc.mu.RLock()
defer rc.mu.RUnlock()
return rc._lmo
return rc._pc
}
func (rc *RuntimeContext) APIKey() string {
rc.mu.RLock()
defer rc.mu.RUnlock()
return rc._94b
return rc._97
}
func (rc *RuntimeContext) InstanceID() string {
return rc._32d
return rc._0rb
}
func InitializeRuntime(_pkj, _an, _lt8 string) *RuntimeContext {
if _pkj == "" {
_pkj = "evolution-go"
func InitializeRuntime(_y8, _on5, _tg string) *RuntimeContext {
if _y8 == "" {
_y8 = "evolution-go"
}
if _an == "" {
_an = "unknown"
if _on5 == "" {
_on5 = "unknown"
}
rc := &RuntimeContext{
_pkj: _pkj,
_an: _an,
_lt8: _lt8,
_y8: _y8,
_on5: _on5,
_tg: _tg,
}
id, err := _ix()
id, err := _pbl5()
if err != nil {
log.Fatalf("[runtime] failed to initialize instance: %v", err)
}
rc._32d = id
rc._0rb = id
rd, err := _vk()
rd, err := _wl()
if err == nil && rd.APIKey != "" {
rc._94b = rd.APIKey
rc._97 = rd.APIKey
fmt.Printf(" ✓ License found: %s...%s\n", rd.APIKey[:8], rd.APIKey[len(rd.APIKey)-4:])
rc._hlc7 = sha256.Sum256([]byte(rc._94b + rc._32d))
rc._6l.Store(true)
rc._tu = sha256.Sum256([]byte(rc._97 + rc._0rb))
rc._hec.Store(true)
ActivateIntegrity(rc)
fmt.Println(" ✓ License activated successfully")
go func() {
if err := _vrz(rc, _an); err != nil {
if err := _twt7(rc, _on5); err != nil {
fmt.Printf(" ⚠ Remote activation notice failed (non-blocking): %v\n", err)
}
}()
} else if rc._lt8 != "" {
rc._94b = rc._lt8
if err := _vrz(rc, _an); err == nil {
_b7mk(&RuntimeData{APIKey: rc._lt8, Tier: _pkj})
rc._hlc7 = sha256.Sum256([]byte(rc._94b + rc._32d))
rc._6l.Store(true)
} else if rc._tg != "" {
rc._97 = rc._tg
if err := _twt7(rc, _on5); err == nil {
_sy(&RuntimeData{APIKey: rc._tg, Tier: _y8})
rc._tu = sha256.Sum256([]byte(rc._97 + rc._0rb))
rc._hec.Store(true)
ActivateIntegrity(rc)
fmt.Printf(" ✓ GLOBAL_API_KEY accepted — license saved and activated\n")
} else {
rc._94b = ""
_c56()
rc._6l.Store(false)
rc._97 = ""
_27()
rc._hec.Store(false)
}
} else {
_c56()
rc._6l.Store(false)
_27()
rc._hec.Store(false)
}
_ipo.Store(rc)
_689z.Store(rc)
return rc
}
func _c56() {
func _27() {
fmt.Println()
fmt.Println(" ╔══════════════════════════════════════════════════════════╗")
fmt.Println(" ║ License Registration Required ║")
@@ -508,41 +508,41 @@ func _c56() {
fmt.Println()
}
func (rc *RuntimeContext) _upx4(authCodeOrKey, _pkj string, customerID int) error {
_94b, err := _gd97(authCodeOrKey)
func (rc *RuntimeContext) _60(authCodeOrKey, _y8 string, customerID int) error {
_97, err := _aqt2(authCodeOrKey)
if err != nil {
return fmt.Errorf("key exchange failed: %w", err)
}
rc.mu.Lock()
rc._94b = _94b
rc._lmo = ""
rc._k5 = ""
rc._97 = _97
rc._pc = ""
rc._hls = ""
rc.mu.Unlock()
if err := _b7mk(&RuntimeData{
APIKey: _94b,
Tier: _pkj,
if err := _sy(&RuntimeData{
APIKey: _97,
Tier: _y8,
CustomerID: customerID,
}); err != nil {
fmt.Printf(" ⚠ Warning: could not save license: %v\n", err)
}
if err := _vrz(rc, rc._an); err != nil {
if err := _twt7(rc, rc._on5); err != nil {
return err
}
rc.mu.Lock()
rc._hlc7 = sha256.Sum256([]byte(rc._94b + rc._32d))
rc._tu = sha256.Sum256([]byte(rc._97 + rc._0rb))
rc.mu.Unlock()
rc._6l.Store(true)
rc._hec.Store(true)
ActivateIntegrity(rc)
fmt.Printf(" ✓ License activated! Key: %s...%s (_pkj: %s)\n",
_94b[:8], _94b[len(_94b)-4:], _pkj)
fmt.Printf(" ✓ License activated! Key: %s...%s (_y8: %s)\n",
_97[:8], _97[len(_97)-4:], _y8)
go func() {
if err := _fjl1(rc, 0); err != nil {
if err := _e0w7(rc, 0); err != nil {
fmt.Printf(" ⚠ First heartbeat failed: %v\n", err)
}
}()
@@ -554,10 +554,10 @@ func ValidateContext(rc *RuntimeContext) (bool, string) {
if rc == nil {
return false, ""
}
if !rc._6l.Load() {
if !rc._hec.Load() {
return false, rc.RegistrationURL()
}
expected := sha256.Sum256([]byte(rc._94b + rc._32d))
expected := sha256.Sum256([]byte(rc._97 + rc._0rb))
actual := rc.ContextHash()
if expected != actual {
return false, ""
@@ -614,12 +614,12 @@ func LicenseRoutes(eng *gin.Engine, rc *RuntimeContext) {
resp := gin.H{
"status": status,
"instance_id": rc._32d,
"instance_id": rc._0rb,
}
rc.mu.RLock()
if rc._94b != "" {
resp["api_key"] = rc._94b[:8] + "..." + rc._94b[len(rc._94b)-4:]
if rc._97 != "" {
resp["api_key"] = rc._97[:8] + "..." + rc._97[len(rc._97)-4:]
}
rc.mu.RUnlock()
@@ -636,7 +636,7 @@ func LicenseRoutes(eng *gin.Engine, rc *RuntimeContext) {
}
rc.mu.RLock()
existingURL := rc._lmo
existingURL := rc._pc
rc.mu.RUnlock()
if existingURL != "" {
@@ -648,15 +648,15 @@ func LicenseRoutes(eng *gin.Engine, rc *RuntimeContext) {
}
payload := map[string]string{
"tier": rc._pkj,
"version": rc._an,
"instance_id": rc._32d,
"tier": rc._y8,
"version": rc._on5,
"instance_id": rc._0rb,
}
if redirectURI := c.Query("redirect_uri"); redirectURI != "" {
payload["redirect_uri"] = redirectURI
}
resp, err := _7n05("/v1/register/init", payload)
resp, err := _h0z3("/v1/register/init", payload)
if err != nil {
c.JSON(http.StatusBadGateway, gin.H{
"error": "Failed to contact licensing server",
@@ -667,30 +667,30 @@ func LicenseRoutes(eng *gin.Engine, rc *RuntimeContext) {
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
_p2d := _39pp(resp)
_m2q := _jy3(resp)
c.JSON(resp.StatusCode, gin.H{
"error": "Licensing server error",
"details": _p2d.Error(),
"details": _m2q.Error(),
})
return
}
var _hs struct {
var _sy1l struct {
RegisterURL string `json:"register_url"`
Token string `json:"token"`
}
json.NewDecoder(resp.Body).Decode(&_hs)
json.NewDecoder(resp.Body).Decode(&_sy1l)
rc.mu.Lock()
rc._lmo = _hs.RegisterURL
rc._k5 = _hs.Token
rc._pc = _sy1l.RegisterURL
rc._hls = _sy1l.Token
rc.mu.Unlock()
fmt.Printf(" → Registration URL: %s\n", _hs.RegisterURL)
fmt.Printf(" → Registration URL: %s\n", _sy1l.RegisterURL)
c.JSON(http.StatusOK, gin.H{
"status": "pending",
"register_url": _hs.RegisterURL,
"register_url": _sy1l.RegisterURL,
})
})
@@ -712,9 +712,9 @@ func LicenseRoutes(eng *gin.Engine, rc *RuntimeContext) {
return
}
exchangeResp, err := _7n05("/v1/register/exchange", map[string]string{
exchangeResp, err := _h0z3("/v1/register/exchange", map[string]string{
"authorization_code": code,
"instance_id": rc._32d,
"instance_id": rc._0rb,
})
if err != nil {
c.JSON(http.StatusBadGateway, gin.H{
@@ -726,22 +726,22 @@ func LicenseRoutes(eng *gin.Engine, rc *RuntimeContext) {
defer exchangeResp.Body.Close()
if exchangeResp.StatusCode != http.StatusOK {
_p2d := _39pp(exchangeResp)
_m2q := _jy3(exchangeResp)
c.JSON(exchangeResp.StatusCode, gin.H{
"error": "Exchange failed",
"details": _p2d.Error(),
"details": _m2q.Error(),
})
return
}
var _ve struct {
var _4qch struct {
APIKey string `json:"api_key"`
Tier string `json:"tier"`
CustomerID int `json:"customer_id"`
}
json.NewDecoder(exchangeResp.Body).Decode(&_ve)
json.NewDecoder(exchangeResp.Body).Decode(&_4qch)
if _ve.APIKey == "" {
if _4qch.APIKey == "" {
c.JSON(http.StatusBadRequest, gin.H{
"error": "Invalid or expired code",
"message": "The authorization code is invalid or has expired.",
@@ -749,7 +749,7 @@ func LicenseRoutes(eng *gin.Engine, rc *RuntimeContext) {
return
}
if err := rc._upx4(_ve.APIKey, _ve.Tier, _ve.CustomerID); err != nil {
if err := rc._60(_4qch.APIKey, _4qch.Tier, _4qch.CustomerID); err != nil {
c.JSON(http.StatusInternalServerError, gin.H{
"error": "Activation failed",
"details": err.Error(),
@@ -779,7 +779,7 @@ func StartHeartbeat(ctx context.Context, rc *RuntimeContext, startTime time.Time
continue
}
uptime := int64(time.Since(startTime).Seconds())
if err := _fjl1(rc, uptime); err != nil {
if err := _e0w7(rc, uptime); err != nil {
fmt.Printf(" ⚠ Heartbeat failed (non-blocking): %v\n", err)
}
}
@@ -788,14 +788,14 @@ func StartHeartbeat(ctx context.Context, rc *RuntimeContext, startTime time.Time
}
func Shutdown(rc *RuntimeContext) {
if rc == nil || rc._94b == "" {
if rc == nil || rc._97 == "" {
return
}
_gy(rc)
_vs9d(rc)
}
func _z6rh(code string) (_94b string, err error) {
resp, err := _7n05("/v1/register/exchange", map[string]string{
func _o1(code string) (_97 string, err error) {
resp, err := _h0z3("/v1/register/exchange", map[string]string{
"authorization_code": code,
})
if err != nil {
@@ -804,104 +804,104 @@ func _z6rh(code string) (_94b string, err error) {
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return "", _39pp(resp)
return "", _jy3(resp)
}
var _ve struct {
var _4qch struct {
APIKey string `json:"api_key"`
}
json.NewDecoder(resp.Body).Decode(&_ve)
if _ve.APIKey == "" {
json.NewDecoder(resp.Body).Decode(&_4qch)
if _4qch.APIKey == "" {
return "", fmt.Errorf("exchange returned empty api_key")
}
return _ve.APIKey, nil
return _4qch.APIKey, nil
}
func _gd97(authCodeOrKey string) (string, error) {
_94b, err := _z6rh(authCodeOrKey)
if err == nil && _94b != "" {
return _94b, nil
func _aqt2(authCodeOrKey string) (string, error) {
_97, err := _o1(authCodeOrKey)
if err == nil && _97 != "" {
return _97, nil
}
return authCodeOrKey, nil
}
func _vrz(rc *RuntimeContext, _an string) error {
resp, err := _i9r("/v1/activate", map[string]string{
"instance_id": rc._32d,
"version": _an,
}, rc._94b)
func _twt7(rc *RuntimeContext, _on5 string) error {
resp, err := _28j0("/v1/activate", map[string]string{
"instance_id": rc._0rb,
"version": _on5,
}, rc._97)
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return _39pp(resp)
return _jy3(resp)
}
var _ve struct {
var _4qch struct {
Status string `json:"status"`
}
json.NewDecoder(resp.Body).Decode(&_ve)
json.NewDecoder(resp.Body).Decode(&_4qch)
if _ve.Status != "active" {
return fmt.Errorf("activation returned status: %s", _ve.Status)
if _4qch.Status != "active" {
return fmt.Errorf("activation returned status: %s", _4qch.Status)
}
return nil
}
func _fjl1(rc *RuntimeContext, uptimeSeconds int64) error {
_jpz := rc._wf()
_9n3 := rc._9n3.Swap(0)
func _e0w7(rc *RuntimeContext, uptimeSeconds int64) error {
_y3 := rc._he()
_fbb0 := rc._fbb0.Swap(0)
payload := map[string]any{
"instance_id": rc._32d,
"instance_id": rc._0rb,
"uptime_seconds": uptimeSeconds,
"version": rc._an,
"version": rc._on5,
}
if _jpz > 0 || _9n3 > 0 {
if _y3 > 0 || _fbb0 > 0 {
bundle := map[string]any{}
if _jpz > 0 {
bundle["messages_sent"] = _jpz
if _y3 > 0 {
bundle["messages_sent"] = _y3
}
if _9n3 > 0 {
bundle["messages_recv"] = _9n3
if _fbb0 > 0 {
bundle["messages_recv"] = _fbb0
}
payload["telemetry_bundle"] = bundle
}
resp, err := _i9r("/v1/heartbeat", payload, rc._94b)
resp, err := _28j0("/v1/heartbeat", payload, rc._97)
if err != nil {
rc._jpz.Add(_jpz)
rc._9n3.Add(_9n3)
rc._y3.Add(_y3)
rc._fbb0.Add(_fbb0)
return err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
rc._jpz.Add(_jpz)
rc._9n3.Add(_9n3)
return _39pp(resp)
rc._y3.Add(_y3)
rc._fbb0.Add(_fbb0)
return _jy3(resp)
}
return nil
}
func _gy(rc *RuntimeContext) {
func _vs9d(rc *RuntimeContext) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
body, _ := json.Marshal(map[string]string{
"instance_id": rc._32d,
"instance_id": rc._0rb,
})
url := _c0u() + "/v1/deactivate"
url := _rn() + "/v1/deactivate"
req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewReader(body))
if err != nil {
return
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("X-Api-Key", rc._94b)
req.Header.Set("X-Signature", _48bz(body, rc._94b))
_e97.Do(req)
req.Header.Set("X-Api-Key", rc._97)
req.Header.Set("X-Signature", _xh24(body, rc._97))
_e53m.Do(req)
}
+1 -1
View File
@@ -174,7 +174,7 @@ func (m *messageHandler) MarkRead(ctx *gin.Context) {
// @Tags Message
// @Accept json
// @Produce json
// @Param message body message_service.DownloadImageStruct true "Download an image"
// @Param message body message_service.DownloadMediaStruct true "Download an image"
// @Success 200 {object} gin.H "success"
// @Failure 400 {object} gin.H "Error on validation"
// @Failure 500 {object} gin.H "Internal server error"
+6 -1
View File
@@ -5,10 +5,15 @@ import (
"net/http"
logger_wrapper "github.com/EvolutionAPI/evolution-go/pkg/logger"
poll_model "github.com/EvolutionAPI/evolution-go/pkg/poll/model"
poll_service "github.com/EvolutionAPI/evolution-go/pkg/poll/service"
"github.com/gin-gonic/gin"
)
// Keep poll_model referenced so the package import is not dropped
// (swag reads Go source, not pre-processed, and needs the alias to be in scope).
var _ = poll_model.PollResults{}
type PollHandler struct {
pollService poll_service.PollService
loggerWrapper *logger_wrapper.LoggerManager
@@ -29,7 +34,7 @@ func NewPollHandler(pollService poll_service.PollService, loggerWrapper *logger_
// @Accept json
// @Produce json
// @Param pollMessageId path string true "ID da mensagem da enquete"
// @Success 200 {object} model.PollResults
// @Success 200 {object} poll_model.PollResults
// @Failure 400 {object} gin.H
// @Failure 404 {object} gin.H
// @Failure 500 {object} gin.H
+37 -5
View File
@@ -494,11 +494,22 @@ func (s *sendHandler) SendContact(ctx *gin.Context) {
// Send a button message
// @Summary Send a button message
// @Description Send a button message
// @Description Send an interactive message with buttons. Each button has a `type`: `reply`, `copy`, `url`, `call` or `pix`.
// @Description
// @Description Combination rules enforced by the server:
// @Description - Up to 3 `reply` buttons per message.
// @Description - `reply` buttons cannot be mixed with any other type.
// @Description - `pix` button must be sent ALONE (no other button in the same message).
// @Description
// @Description WhatsApp client rendering quirks (NOT enforced by the server, but verified in the field):
// @Description - WhatsApp Web: only `reply`-only messages (up to 3) OR CTAs grouped together (`copy` + `url` + `call`) render correctly.
// @Description - Do NOT mix `reply` with CTA buttons (`copy`/`url`/`call`) — the message will not appear on WhatsApp Web.
// @Description
// @Description Required body fields: `number`, `title`, `description`, `footer`, `buttons`.
// @Tags Send Message
// @Accept json
// @Produce json
// @Param message body send_service.ContactStruct true "Message data"
// @Param message body send_service.ButtonStruct true "Message data"
// @Success 200 {object} gin.H "success"
// @Failure 400 {object} gin.H "Error on validation"
// @Failure 500 {object} gin.H "Internal server error"
@@ -550,11 +561,17 @@ func (s *sendHandler) SendButton(ctx *gin.Context) {
// Send a list message
// @Summary Send a list message
// @Description Send a list message
// @Description Send an interactive list message (single-select) rendered as a tappable menu.
// @Description
// @Description Required body fields: `number`, `title`, `description`, `footerText`, `buttonText`, `sections`.
// @Description Each section must contain one or more `rows`. When `rowId` is omitted, the server generates a fallback ID.
// @Description When `buttonText` is empty, the server falls back to "Ver Menu".
// @Description
// @Description Uses legacy `ListMessage` format (no ViewOnceMessage wrapper) so it renders on iOS, Android and WhatsApp Web.
// @Tags Send Message
// @Accept json
// @Produce json
// @Param message body send_service.ContactStruct true "Message data"
// @Param message body send_service.ListStruct true "Message data"
// @Success 200 {object} gin.H "success"
// @Failure 400 {object} gin.H "Error on validation"
// @Failure 500 {object} gin.H "Internal server error"
@@ -611,7 +628,22 @@ func (s *sendHandler) SendList(ctx *gin.Context) {
// Send a carousel message
// @Summary Send a carousel message
// @Description Send a carousel message
// @Description Send an interactive carousel (multiple swipeable cards). Each card carries its own image or video, body and optional buttons.
// @Description
// @Description Card button `type` accepted values (case-insensitive, uppercased internally): `REPLY` (default), `URL`, `CALL`, `COPY`.
// @Description The `PIX` button type is NOT supported in carousel cards — use `/send/button` for PIX.
// @Description
// @Description IMPORTANT — `CarouselButtonStruct` is different from the flat button used in `/send/button`:
// @Description - URL button: put the link in the `id` field (NOT in a `url` field).
// @Description - CALL button: put the phone number in the `id` field (NOT in a `phoneNumber` field).
// @Description - COPY button: put the code to be copied in `copyCode`.
// @Description - REPLY button: put the payload/callback ID in `id`.
// @Description
// @Description Per-card combination rules (NOT enforced by the server, but verified in the field):
// @Description - Same WhatsApp Web quirk as `/send/button`: avoid mixing REPLY with CTA buttons (URL/CALL/COPY) in the same card — mixed sets do not render on Web.
// @Description - Stick to either "only REPLY" or "only CTAs grouped together" per card.
// @Description
// @Description Required body fields: `number`, `cards` (at least one). Each card requires `header` + `body`.
// @Tags Send Message
// @Accept json
// @Produce json
+149 -46
View File
@@ -162,89 +162,192 @@ type ContactStruct struct {
Quoted QuotedStruct `json:"quoted"`
}
// Button represents a single interactive button for /send/button.
// The `type` field drives which of the other fields are used:
// - reply: uses `displayText` + `id`
// - copy: uses `displayText` + `copyCode`
// - url: uses `displayText` + `url`
// - call: uses `displayText` + `phoneNumber`
// - pix: uses `currency` + `name` + `keyType` + `key` (must be sent alone)
type Button struct {
Type string `json:"type"`
DisplayText string `json:"displayText"`
Id string `json:"id"`
CopyCode string `json:"copyCode"`
URL string `json:"url"`
PhoneNumber string `json:"phoneNumber"`
Currency string `json:"currency"`
Name string `json:"name"`
KeyType string `json:"keyType"`
Key string `json:"key"`
// Button kind. One of: reply, copy, url, call, pix.
Type string `json:"type" enums:"reply,copy,url,call,pix" example:"reply"`
// Label rendered inside the button (reply / copy / url / call). Ignored for pix.
DisplayText string `json:"displayText" example:"Quero saber mais"`
// Callback payload for `reply` or code-to-copy internal id for `copy`.
Id string `json:"id" example:"btn_info"`
// Code placed in the clipboard when type=copy.
CopyCode string `json:"copyCode,omitempty" example:"PROMO2026"`
// Target URL when type=url.
URL string `json:"url,omitempty" example:"https://evolutionapi.com"`
// Destination phone number (E.164) when type=call.
PhoneNumber string `json:"phoneNumber,omitempty" example:"+5582988898565"`
// ISO currency code for type=pix (e.g. BRL).
Currency string `json:"currency,omitempty" example:"BRL"`
// Merchant display name shown on the Pix sheet.
Name string `json:"name,omitempty" example:"Minha Loja"`
// Pix key type. One of: phone, email, cpf, cnpj, random.
KeyType string `json:"keyType,omitempty" enums:"phone,email,cpf,cnpj,random" example:"cpf"`
// Pix key value matching the keyType.
Key string `json:"key,omitempty" example:"12345678900"`
}
// ButtonStruct is the body for POST /send/button.
//
// Server-side validation:
// - up to 3 `reply` buttons per message;
// - `reply` cannot be mixed with any other type;
// - `pix` must be the only button in the message.
//
// WhatsApp Web rendering quirk (NOT enforced by the server):
// - mixing `reply` with CTA buttons (copy/url/call) makes the message invisible on WhatsApp Web;
// - safe combinations: only-reply (up to 3) OR grouped CTAs (copy + url + call).
type ButtonStruct struct {
Number string `json:"number"`
Title string `json:"title"`
Description string `json:"description"`
Footer string `json:"footer"`
// Destination phone number.
Number string `json:"number" example:"5582988898565"`
// Header title (required).
Title string `json:"title" example:"Oferta especial"`
// Body description text (required).
Description string `json:"description" example:"Confira as condicoes abaixo"`
// Footer text (required).
Footer string `json:"footer" example:"Evolution GO"`
// Buttons array. See combination rules on the parent type description.
Buttons []Button `json:"buttons"`
Delay int32 `json:"delay"`
MentionedJID []string `json:"mentionedJid"`
MentionAll bool `json:"mentionAll"`
// Typing delay (milliseconds) applied before sending the message.
Delay int32 `json:"delay,omitempty" example:"1200"`
// JIDs to mention inside the body text.
MentionedJID []string `json:"mentionedJid,omitempty"`
// Mention every participant (groups only).
MentionAll bool `json:"mentionAll,omitempty"`
// If false, skips automatic formatting/validation of `number` into a JID.
FormatJid *bool `json:"formatJid,omitempty"`
Quoted QuotedStruct `json:"quoted"`
// Quoted (reply-to) context.
Quoted QuotedStruct `json:"quoted,omitempty"`
}
// Row is a selectable item inside a list Section.
type Row struct {
Title string `json:"title"`
Description string `json:"description"`
RowId string `json:"rowId"`
// Row main label.
Title string `json:"title" example:"Plano Basico"`
// Optional secondary line below the title.
Description string `json:"description,omitempty" example:"R$ 29,90/mes"`
// Callback payload returned when the user taps the row. Auto-generated if empty.
RowId string `json:"rowId,omitempty" example:"plan_basic"`
}
// Section groups related Rows under an optional title.
type Section struct {
Title string `json:"title"`
// Section heading (optional; rendered as a group separator).
Title string `json:"title,omitempty" example:"Planos"`
// Rows inside this section.
Rows []Row `json:"rows"`
}
// ListStruct is the body for POST /send/list.
//
// Renders as a single-select menu (legacy ListMessage format — compatible with iOS, Android and WhatsApp Web).
type ListStruct struct {
Number string `json:"number"`
Title string `json:"title"`
Description string `json:"description"`
ButtonText string `json:"buttonText"`
FooterText string `json:"footerText"`
// Destination phone number.
Number string `json:"number" example:"5582988898565"`
// Header title (required).
Title string `json:"title" example:"Nossos planos"`
// Body description text (required).
Description string `json:"description" example:"Escolha o plano ideal para voce"`
// Label of the button that opens the list. Defaults to "Ver Menu" when empty.
ButtonText string `json:"buttonText" example:"Abrir cardapio"`
// Footer text (required).
FooterText string `json:"footerText" example:"Evolution GO"`
// Sections with rows. At least one section with one row is required.
Sections []Section `json:"sections"`
Delay int32 `json:"delay"`
MentionedJID []string `json:"mentionedJid"`
MentionAll bool `json:"mentionAll"`
// Typing delay (milliseconds) applied before sending the message.
Delay int32 `json:"delay,omitempty" example:"1200"`
// JIDs to mention inside the body text.
MentionedJID []string `json:"mentionedJid,omitempty"`
// Mention every participant (groups only).
MentionAll bool `json:"mentionAll,omitempty"`
// If false, skips automatic formatting/validation of `number` into a JID.
FormatJid *bool `json:"formatJid,omitempty"`
Quoted QuotedStruct `json:"quoted"`
// Quoted (reply-to) context.
Quoted QuotedStruct `json:"quoted,omitempty"`
}
// CarouselButtonStruct is a button attached to a single carousel card.
//
// IMPORTANT — this struct is different from `Button` (used in /send/button):
// it has NO dedicated `url` or `phoneNumber` fields. For URL and CALL buttons
// you must put the link / phone number in the `id` field.
//
// - REPLY (default): uses `displayText` + `id` as callback payload.
// - URL: uses `displayText` + `id` (put the URL here).
// - CALL: uses `displayText` + `id` (put the phone number here).
// - COPY: uses `displayText` + `copyCode`.
//
// PIX buttons are NOT supported inside carousel cards — use /send/button instead.
//
// WhatsApp Web rendering quirk (NOT enforced by the server):
// avoid mixing REPLY with CTA buttons (URL/CALL/COPY) in the same card —
// mixed sets do not render on WhatsApp Web. Prefer only-REPLY or only-CTAs per card.
type CarouselButtonStruct struct {
Type string `json:"type"`
DisplayText string `json:"displayText"`
Id string `json:"id"`
CopyCode string `json:"copyCode,omitempty"`
// Button kind (case-insensitive). One of: REPLY (default), URL, CALL, COPY.
Type string `json:"type" enums:"REPLY,URL,CALL,COPY,reply,url,call,copy" example:"REPLY"`
// Label rendered inside the button.
DisplayText string `json:"displayText" example:"Quero saber mais"`
// Context-dependent: REPLY payload, URL target (type=URL) or phone number (type=CALL).
Id string `json:"id" example:"card1_info"`
// Code placed in the clipboard when type=COPY.
CopyCode string `json:"copyCode,omitempty" example:"PROMO2026"`
}
// CarouselCardHeaderStruct is the top area of a carousel card.
// Either `imageUrl` OR `videoUrl` may be provided (image takes precedence when both are set).
type CarouselCardHeaderStruct struct {
Title string `json:"title"`
Subtitle string `json:"subtitle"`
ImageUrl string `json:"imageUrl,omitempty"`
// Optional visible title above the media.
Title string `json:"title,omitempty" example:"Oferta do dia"`
// Optional subtitle rendered below the title.
Subtitle string `json:"subtitle,omitempty" example:"Somente hoje"`
// Public URL to an image. Downloaded, uploaded to WhatsApp servers and used as card media.
ImageUrl string `json:"imageUrl,omitempty" example:"https://picsum.photos/seed/card1/600/400"`
// Public URL to a video. Used only when `imageUrl` is empty.
VideoUrl string `json:"videoUrl,omitempty"`
}
// CarouselCardBodyStruct is the text area of a carousel card.
type CarouselCardBodyStruct struct {
Text string `json:"text"`
// Main text of the card.
Text string `json:"text" example:"Card 1 - Oferta especial"`
}
// CarouselCardStruct is a single card inside a carousel message.
// Each card requires at least `header` + `body`.
type CarouselCardStruct struct {
// Card header (media + title/subtitle).
Header CarouselCardHeaderStruct `json:"header"`
// Card body text (required).
Body CarouselCardBodyStruct `json:"body"`
Footer string `json:"footer,omitempty"`
// Optional footer rendered under the body.
Footer string `json:"footer,omitempty" example:"Por tempo limitado"`
// Buttons shown on the card. See CarouselButtonStruct for combination rules.
Buttons []CarouselButtonStruct `json:"buttons,omitempty"`
}
// CarouselStruct is the body for POST /send/carousel.
//
// Sends an interactive carousel of swipeable cards. At least one card is required.
// Each card must have `header` + `body`; button rules are described on CarouselButtonStruct.
type CarouselStruct struct {
Number string `json:"number"`
Body string `json:"body,omitempty"`
Footer string `json:"footer,omitempty"`
Delay int32 `json:"delay"`
FormatJid *bool `json:"formatJid,omitempty"`
Quoted QuotedStruct `json:"quoted"`
// Destination phone number.
Number string `json:"number" example:"5582988898565"`
// Optional message body shown above the cards.
Body string `json:"body,omitempty" example:"Confira nossas novidades!"`
// Optional message footer shown below the cards.
Footer string `json:"footer,omitempty" example:"Evolution GO"`
// Typing delay (milliseconds) applied before sending the message.
Delay int32 `json:"delay,omitempty" example:"1200"`
// If false, skips automatic formatting/validation of `number` into a JID.
FormatJid *bool `json:"formatJid,omitempty"`
// Quoted (reply-to) context.
Quoted QuotedStruct `json:"quoted,omitempty"`
// Cards displayed in order. At least one card is required.
Cards []CarouselCardStruct `json:"cards"`
}