feat(integrations): align app hook payloads

This commit is contained in:
2026-06-06 06:46:36 +08:00
parent 02ea135e0c
commit d241925b6a
12 changed files with 504 additions and 132 deletions
+31 -2
View File
@@ -22,7 +22,19 @@ func NewIntegrationHookRepo(db *gorm.DB) *IntegrationHookRepo {
// GetByID retrieves an integration hook by primary key.
func (r *IntegrationHookRepo) GetByID(ctx context.Context, id uint) (*model.IntegrationHook, error) {
var hook model.IntegrationHook
if err := r.db.WithContext(ctx).First(&hook, id).Error; err != nil {
if err := r.db.WithContext(ctx).Preload("Inbox").First(&hook, id).Error; err != nil {
return nil, err
}
return &hook, nil
}
// GetByAccountAndID retrieves an integration hook scoped to an account.
func (r *IntegrationHookRepo) GetByAccountAndID(ctx context.Context, accountID, id uint) (*model.IntegrationHook, error) {
var hook model.IntegrationHook
if err := r.db.WithContext(ctx).
Preload("Inbox").
Where("account_id = ?", accountID).
First(&hook, id).Error; err != nil {
return nil, err
}
return &hook, nil
@@ -38,10 +50,22 @@ func (r *IntegrationHookRepo) FindByAccount(ctx context.Context, accountID uint,
return nil, 0, err
}
err := q.Offset(offset).Limit(limit).Order("id ASC").Find(&hooks).Error
err := q.Preload("Inbox").Offset(offset).Limit(limit).Order("id ASC").Find(&hooks).Error
return hooks, total, err
}
// FindByAccountAndApp retrieves integration hooks for a Chatwoot app id.
func (r *IntegrationHookRepo) FindByAccountAndApp(ctx context.Context, accountID uint, appID string) ([]model.IntegrationHook, error) {
var hooks []model.IntegrationHook
err := r.db.WithContext(ctx).
Preload("Inbox").
Where("account_id = ?", accountID).
Where("app_id = ? OR (app_id = '' AND hook_type = ?)", appID, appID).
Order("id ASC").
Find(&hooks).Error
return hooks, err
}
// FindByAccountAndType retrieves integration hooks for an account filtered by hook type.
func (r *IntegrationHookRepo) FindByAccountAndType(ctx context.Context, accountID uint, hookType model.HookType) ([]model.IntegrationHook, error) {
var hooks []model.IntegrationHook
@@ -114,3 +138,8 @@ func (r *IntegrationAppRepo) GetByHookType(ctx context.Context, hookType model.H
}
return &app, nil
}
// GetByAppID retrieves an integration app by Chatwoot app id.
func (r *IntegrationAppRepo) GetByAppID(ctx context.Context, appID string) (*model.IntegrationApp, error) {
return r.GetByHookType(ctx, model.HookType(appID))
}