mirror of
				https://github.com/abhinavxd/libredesk.git
				synced 2025-11-03 21:43:35 +00:00 
			
		
		
		
	wip: intercom like live chat with chat widget
- new vue app for serving live chat widget, created subdirectories inside frontend dir `main` and `widget` - vite changes for both main app and widget app. - new backend live chat channel - apis for live chat widget
This commit is contained in:
		
							
								
								
									
										34
									
								
								cmd/init.go
									
									
									
									
									
								
							
							
						
						
									
										34
									
								
								cmd/init.go
									
									
									
									
									
								
							@@ -27,6 +27,7 @@ import (
 | 
			
		||||
	customAttribute "github.com/abhinavxd/libredesk/internal/custom_attribute"
 | 
			
		||||
	"github.com/abhinavxd/libredesk/internal/inbox"
 | 
			
		||||
	"github.com/abhinavxd/libredesk/internal/inbox/channel/email"
 | 
			
		||||
	"github.com/abhinavxd/libredesk/internal/inbox/channel/livechat"
 | 
			
		||||
	imodels "github.com/abhinavxd/libredesk/internal/inbox/models"
 | 
			
		||||
	"github.com/abhinavxd/libredesk/internal/macro"
 | 
			
		||||
	"github.com/abhinavxd/libredesk/internal/media"
 | 
			
		||||
@@ -132,7 +133,8 @@ func initConstants() *constants {
 | 
			
		||||
// initFS initializes the stuffbin FileSystem.
 | 
			
		||||
func initFS() stuffbin.FileSystem {
 | 
			
		||||
	var files = []string{
 | 
			
		||||
		"frontend/dist",
 | 
			
		||||
		"frontend/dist/main",
 | 
			
		||||
		"frontend/dist/widget",
 | 
			
		||||
		"i18n",
 | 
			
		||||
		"static",
 | 
			
		||||
	}
 | 
			
		||||
@@ -572,11 +574,41 @@ func initEmailInbox(inboxRecord imodels.Inbox, msgStore inbox.MessageStore, usrS
 | 
			
		||||
	return inbox, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// initLiveChatInbox initializes the live chat inbox.
 | 
			
		||||
func initLiveChatInbox(inboxRecord imodels.Inbox, msgStore inbox.MessageStore, usrStore inbox.UserStore) (inbox.Inbox, error) {
 | 
			
		||||
	var config livechat.Config
 | 
			
		||||
 | 
			
		||||
	// Load JSON data into Koanf.
 | 
			
		||||
	if err := ko.Load(rawbytes.Provider([]byte(inboxRecord.Config)), kjson.Parser()); err != nil {
 | 
			
		||||
		return nil, fmt.Errorf("loading config: %w", err)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if err := ko.UnmarshalWithConf("", &config, koanf.UnmarshalConf{Tag: "json"}); err != nil {
 | 
			
		||||
		return nil, fmt.Errorf("unmarshalling `%s` %s config: %w", inboxRecord.Channel, inboxRecord.Name, err)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	inbox, err := livechat.New(msgStore, usrStore, livechat.Opts{
 | 
			
		||||
		ID:     inboxRecord.ID,
 | 
			
		||||
		Config: config,
 | 
			
		||||
		Lo:     initLogger("livechat_inbox"),
 | 
			
		||||
	})
 | 
			
		||||
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, fmt.Errorf("initializing `%s` inbox: `%s` error : %w", inboxRecord.Channel, inboxRecord.Name, err)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	log.Printf("`%s` inbox successfully initialized", inboxRecord.Name)
 | 
			
		||||
 | 
			
		||||
	return inbox, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// initializeInboxes handles inbox initialization.
 | 
			
		||||
func initializeInboxes(inboxR imodels.Inbox, msgStore inbox.MessageStore, usrStore inbox.UserStore) (inbox.Inbox, error) {
 | 
			
		||||
	switch inboxR.Channel {
 | 
			
		||||
	case "email":
 | 
			
		||||
		return initEmailInbox(inboxR, msgStore, usrStore)
 | 
			
		||||
	case "livechat":
 | 
			
		||||
		return initLiveChatInbox(inboxR, msgStore, usrStore)
 | 
			
		||||
	default:
 | 
			
		||||
		return nil, fmt.Errorf("unknown inbox channel: %s", inboxR.Channel)
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user