feat: integrate customer service chat
This commit is contained in:
@@ -19,10 +19,23 @@ type Config struct {
|
||||
Redis RedisConfig `json:"redis"`
|
||||
Auth AuthConfig `json:"auth"`
|
||||
Upload UploadConfig `json:"upload"`
|
||||
IM IMConfig `json:"im"`
|
||||
ReadTimeout time.Duration `json:"-"`
|
||||
WriteTimeout time.Duration `json:"-"`
|
||||
}
|
||||
|
||||
type IMConfig struct {
|
||||
BaseURL string `json:"base_url"`
|
||||
HTTPAPIURL string `json:"http_api_url"`
|
||||
WebSocketURL string `json:"websocket_url"`
|
||||
FileURL string `json:"file_url"`
|
||||
TenantCode string `json:"tenant_code"`
|
||||
APIKey string `json:"api_key"`
|
||||
InternalService string `json:"internal_service"`
|
||||
InternalSecret string `json:"internal_secret"`
|
||||
Timeout time.Duration `json:"-"`
|
||||
}
|
||||
|
||||
type UploadConfig struct {
|
||||
Dir string `json:"dir"`
|
||||
PublicPath string `json:"public_path"`
|
||||
@@ -87,7 +100,13 @@ func defaultConfig() *Config {
|
||||
DefaultTenantID: 0,
|
||||
RequiredAPIKey: true,
|
||||
},
|
||||
Upload: UploadConfig{Dir: "storage/uploads", PublicPath: "/uploads"},
|
||||
Upload: UploadConfig{Dir: "storage/uploads", PublicPath: "/uploads"},
|
||||
IM: IMConfig{
|
||||
BaseURL: "https://api.118im.com", HTTPAPIURL: "https://api.118im.com/v1/im",
|
||||
WebSocketURL: "wss://api.118im.com/v0/channels", FileURL: "https://api.118im.com/v0/file",
|
||||
TenantCode: "allrich", APIKey: "AQAAAAABAAChdu8_yk0OxZcId6FnwYNS",
|
||||
InternalService: "olons-server", Timeout: 8 * time.Second,
|
||||
},
|
||||
ReadTimeout: 8 * time.Second,
|
||||
WriteTimeout: 8 * time.Second,
|
||||
}
|
||||
@@ -113,6 +132,15 @@ func applyEnv(cfg *Config) {
|
||||
setBool(&cfg.Auth.RequiredAPIKey, "OLONS_SERVER_REQUIRED_API_KEY")
|
||||
setString(&cfg.Upload.Dir, "OLONS_SERVER_UPLOAD_DIR")
|
||||
setString(&cfg.Upload.PublicPath, "OLONS_SERVER_UPLOAD_PUBLIC_PATH")
|
||||
setString(&cfg.IM.BaseURL, "OLONS_IM_BASE_URL")
|
||||
setString(&cfg.IM.HTTPAPIURL, "OLONS_IM_HTTP_API_URL")
|
||||
setString(&cfg.IM.WebSocketURL, "OLONS_IM_WS_URL")
|
||||
setString(&cfg.IM.FileURL, "OLONS_IM_FILE_URL")
|
||||
setString(&cfg.IM.TenantCode, "OLONS_IM_TENANT_CODE")
|
||||
setString(&cfg.IM.APIKey, "OLONS_IM_API_KEY")
|
||||
setString(&cfg.IM.InternalService, "OLONS_IM_INTERNAL_SERVICE")
|
||||
setString(&cfg.IM.InternalSecret, "OLONS_IM_INTERNAL_SECRET")
|
||||
setDuration(&cfg.IM.Timeout, "OLONS_IM_TIMEOUT")
|
||||
if keys := strings.TrimSpace(os.Getenv("OLONS_SERVER_API_KEYS")); keys != "" {
|
||||
cfg.Auth.APIKeys = splitCSV(keys)
|
||||
}
|
||||
@@ -147,6 +175,9 @@ func (c *Config) validate() error {
|
||||
if strings.TrimSpace(c.Upload.Dir) == "" || !strings.HasPrefix(c.Upload.PublicPath, "/") {
|
||||
return errors.New("upload config is invalid")
|
||||
}
|
||||
if c.IM.Timeout <= 0 {
|
||||
c.IM.Timeout = 8 * time.Second
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -181,6 +212,14 @@ func setBool(target *bool, key string) {
|
||||
}
|
||||
}
|
||||
|
||||
func setDuration(target *time.Duration, key string) {
|
||||
if value := strings.TrimSpace(os.Getenv(key)); value != "" {
|
||||
if parsed, err := time.ParseDuration(value); err == nil {
|
||||
*target = parsed
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func splitCSV(value string) []string {
|
||||
parts := strings.Split(value, ",")
|
||||
items := make([]string, 0, len(parts))
|
||||
|
||||
Reference in New Issue
Block a user