{"_id":"@alm1983_root/smart-messenger-chat-sdk","name":"@alm1983_root/smart-messenger-chat-sdk","dist-tags":{"latest":"0.0.1"},"versions":{"0.0.1":{"name":"@alm1983_root/smart-messenger-chat-sdk","version":"0.0.1","private":false,"type":"module","description":"A lightweight chat widget SDK using iframe","main":"./dist/chat-sdk-v2.cjs.js","module":"./dist/chat-sdk-v2.es.js","types":"./dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/chat-sdk-v2.es.js","require":"./dist/chat-sdk-v2.cjs.js"}},"keywords":["chat","widget","iframe","sdk","javascript"],"scripts":{"dev":"vite","build":"vite build","lint":"eslint .","preview":"vite preview","prepublishOnly":"pnpm build"},"devDependencies":{"@eslint/js":"^9.29.0","eslint":"8.57.0","eslint-plugin-react-hooks":"^5.2.0","eslint-plugin-react-refresh":"^0.4.20","globals":"^16.2.0","vite":"^6.3.5","vite-plugin-dts":"^4.5.4","typescript-eslint":"^8.34.1"},"_id":"@alm1983_root/smart-messenger-chat-sdk@0.0.1","gitHead":"c8454f40d44dbfd5569a5fc820ed72e3050596ff","_nodeVersion":"22.15.0","_npmVersion":"11.3.0","dist":{"integrity":"sha512-Uhz2uZr3c3bKQ224sM8+IdMkjDlGjQdC9DrWENnGljn9Zrttpbhcje9JbHMOWKRZ7PS6vdnkqJldc8fQdmwzMg==","shasum":"9162d8dd50be9e5a3e63488f571c91bc4aaf56d8","tarball":"https://registry.npmjs.org/@alm1983_root/smart-messenger-chat-sdk/-/smart-messenger-chat-sdk-0.0.1.tgz","fileCount":6,"unpackedSize":34479,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIDqe5HFT89+A1HZ8QKDkc+/3bANTDvEAwYWW0F9LHsP2AiEAlF5EDSR0WVagLFOQpaG0tfs9OxLDCyNVKTgaydwJKE8="}]},"_npmUser":{"name":"alm1983_root","email":"smartdoctor1983@gmail.com","actor":{"name":"alm1983_root","email":"smartdoctor1983@gmail.com","type":"user"}},"directories":{},"maintainers":[{"name":"alm1983_root","email":"smartdoctor1983@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/smart-messenger-chat-sdk_0.0.1_1750648926379_0.8043485980030041"},"_hasShrinkwrap":false}},"time":{"created":"2025-06-23T03:22:06.274Z","0.0.1":"2025-06-23T03:22:06.568Z","modified":"2025-06-23T03:22:06.858Z"},"maintainers":[{"name":"alm1983_root","email":"smartdoctor1983@gmail.com"}],"description":"A lightweight chat widget SDK using iframe","keywords":["chat","widget","iframe","sdk","javascript"],"readme":"# Chat SDK v2\n\nA modern, lightweight chat widget SDK that can be easily integrated into any website.\n\n## Features\n\n- 🚀 Easy integration with just a few lines of code\n- 🎨 Customizable appearance and positioning\n- 👥 User and hospital information management\n- 📱 Responsive design\n- 🌐 Multi-language support\n- 💬 Real-time messaging through iframe communication\n\n## Installation\n\n```bash\nnpm install @your-org/chat-sdk-v2\n```\n\nOr include via CDN:\n\n```html\n<script src=\"https://cdn.your-domain.com/chat-sdk-v2.js\"></script>\n```\n\n## Basic Usage\n\n### Initialize with Default Settings\n\n```javascript\nimport ChatSDK from \"@your-org/chat-sdk-v2\";\n\n// Initialize with default settings\nChatSDK.init();\n```\n\n### Initialize with Custom Configuration\n\n```javascript\nimport ChatSDK from \"@your-org/chat-sdk-v2\";\n\nChatSDK.init({\n  position: \"bottom-right\",\n  primaryColor: \"#3B82F6\",\n  secondaryColor: \"#10B981\",\n  startOpen: false,\n  hospitalInfo: {\n    hospitalId: \"hospital-123\",\n    hospitalName: \"스마트 병원\",\n    operatingHours: \"09:00-18:00\",\n  },\n  userInfo: {\n    userName: \"홍길동\",\n    userPhone: \"010-1234-5678\",\n    userLanguage: \"ko\",\n  },\n});\n```\n\n## API Methods\n\n### Core Methods\n\n#### `init(config?: ChatSDKConfig): boolean`\n\nInitialize the chat SDK with optional configuration.\n\n```javascript\nconst success = ChatSDK.init({\n  position: \"bottom-left\",\n  primaryColor: \"#FF6B6B\",\n  hospitalInfo: {\n    hospitalId: \"my-hospital\",\n    hospitalName: \"우리 병원\",\n    operatingHours: \"24시간 운영\",\n  },\n});\n\nif (success) {\n  console.log(\"Chat SDK initialized successfully\");\n}\n```\n\n#### `open(): void`\n\nOpen the chat widget.\n\n```javascript\nChatSDK.open();\n```\n\n#### `close(): void`\n\nClose the chat widget.\n\n```javascript\nChatSDK.close();\n```\n\n#### `toggle(): void`\n\nToggle the chat widget open/closed state.\n\n```javascript\nChatSDK.toggle();\n```\n\n### Information Management\n\n#### `setHospitalInfo(hospitalInfo: HospitalInfo): void`\n\nUpdate hospital information dynamically.\n\n```javascript\nChatSDK.setHospitalInfo({\n  hospitalId: \"new-hospital-id\",\n  hospitalName: \"새로운 병원명\",\n  operatingHours: \"08:00-20:00\",\n});\n```\n\n#### `setUserInfo(userInfo: UserInfo): void`\n\nUpdate user information dynamically.\n\n```javascript\nChatSDK.setUserInfo({\n  userName: \"김철수\",\n  userPhone: \"010-9876-5432\",\n  userLanguage: \"en\",\n});\n```\n\n### Utility Methods\n\n#### `isOpen(): boolean`\n\nCheck if the chat widget is currently open.\n\n```javascript\nif (ChatSDK.isOpen()) {\n  console.log(\"Chat is currently open\");\n}\n```\n\n#### `getConfig(): ChatSDKConfig | null`\n\nGet the current configuration.\n\n```javascript\nconst currentConfig = ChatSDK.getConfig();\nconsole.log(\"Current config:\", currentConfig);\n```\n\n#### `updateConfig(newConfig: Partial<ChatSDKConfig>): void`\n\nUpdate configuration partially.\n\n```javascript\nChatSDK.updateConfig({\n  primaryColor: \"#FF5722\",\n  position: \"top-right\",\n});\n```\n\n#### `destroy(): void`\n\nCompletely remove the chat widget from the page.\n\n```javascript\nChatSDK.destroy();\n```\n\n## Configuration Options\n\n### ChatSDKConfig Interface\n\n```typescript\ninterface ChatSDKConfig {\n  position?: \"bottom-left\" | \"bottom-right\" | \"top-left\" | \"top-right\";\n  primaryColor?: string;\n  secondaryColor?: string;\n  startOpen?: boolean;\n  customStyles?: Record<string, Record<string, string>>;\n  hospitalInfo?: HospitalInfo;\n  userInfo?: UserInfo;\n}\n\ninterface HospitalInfo {\n  hospitalId: string;\n  hospitalName: string;\n  operatingHours: string;\n}\n\ninterface UserInfo {\n  userName?: string;\n  userPhone?: string;\n  userLanguage?: string;\n}\n```\n\n## Advanced Usage\n\n### Custom Styling\n\n```javascript\nChatSDK.init({\n  customStyles: {\n    \".chat-widget-container\": {\n      \"border-radius\": \"20px\",\n      \"box-shadow\": \"0 10px 30px rgba(0,0,0,0.3)\",\n    },\n    \".chat-toggle-button\": {\n      background: \"linear-gradient(45deg, #FF6B6B, #4ECDC4)\",\n    },\n  },\n});\n```\n\n### Event Listening\n\nThe SDK dispatches custom events that you can listen to:\n\n```javascript\n// Listen for when the chat opens\nwindow.addEventListener(\"chatSDKOpened\", (event) => {\n  console.log(\"Chat opened with config:\", event.detail.config);\n});\n\n// Listen for when the chat closes\nwindow.addEventListener(\"chatSDKClosed\", (event) => {\n  console.log(\"Chat closed\");\n});\n\n// Listen for when the iframe is loaded\nwindow.addEventListener(\"chatSDKIframeLoaded\", (event) => {\n  console.log(\"Chat iframe loaded\");\n});\n\n// Listen for when the SDK is destroyed\nwindow.addEventListener(\"chatSDKDestroyed\", (event) => {\n  console.log(\"Chat SDK destroyed\");\n});\n```\n\n### Dynamic User Management\n\n```javascript\n// Example: Update user info after login\nfunction handleUserLogin(userData) {\n  ChatSDK.setUserInfo({\n    userName: userData.name,\n    userPhone: userData.phone,\n    userLanguage: userData.preferredLanguage || \"ko\",\n  });\n\n  // Open chat after login\n  ChatSDK.open();\n}\n\n// Example: Update hospital context\nfunction switchHospital(hospitalData) {\n  ChatSDK.setHospitalInfo({\n    hospitalId: hospitalData.id,\n    hospitalName: hospitalData.name,\n    operatingHours: hospitalData.hours,\n  });\n}\n```\n\n## Browser Support\n\n- Chrome 70+\n- Firefox 65+\n- Safari 12+\n- Edge 79+\n\n## Communication Protocol\n\nThe SDK communicates with the iframe using `postMessage` API. The following message types are supported:\n\n### Incoming Messages (Iframe → SDK)\n\n```javascript\n// Iframe ready signal (required)\n{\n  type: \"iframe_ready\";\n}\n\n// Unread message count\n{\n  unreadMessagesTotalCount: number;\n}\n```\n\n### Outgoing Messages (SDK → Iframe)\n\n```javascript\n// Hospital information (sent after iframe_ready)\n{\n  hospitalInfo: {\n    hospitalId: string,\n    hospitalName: string,\n    operatingHours: string\n  }\n}\n\n// User information (sent after iframe_ready)\n{\n  userInfo: {\n    userName?: string,\n    userPhone?: string,\n    userLanguage?: string\n  }\n}\n```\n\n### Implementation Notes\n\n1. **Initialization Flow**:\n   - SDK loads iframe\n   - Iframe sends `{ type: \"iframe_ready\" }` when fully loaded\n   - SDK responds by sending hospital and user information\n2. **Dynamic Updates**:\n   - `setHospitalInfo()` and `setUserInfo()` send messages immediately\n   - No need to wait for ready signal on subsequent updates\n\n## Troubleshooting\n\n### Common Issues\n\n1. **SDK not initializing**: Make sure you're calling `init()` after the DOM is loaded.\n2. **Messages not being sent**: Check if the iframe has fully loaded before sending messages.\n3. **Styling conflicts**: Use the `customStyles` option to override default styles.\n\n### Debug Mode\n\n```javascript\n// Enable debug logging\nwindow.ChatSDKDebug = true;\nChatSDK.init();\n```\n\n## Version\n\nCurrent version: 2.0.0\n\n## License\n\nMIT License\n","readmeFilename":"README.md","_rev":"1-be184edf21c99799a9693fd71fadfcb9"}