feat(public): implement chatwoot public inbox flow
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/gochat/gochat/internal/model"
|
||||
channelmodel "github.com/gochat/gochat/internal/model/channel"
|
||||
)
|
||||
|
||||
// InboxRepo implements GORM repository for Inbox.
|
||||
@@ -145,6 +146,19 @@ func (r *InboxRepo) FindByWebsiteToken(ctx context.Context, websiteToken string)
|
||||
return nil, gorm.ErrRecordNotFound
|
||||
}
|
||||
|
||||
// FindAPIInboxByIdentifier resolves a public API inbox via Channel::Api identifier.
|
||||
func (r *InboxRepo) FindAPIInboxByIdentifier(ctx context.Context, identifier string) (*model.Inbox, *channelmodel.ChannelAPI, error) {
|
||||
var channelAPI channelmodel.ChannelAPI
|
||||
if err := r.db.WithContext(ctx).Where("identifier = ?", identifier).First(&channelAPI).Error; err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
inbox, err := r.FindByID(ctx, channelAPI.InboxID)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
return inbox, &channelAPI, nil
|
||||
}
|
||||
|
||||
// parseChannelConfig parses the JSON-encoded ChannelConfig string into a map.
|
||||
func parseChannelConfig(inbox *model.Inbox) map[string]interface{} {
|
||||
if inbox.ChannelConfig == "" {
|
||||
@@ -176,4 +190,4 @@ func (r *InboxRepo) UpdateSecret(ctx context.Context, id uint, secret string) er
|
||||
func (r *InboxRepo) UpdateFields(ctx context.Context, id uint, updates map[string]interface{}) error {
|
||||
return r.db.WithContext(ctx).Model(&model.Inbox{}).Where("id = ?", id).
|
||||
Updates(updates).Error
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user