npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

smartchat-widget

v1.0.11

Published

SmartChat Widget - 企業級智能客服嵌入套件

Downloads

23

Readme

SmartChat Widget for Angular 12

npm version Angular 12 TypeScript License: MIT

專為 Angular 12 環境優化的智能客服嵌入套件 - 讓您的 Angular 12 應用 5 分鐘內擁有專業 AI 客服功能

🎯 Angular 12 專用特色

  • 完全兼容 Angular 12.x 版本
  • TypeScript 4.3 支援
  • IE 11 瀏覽器支援
  • SystemJSRequireJS 兼容
  • SSR (Server-Side Rendering) 安全
  • AOT (Ahead-of-Time) 編譯優化

📦 安裝

NPM 安裝

npm install smartchat-widget-ng12

Yarn 安裝

yarn add smartchat-widget-ng12

🚀 快速開始

1. 導入模組 (app.module.ts)

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';

import { SmartChatWidgetModule } from 'smartchat-widget-ng12';
import { AppComponent } from './app.component';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    SmartChatWidgetModule.forRoot({
      defaultConfig: {
        apiEndpoint: 'https://your-api.com/v1',
        theme: {
          primaryColor: '#007bff'
        }
      }
    })
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

2. 在組件中使用服務

import { Component, OnInit } from '@angular/core';
import { SmartChatWidgetService, SmartChatConfig } from 'smartchat-widget-ng12';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html'
})
export class AppComponent implements OnInit {

  constructor(private smartChat: SmartChatWidgetService) {}

  async ngOnInit() {
    const config: SmartChatConfig = {
      clientId: 'your-client-id',
      apiEndpoint: 'https://api.smartchat.com/v1',
      theme: {
        primaryColor: '#007bff',
        position: 'bottom-right'
      },
      ui: {
        showHeader: true,
        showAvatar: true,
        enableSound: true
      }
    };

    try {
      await this.smartChat.initialize(config);
      console.log('SmartChat 初始化成功');
    } catch (error) {
      console.error('初始化失敗:', error);
    }
  }

  openChat() {
    this.smartChat.open();
  }

  closeChat() {
    this.smartChat.close();
  }
}

3. 使用預建組件 (可選)

<!-- app.component.html -->
<smartchat-widget 
  [config]="chatConfig"
  [showControls]="true"
  [showStatus]="true"
  [autoInit]="true">
</smartchat-widget>
// app.component.ts
export class AppComponent {
  chatConfig: SmartChatConfig = {
    clientId: 'your-client-id',
    theme: {
      primaryColor: '#28a745',
      position: 'bottom-right'
    }
  };
}

🔧 Angular 12 專用配置

SystemJS 配置 (如果使用)

// systemjs.config.js
System.config({
  map: {
    'smartchat-widget-ng12': 'node_modules/smartchat-widget-ng12/dist/smartchat-widget.umd.js'
  }
});

Webpack 配置優化

// webpack.config.js
module.exports = {
  resolve: {
    alias: {
      'smartchat-widget-ng12': path.resolve('./node_modules/smartchat-widget-ng12/dist/smartchat-widget.esm.js')
    }
  }
};

IE 11 Polyfills

如需支援 IE 11,請在 polyfills.ts 中添加:

// polyfills.ts
import 'core-js/es/promise';
import 'core-js/es/array';
import 'core-js/es/object';

📱 API 參考

SmartChatWidgetService

方法

| 方法 | 描述 | 參數 | 返回值 | |------|------|------|--------| | initialize(config) | 初始化 Widget | SmartChatConfig | Promise<void> | | open() | 開啟聊天窗口 | - | void | | close() | 關閉聊天窗口 | - | void | | sendMessage(message) | 發送訊息 | string | void | | clearChat() | 清空聊天記錄 | - | void | | getVersion() | 獲取版本號 | - | string | | destroy() | 銷毀 Widget | - | void | | isInitialized() | 檢查初始化狀態 | - | boolean |

配置接口

interface SmartChatConfig {
  clientId: string;                    // 必填:客戶端 ID
  apiEndpoint?: string;                // API 端點
  theme?: {
    primaryColor?: string;             // 主題色彩
    position?: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';
    zIndex?: number;                   // 層級
  };
  ui?: {
    showHeader?: boolean;              // 顯示標題
    showAvatar?: boolean;              // 顯示頭像
    enableSound?: boolean;             // 啟用聲音
    enableTyping?: boolean;            // 顯示打字狀態
  };
  debug?: boolean;                     // 調試模式
}

🔄 從其他版本遷移

從 smartchat-widget 遷移

# 移除舊版本
npm uninstall smartchat-widget

# 安裝 Angular 12 版本
npm install smartchat-widget-ng12

更新導入語句:

// 舊版本
import { SmartChatWidget } from 'smartchat-widget';

// Angular 12 版本
import { SmartChatWidgetService } from 'smartchat-widget-ng12';

🛠️ 開發指南

本地開發

# 複製專案
git clone https://github.com/smartchat/widget-ng12.git

# 安裝依賴
npm install

# 構建 Angular 12 版本
node build-ng12.js

# 運行測試
npm test

構建命令

# 構建所有版本
npm run build

# 只構建 Angular 12 版本
node build-ng12.js

# 監聽模式
npm run build:watch

🆘 故障排除

常見問題

Q: 在 IE 11 中不工作? A: 請確保已載入必要的 polyfills(參見上方 IE 11 Polyfills 章節)

Q: SystemJS 載入失敗? A: 請使用 UMD 版本:dist/smartchat-widget.umd.js

Q: AOT 編譯錯誤? A: 確保使用 forRoot() 方法導入模組

Q: TypeScript 編譯錯誤? A: 請確認 TypeScript 版本為 ~4.3.0

版本兼容性

| Angular 版本 | TypeScript 版本 | 推薦套件版本 | |-------------|----------------|-------------| | 12.x | ~4.3.0 | smartchat-widget-ng12 | | 13+ | ~4.4+ | smartchat-widget |

📞 技術支援

📄 授權

MIT License - 詳見 LICENSE 文件


SmartChat Team - 專為 Angular 12 打造 🚀