|
1 | | -# 💬 Chatwoot iOS SDK (SwiftUI) |
| 1 | +# 💬 Chatwoot Agent iOS SDK (UIKit) |
2 | 2 |
|
3 | | -iOS SDK for Chatwoot |
| 3 | +A lightweight iOS SDK built with **Swift** and **UIKit** to embed a Chatwoot-powered chat interface in any iOS app. |
4 | 4 |
|
5 | 5 |
|
6 | 6 |
|
7 | | -## 📦 Installation |
| 7 | +## 🎯 Objective |
8 | 8 |
|
9 | | -### Option 1: Swift Package Manager (Recommended) |
| 9 | +- Enable any iOS app to launch a full-featured Chatwoot chat screen |
| 10 | +- Use UIKit for broad iOS compatibility (iOS 12+) |
10 | 11 |
|
11 | | -You can integrate the Chatwoot iOS SDK using Swift Package Manager: |
| 12 | +## 🧱 Supported Platforms |
12 | 13 |
|
13 | | -1. Open your Xcode project. |
14 | | -2. Navigate to `File > Add Packages...` |
15 | | -3. Enter the following URL in the search field: |
16 | | - ``` |
17 | | - https://github.com/chatwoot/agent-ios-sdk.git |
18 | | - ``` |
19 | | -4. Select the version you want to use (e.g. from version `1.0.0`) and click **Add Package**. |
| 14 | +- ✅ **Swift 5.7+** |
| 15 | +- ✅ **UIKit Framework** |
| 16 | +- ✅ **iOS 12+** (Broad device compatibility) |
| 17 | +- ✅ **SwiftUI Compatible** (via UIViewControllerRepresentable) |
20 | 18 |
|
21 | | -Then, import the SDK in your code: |
22 | | -```swift |
23 | | -import ChatwootSDK |
24 | | -``` |
25 | 19 |
|
26 | | -### Option 2: Manual via `Package.swift` |
27 | 20 |
|
28 | | -If you're managing dependencies directly with Swift Package Manager via `Package.swift`: |
| 21 | +## 📦 Installation |
| 22 | + |
| 23 | +### **Via Swift Package Manager (Remote)** |
| 24 | + |
| 25 | +In `Package.swift`: |
29 | 26 |
|
30 | 27 | ```swift |
31 | | -.package(url: "https://github.com/chatwoot/agent-ios-sdk.git", from: "1.0.0") |
| 28 | +.package(url: "https://github.com/chatwoot/ios-agent-sdk", from: "1.0.0") |
32 | 29 | ``` |
33 | 30 |
|
34 | | -Then, import the SDK where needed: |
| 31 | +### **Via Xcode (Local Package)** |
| 32 | + |
| 33 | +1. **Open your Xcode project** |
| 34 | +2. **Add Package Dependency:** |
| 35 | + - Go to **File → Add Package Dependencies...** |
| 36 | + - Click **Add Local..** (bottom left) |
| 37 | + - Navigate to your local `ios-sdk` folder |
| 38 | + - Select the folder and click **Add Package** |
| 39 | +3. **Configure Package:** Select your target(s) and click **Add Package** |
| 40 | + |
| 41 | +### **Import in your app:** |
| 42 | + |
35 | 43 | ```swift |
36 | 44 | import ChatwootSDK |
37 | 45 | ``` |
@@ -62,43 +70,63 @@ To enable photo capture or image upload features in the chat interface, **you mu |
62 | 70 | ## ⚙️ Configuration Parameters |
63 | 71 |
|
64 | 72 | | Parameter | Type | Required | Description | |
65 | | -|-----------------|-----------|----------|---------------------------------------------| |
| 73 | +|--|-----------|----------|---------------------------------------------| |
66 | 74 | | `accountId` | `Int` | ✅ | Unique ID for the Chatwoot account | |
67 | 75 | | `apiHost` | `String` | ✅ | Chatwoot API host URL | |
68 | 76 | | `accessToken` | `String` | ✅ | Access token for authentication | |
69 | 77 | | `pubsubToken` | `String` | ✅ | Token for real-time updates | |
70 | 78 | | `websocketUrl` | `String` | ✅ | WebSocket URL for real-time communication | |
71 | 79 |
|
| 80 | +--- |
72 | 81 |
|
73 | 82 | ## 🛠️ Example Usage |
74 | 83 |
|
75 | | -### Step 1: Set up the SDK |
| 84 | +### UIKit |
76 | 85 |
|
77 | 86 | ```swift |
| 87 | +import ChatwootSDK |
| 88 | + |
| 89 | +// 1. Setup in AppDelegate/SceneDelegate |
78 | 90 | ChatwootSDK.setup(ChatwootConfiguration( |
79 | 91 | accountId: 1, |
80 | 92 | apiHost: "https://your-chatwoot.com", |
81 | 93 | accessToken: "YOUR_ACCESS_TOKEN", |
82 | 94 | pubsubToken: "YOUR_PUBSUB_TOKEN", |
83 | 95 | websocketUrl: "wss://your-chatwoot.com" |
84 | 96 | )) |
| 97 | + |
| 98 | +// 2. Present chat modally |
| 99 | +ChatwootSDK.presentChat(from: self, conversationId: 123) |
85 | 100 | ``` |
86 | 101 |
|
87 | | -### Step 2: Show the Chat Interface |
| 102 | +### SwiftUI |
88 | 103 |
|
89 | 104 | ```swift |
90 | | -@State private var showChat = false |
91 | | -@State private var conversationId: Int = 123 // Required: conversation ID to load |
| 105 | +import SwiftUI |
| 106 | +import ChatwootSDK |
92 | 107 |
|
93 | | -var body: some View { |
94 | | - Button("Open Chat") { |
95 | | - showChat = true |
| 108 | +struct ChatwootWrapper: UIViewControllerRepresentable { |
| 109 | + let conversationId: Int |
| 110 | + |
| 111 | + func makeUIViewController(context: Context) -> UIViewController { |
| 112 | + return ChatwootSDK.loadChatUI(conversationId: conversationId) |
96 | 113 | } |
97 | | - .fullScreenCover(isPresented: $showChat) { |
98 | | - ChatwootSDK.loadChatUI(conversationId: conversationId) |
| 114 | + |
| 115 | + func updateUIViewController(_ uiViewController: UIViewController, context: Context) {} |
| 116 | +} |
| 117 | + |
| 118 | +struct ContentView: View { |
| 119 | + @State private var showChat = false |
| 120 | + |
| 121 | + var body: some View { |
| 122 | + Button("Open Chat") { |
| 123 | + showChat = true |
| 124 | + } |
| 125 | + .fullScreenCover(isPresented: $showChat) { |
| 126 | + ChatwootWrapper(conversationId: 123) |
| 127 | + } |
99 | 128 | } |
100 | 129 | } |
101 | 130 | ``` |
102 | 131 |
|
103 | | -The `conversationId` is required to load the chat UI. Make sure you have a valid conversation ID before calling `loadChatUI`. |
104 | | - |
| 132 | +The conversationId is required to load the chat UI. Make sure you have a valid conversation ID before calling loadChatUI. |
0 commit comments