@figoailabs/figochat-capacitor 0.0.0-stage → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/LICENSE +21 -0
- package/Package.swift +26 -0
- package/README.md +172 -2
- package/android/build.gradle +56 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/java/com/figolabs/figochat/capacitor/FigoChatPlugin.kt +100 -0
- package/dist/cjs/definitions.js +2 -0
- package/dist/cjs/index.js +24 -0
- package/dist/cjs/web.js +24 -0
- package/dist/esm/definitions.d.ts +60 -0
- package/dist/esm/definitions.js +1 -0
- package/dist/esm/index.d.ts +5 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/web.d.ts +12 -0
- package/dist/esm/web.js +20 -0
- package/ios/Sources/FigoChatPlugin/FigoChatPlugin.swift +90 -0
- package/package.json +38 -4
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 1.1.0
|
|
4
|
+
|
|
5
|
+
- First release: FigoChat for Capacitor 8 (Ionic Angular, React, Vue).
|
|
6
|
+
- `initialize`, `open`, `getThreadId`, `resetConversation`, `logout`.
|
|
7
|
+
- `messageSent` and `messageReceived` events.
|
|
8
|
+
- Uses the native FigoChat SDKs 1.1.0: iOS through Swift Package Manager from github.com/figoailabs/figochat-ios, Android through JitPack from github.com/figoailabs/figochat-android.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Figo AI Labs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/Package.swift
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// swift-tools-version: 5.9
|
|
2
|
+
// The package name must stay "FigoailabsFigochatCapacitor": the Capacitor CLI derives it from the npm name.
|
|
3
|
+
import PackageDescription
|
|
4
|
+
|
|
5
|
+
let package = Package(
|
|
6
|
+
name: "FigoailabsFigochatCapacitor",
|
|
7
|
+
platforms: [.iOS(.v16)],
|
|
8
|
+
products: [
|
|
9
|
+
.library(name: "FigoailabsFigochatCapacitor", targets: ["FigoChatPlugin"]),
|
|
10
|
+
],
|
|
11
|
+
dependencies: [
|
|
12
|
+
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "8.0.0"),
|
|
13
|
+
.package(url: "https://github.com/figoailabs/figochat-ios.git", from: "1.1.0"),
|
|
14
|
+
],
|
|
15
|
+
targets: [
|
|
16
|
+
.target(
|
|
17
|
+
name: "FigoChatPlugin",
|
|
18
|
+
dependencies: [
|
|
19
|
+
.product(name: "Capacitor", package: "capacitor-swift-pm"),
|
|
20
|
+
.product(name: "Cordova", package: "capacitor-swift-pm"),
|
|
21
|
+
.product(name: "FigoChat", package: "figochat-ios"),
|
|
22
|
+
],
|
|
23
|
+
path: "ios/Sources/FigoChatPlugin"
|
|
24
|
+
),
|
|
25
|
+
]
|
|
26
|
+
)
|
package/README.md
CHANGED
|
@@ -1,3 +1,173 @@
|
|
|
1
|
-
#
|
|
1
|
+
# FigoChat for Capacitor
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Add a Figo AI assistant chat to **Ionic and Capacitor apps** (Angular, React, Vue or plain JavaScript). Users can type, send voice notes and upload photos or files (images are read with OCR), and live agent replies appear in the same chat. The screen uses your brand color.
|
|
4
|
+
|
|
5
|
+
The plugin opens the native chat screen from the [FigoChat iOS SDK](https://github.com/figoailabs/figochat-ios) and [FigoChat Android SDK](https://github.com/figoailabs/figochat-android). It doesn't run in a browser.
|
|
6
|
+
|
|
7
|
+
- **Capacitor 8**
|
|
8
|
+
- **iOS 16+**, Swift Package Manager (the default for new Capacitor 8 apps)
|
|
9
|
+
- **Android 8.0+** (API 26)
|
|
10
|
+
|
|
11
|
+
## Before you start
|
|
12
|
+
|
|
13
|
+
You need an **API key** and an **assistant ID** from the FigoChat admin at [app.figolabs.ai](https://app.figolabs.ai):
|
|
14
|
+
|
|
15
|
+
- **API key:** click **API Keys** in the sidebar, then **Create API Key**. Copy the key right away: it's shown only once.
|
|
16
|
+
- **Assistant ID:** click **AI Chatbots** in the sidebar, open your chatbot, and copy its **Assistant ID**.
|
|
17
|
+
|
|
18
|
+
The company also needs at least 0.02 AI credits (see **Billing**).
|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install @figoailabs/figochat-capacitor
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npx cap sync
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### iOS
|
|
31
|
+
|
|
32
|
+
1. In Xcode, set the app target's **Minimum Deployments** to **iOS 16.0** or later (Capacitor's default is 15.0). Then run `npx cap sync ios` again.
|
|
33
|
+
2. Add the microphone description to `ios/App/App/Info.plist`:
|
|
34
|
+
|
|
35
|
+
```xml
|
|
36
|
+
<key>NSMicrophoneUsageDescription</key>
|
|
37
|
+
<string>Record voice messages for chat.</string>
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
The plugin needs Swift Package Manager. If your iOS project still uses CocoaPods (a `Podfile` in `ios/App`), migrate it first with `npx cap spm-migration-assistant`.
|
|
41
|
+
|
|
42
|
+
### Android
|
|
43
|
+
|
|
44
|
+
1. In `android/variables.gradle`, set `minSdkVersion = 26`.
|
|
45
|
+
2. In `android/build.gradle`, add JitPack to `allprojects.repositories`:
|
|
46
|
+
|
|
47
|
+
```groovy
|
|
48
|
+
allprojects {
|
|
49
|
+
repositories {
|
|
50
|
+
google()
|
|
51
|
+
mavenCentral()
|
|
52
|
+
maven { url 'https://jitpack.io' }
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
The SDK's manifest already declares the internet and microphone permissions and the chat screen. The microphone permission is requested the first time the user taps the mic.
|
|
58
|
+
|
|
59
|
+
## Use
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
import { FigoChat } from '@figoailabs/figochat-capacitor';
|
|
63
|
+
|
|
64
|
+
// once, for example after the user signs in
|
|
65
|
+
await FigoChat.initialize({
|
|
66
|
+
apiKey: 'YOUR_API_KEY',
|
|
67
|
+
assistantId: 'YOUR_ASSISTANT_ID',
|
|
68
|
+
fullName: 'Ada Lovelace',
|
|
69
|
+
emailAddress: 'ada@example.com',
|
|
70
|
+
mobilePhone: '+2348012345678',
|
|
71
|
+
primaryColor: '#F97316',
|
|
72
|
+
title: 'Support',
|
|
73
|
+
welcomeMessage: 'Hi Ada! How can I help you today?',
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// from a button
|
|
77
|
+
await FigoChat.open();
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Angular service
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
import { Injectable } from '@angular/core';
|
|
84
|
+
import type { PluginListenerHandle } from '@capacitor/core';
|
|
85
|
+
import { FigoChat } from '@figoailabs/figochat-capacitor';
|
|
86
|
+
|
|
87
|
+
@Injectable({ providedIn: 'root' })
|
|
88
|
+
export class ChatService {
|
|
89
|
+
private handles: PluginListenerHandle[] = [];
|
|
90
|
+
|
|
91
|
+
async start(user: { name: string; email: string; phone: string }) {
|
|
92
|
+
await FigoChat.initialize({
|
|
93
|
+
apiKey: 'YOUR_API_KEY',
|
|
94
|
+
assistantId: 'YOUR_ASSISTANT_ID',
|
|
95
|
+
fullName: user.name,
|
|
96
|
+
emailAddress: user.email,
|
|
97
|
+
mobilePhone: user.phone,
|
|
98
|
+
primaryColor: '#F97316',
|
|
99
|
+
});
|
|
100
|
+
this.handles.push(
|
|
101
|
+
await FigoChat.addListener('messageSent', (e) => console.log('User:', e.text)),
|
|
102
|
+
await FigoChat.addListener('messageReceived', (e) => console.log('Assistant:', e.text)),
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
open() {
|
|
107
|
+
return FigoChat.open();
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
async stop() {
|
|
111
|
+
await Promise.all(this.handles.map((h) => h.remove()));
|
|
112
|
+
await FigoChat.logout();
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## API
|
|
118
|
+
|
|
119
|
+
| Method | Description |
|
|
120
|
+
|---|---|
|
|
121
|
+
| `initialize(options)` | Configures the SDK. Call it once and again whenever the user or settings change. |
|
|
122
|
+
| `open()` | Opens the native chat screen full screen. |
|
|
123
|
+
| `getThreadId()` | `{ threadId }` of the current conversation, or `null` before the first reply. Save it to resume later with `initialize({ threadId })`. |
|
|
124
|
+
| `resetConversation()` | The next message starts a new conversation. |
|
|
125
|
+
| `logout()` | Clears the settings, e.g. when the user signs out. |
|
|
126
|
+
| `addListener('messageSent', fn)` | Fired when the API accepts the user's message; `fn({ text })` gets the text the user sent. |
|
|
127
|
+
| `addListener('messageReceived', fn)` | Fired for each assistant reply and each live agent message; `fn({ text })` gets the reply as plain text. |
|
|
128
|
+
| `removeAllListeners()` | Removes every listener. |
|
|
129
|
+
|
|
130
|
+
### `initialize` options
|
|
131
|
+
|
|
132
|
+
| Option | Required | Description |
|
|
133
|
+
|---|---|---|
|
|
134
|
+
| `apiKey` | ✓ | API key from **API Keys** in the FigoChat admin |
|
|
135
|
+
| `assistantId` | ✓ | **AI Chatbots** → your chatbot → **Assistant ID** |
|
|
136
|
+
| `fullName`, `emailAddress`, `mobilePhone` | ✓ | The signed-in user; phone ideally in international format |
|
|
137
|
+
| `primaryColor` | ✓ | Brand color as hex, e.g. `#F97316` |
|
|
138
|
+
| `title` | | Header title. Defaults to `Chat` |
|
|
139
|
+
| `welcomeMessage` | | First assistant message. HTML is rendered |
|
|
140
|
+
| `threadId` | | Resume an earlier conversation |
|
|
141
|
+
| `maxFiles` | | Most files per message. Defaults to 5 |
|
|
142
|
+
| `maxFileSizeMB` | | Largest file. Defaults to 10 |
|
|
143
|
+
| `autoSendVoice` | | Send a transcribed voice note right away. Defaults to `true` |
|
|
144
|
+
| `timeout` | | Request timeout in milliseconds. Defaults to 120000 |
|
|
145
|
+
| `baseUrl` | | API host. Defaults to `https://api.figolabs.ai` |
|
|
146
|
+
|
|
147
|
+
### Errors
|
|
148
|
+
|
|
149
|
+
Calls reject with a `code`:
|
|
150
|
+
|
|
151
|
+
| Code | When |
|
|
152
|
+
|---|---|
|
|
153
|
+
| `CONFIG` | `initialize` is missing a required value, or `primaryColor` isn't hex |
|
|
154
|
+
| `NOT_INITIALIZED` | `open` was called before `initialize` |
|
|
155
|
+
| `UNIMPLEMENTED` | Called in a browser (for example `ionic serve`) |
|
|
156
|
+
|
|
157
|
+
Inside the chat, users see friendly messages, such as "Chat isn't available right now. Please try again later." for a bad key or no credits. Technical details are never shown to them.
|
|
158
|
+
|
|
159
|
+
## What the chat does
|
|
160
|
+
|
|
161
|
+
- Assistant replies arrive as HTML and are shown as formatted text: bold, italics, lists and tappable links.
|
|
162
|
+
- Voice notes: tap the mic, speak, tap stop. The screen shows "Processing your voice message…" and then sends the text.
|
|
163
|
+
- Files and photos upload as soon as they're picked and go with the next message.
|
|
164
|
+
- Live agents (Tawk.to, Zoho SalesIQ, FreshChat) reply in the same chat.
|
|
165
|
+
- A small "Powered by Figo AI Labs" footer links to [figolabs.ai](https://figolabs.ai).
|
|
166
|
+
|
|
167
|
+
## API key security
|
|
168
|
+
|
|
169
|
+
The API key ships inside your app, so anyone who unpacks the app can read it and spend your credits. Create a key just for the app under **API Keys** in the FigoChat admin. Keys expire 3 years after they're created. If a key leaks, delete it there and ship an update with a new key. For stronger protection, have your backend hand the key to the app after the user signs in.
|
|
170
|
+
|
|
171
|
+
## License
|
|
172
|
+
|
|
173
|
+
MIT
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// FigoChat Capacitor plugin. Uses the FigoChat Android SDK from JitPack (github.com/figoailabs/figochat-android).
|
|
2
|
+
ext {
|
|
3
|
+
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.1'
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
buildscript {
|
|
7
|
+
ext.kotlin_version = project.hasProperty('kotlin_version') ? rootProject.ext.kotlin_version : '2.1.0'
|
|
8
|
+
repositories {
|
|
9
|
+
google()
|
|
10
|
+
mavenCentral()
|
|
11
|
+
}
|
|
12
|
+
dependencies {
|
|
13
|
+
classpath 'com.android.tools.build:gradle:8.13.0'
|
|
14
|
+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
apply plugin: 'com.android.library'
|
|
19
|
+
apply plugin: 'kotlin-android'
|
|
20
|
+
|
|
21
|
+
android {
|
|
22
|
+
namespace = "com.figolabs.figochat.capacitor"
|
|
23
|
+
compileSdk = project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 36
|
|
24
|
+
defaultConfig {
|
|
25
|
+
// the FigoChat Android SDK needs Android 8.0 (API 26)
|
|
26
|
+
minSdkVersion 26
|
|
27
|
+
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 36
|
|
28
|
+
}
|
|
29
|
+
buildTypes {
|
|
30
|
+
release {
|
|
31
|
+
minifyEnabled false
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
lint {
|
|
35
|
+
abortOnError = false
|
|
36
|
+
}
|
|
37
|
+
compileOptions {
|
|
38
|
+
sourceCompatibility JavaVersion.VERSION_17
|
|
39
|
+
targetCompatibility JavaVersion.VERSION_17
|
|
40
|
+
}
|
|
41
|
+
kotlinOptions {
|
|
42
|
+
jvmTarget = '17'
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
repositories {
|
|
47
|
+
google()
|
|
48
|
+
mavenCentral()
|
|
49
|
+
maven { url 'https://jitpack.io' }
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
dependencies {
|
|
53
|
+
implementation project(':capacitor-android')
|
|
54
|
+
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
|
55
|
+
implementation 'com.github.figoailabs:figochat-android:1.1.0'
|
|
56
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
package com.figolabs.figochat.capacitor
|
|
2
|
+
|
|
3
|
+
import com.figolabs.figochat.FigoChat
|
|
4
|
+
import com.figolabs.figochat.FigoChatException
|
|
5
|
+
import com.figolabs.figochat.FigoChatListener
|
|
6
|
+
import com.getcapacitor.JSObject
|
|
7
|
+
import com.getcapacitor.Plugin
|
|
8
|
+
import com.getcapacitor.PluginCall
|
|
9
|
+
import com.getcapacitor.PluginMethod
|
|
10
|
+
import com.getcapacitor.annotation.CapacitorPlugin
|
|
11
|
+
|
|
12
|
+
/** Bridges the FigoChat Android SDK to JavaScript as `FigoChat`. */
|
|
13
|
+
@CapacitorPlugin(name = "FigoChat")
|
|
14
|
+
class FigoChatPlugin : Plugin() {
|
|
15
|
+
|
|
16
|
+
private val listener = object : FigoChatListener {
|
|
17
|
+
override fun onMessageSent(text: String) {
|
|
18
|
+
notifyListeners("messageSent", JSObject().put("text", text))
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
override fun onMessageReceived(text: String) {
|
|
22
|
+
notifyListeners("messageReceived", JSObject().put("text", text))
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
override fun load() {
|
|
27
|
+
FigoChat.addListener(listener)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
override fun handleOnDestroy() {
|
|
31
|
+
FigoChat.removeListener(listener)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
@PluginMethod
|
|
35
|
+
fun initialize(call: PluginCall) {
|
|
36
|
+
try {
|
|
37
|
+
FigoChat.initialize(
|
|
38
|
+
apiKey = call.getString("apiKey") ?: "",
|
|
39
|
+
fullName = call.getString("fullName") ?: "",
|
|
40
|
+
emailAddress = call.getString("emailAddress") ?: "",
|
|
41
|
+
mobilePhone = call.getString("mobilePhone") ?: "",
|
|
42
|
+
assistantId = call.getString("assistantId") ?: "",
|
|
43
|
+
primaryColor = call.getString("primaryColor") ?: "",
|
|
44
|
+
baseUrl = call.getString("baseUrl") ?: "https://api.figolabs.ai",
|
|
45
|
+
title = call.getString("title") ?: "Chat",
|
|
46
|
+
welcomeMessage = call.getString("welcomeMessage"),
|
|
47
|
+
threadId = call.getString("threadId"),
|
|
48
|
+
maxFiles = call.getInt("maxFiles") ?: 5,
|
|
49
|
+
maxFileSizeMB = call.getInt("maxFileSizeMB") ?: 10,
|
|
50
|
+
autoSendVoice = call.getBoolean("autoSendVoice") ?: true,
|
|
51
|
+
timeoutMillis = call.getDouble("timeout")?.toLong() ?: 120_000L,
|
|
52
|
+
)
|
|
53
|
+
call.resolve()
|
|
54
|
+
} catch (e: FigoChatException) {
|
|
55
|
+
call.reject(e.message, e.code)
|
|
56
|
+
} catch (e: Exception) {
|
|
57
|
+
call.reject(e.message, "UNKNOWN")
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
@PluginMethod
|
|
62
|
+
fun open(call: PluginCall) {
|
|
63
|
+
if (!FigoChat.isInitialized) {
|
|
64
|
+
call.reject("FigoChat is not initialized. Call FigoChat.initialize(...) first.", "NOT_INITIALIZED")
|
|
65
|
+
return
|
|
66
|
+
}
|
|
67
|
+
val activity = activity
|
|
68
|
+
if (activity == null) {
|
|
69
|
+
call.reject("No activity to open the chat from.", "UNAVAILABLE")
|
|
70
|
+
return
|
|
71
|
+
}
|
|
72
|
+
activity.runOnUiThread {
|
|
73
|
+
try {
|
|
74
|
+
FigoChat.open(activity)
|
|
75
|
+
call.resolve()
|
|
76
|
+
} catch (e: FigoChatException) {
|
|
77
|
+
call.reject(e.message, e.code)
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
@PluginMethod
|
|
83
|
+
fun getThreadId(call: PluginCall) {
|
|
84
|
+
val result = JSObject()
|
|
85
|
+
result.put("threadId", FigoChat.threadId ?: org.json.JSONObject.NULL)
|
|
86
|
+
call.resolve(result)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
@PluginMethod
|
|
90
|
+
fun resetConversation(call: PluginCall) {
|
|
91
|
+
FigoChat.resetConversation()
|
|
92
|
+
call.resolve()
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
@PluginMethod
|
|
96
|
+
fun logout(call: PluginCall) {
|
|
97
|
+
FigoChat.logout()
|
|
98
|
+
call.resolve()
|
|
99
|
+
}
|
|
100
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.FigoChat = void 0;
|
|
18
|
+
const core_1 = require("@capacitor/core");
|
|
19
|
+
/** FigoChat for Capacitor. Runs the native FigoChat SDK on iOS and Android. */
|
|
20
|
+
const FigoChat = (0, core_1.registerPlugin)('FigoChat', {
|
|
21
|
+
web: () => Promise.resolve().then(() => require('./web')).then((m) => new m.FigoChatWeb()),
|
|
22
|
+
});
|
|
23
|
+
exports.FigoChat = FigoChat;
|
|
24
|
+
__exportStar(require("./definitions"), exports);
|
package/dist/cjs/web.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FigoChatWeb = void 0;
|
|
4
|
+
const core_1 = require("@capacitor/core");
|
|
5
|
+
const UNAVAILABLE = 'FigoChat runs on iOS and Android only. It is not available in the browser.';
|
|
6
|
+
/** In the browser (e.g. `ionic serve`) every call rejects with code `UNIMPLEMENTED`. */
|
|
7
|
+
class FigoChatWeb extends core_1.WebPlugin {
|
|
8
|
+
async initialize(_options) {
|
|
9
|
+
throw this.unimplemented(UNAVAILABLE);
|
|
10
|
+
}
|
|
11
|
+
async open() {
|
|
12
|
+
throw this.unimplemented(UNAVAILABLE);
|
|
13
|
+
}
|
|
14
|
+
async getThreadId() {
|
|
15
|
+
throw this.unimplemented(UNAVAILABLE);
|
|
16
|
+
}
|
|
17
|
+
async resetConversation() {
|
|
18
|
+
throw this.unimplemented(UNAVAILABLE);
|
|
19
|
+
}
|
|
20
|
+
async logout() {
|
|
21
|
+
throw this.unimplemented(UNAVAILABLE);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.FigoChatWeb = FigoChatWeb;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { PluginListenerHandle } from '@capacitor/core';
|
|
2
|
+
/** Settings passed to `FigoChat.initialize`. */
|
|
3
|
+
export interface FigoChatOptions {
|
|
4
|
+
/** API key from **API Keys** in the FigoChat admin (app.figolabs.ai). Sent as `Authorization: Bearer <apiKey>`. */
|
|
5
|
+
apiKey: string;
|
|
6
|
+
/** Assistant ID: **AI Chatbots** → your chatbot → **Assistant ID** in the admin. */
|
|
7
|
+
assistantId: string;
|
|
8
|
+
/** Full name of the signed-in user of your app. */
|
|
9
|
+
fullName: string;
|
|
10
|
+
/** Email address of the signed-in user. */
|
|
11
|
+
emailAddress: string;
|
|
12
|
+
/** Mobile phone of the signed-in user, ideally in international format (e.g. +2348012345678). */
|
|
13
|
+
mobilePhone: string;
|
|
14
|
+
/** Brand color for the header, user bubbles and buttons, as hex (e.g. `#F97316`). */
|
|
15
|
+
primaryColor: string;
|
|
16
|
+
/** API host. Defaults to `https://api.figolabs.ai`. */
|
|
17
|
+
baseUrl?: string;
|
|
18
|
+
/** Header title. Defaults to `Chat`. */
|
|
19
|
+
title?: string;
|
|
20
|
+
/** First assistant message, shown before the user writes anything. HTML is rendered. */
|
|
21
|
+
welcomeMessage?: string;
|
|
22
|
+
/** Resume an earlier conversation with the value from `getThreadId()`. */
|
|
23
|
+
threadId?: string;
|
|
24
|
+
/** Most files per message. Defaults to 5. */
|
|
25
|
+
maxFiles?: number;
|
|
26
|
+
/** Largest file accepted, in megabytes. Defaults to 10. */
|
|
27
|
+
maxFileSizeMB?: number;
|
|
28
|
+
/** Send a transcribed voice note right away (true) or put the text in the input for editing (false). Defaults to true. */
|
|
29
|
+
autoSendVoice?: boolean;
|
|
30
|
+
/** Request timeout in milliseconds. Defaults to 120000. */
|
|
31
|
+
timeout?: number;
|
|
32
|
+
}
|
|
33
|
+
/** Payload of the `messageSent` and `messageReceived` events. */
|
|
34
|
+
export interface FigoChatMessageEvent {
|
|
35
|
+
/** `messageSent`: the text the user sent. `messageReceived`: the reply as plain text (HTML stripped). */
|
|
36
|
+
text: string;
|
|
37
|
+
}
|
|
38
|
+
export interface FigoChatPlugin {
|
|
39
|
+
/**
|
|
40
|
+
* Configures the SDK. Call it once, for example after the user signs in, and again whenever the user or the
|
|
41
|
+
* settings change. Rejects with code `CONFIG` when a required value is missing or the color isn't hex.
|
|
42
|
+
*/
|
|
43
|
+
initialize(options: FigoChatOptions): Promise<void>;
|
|
44
|
+
/** Opens the native chat screen full screen. Rejects with code `NOT_INITIALIZED` before `initialize`. */
|
|
45
|
+
open(): Promise<void>;
|
|
46
|
+
/** Thread ID of the current conversation, or `null` before the first reply. Save it to resume later. */
|
|
47
|
+
getThreadId(): Promise<{
|
|
48
|
+
threadId: string | null;
|
|
49
|
+
}>;
|
|
50
|
+
/** The next message starts a new conversation. */
|
|
51
|
+
resetConversation(): Promise<void>;
|
|
52
|
+
/** Clears the settings, e.g. when the user signs out. */
|
|
53
|
+
logout(): Promise<void>;
|
|
54
|
+
/** Fired when the API accepts the user's message. */
|
|
55
|
+
addListener(eventName: 'messageSent', listenerFunc: (event: FigoChatMessageEvent) => void): Promise<PluginListenerHandle>;
|
|
56
|
+
/** Fired for each assistant reply and each live agent message, with the reply as plain text. */
|
|
57
|
+
addListener(eventName: 'messageReceived', listenerFunc: (event: FigoChatMessageEvent) => void): Promise<PluginListenerHandle>;
|
|
58
|
+
/** Removes every listener added with `addListener`. */
|
|
59
|
+
removeAllListeners(): Promise<void>;
|
|
60
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { registerPlugin } from '@capacitor/core';
|
|
2
|
+
/** FigoChat for Capacitor. Runs the native FigoChat SDK on iOS and Android. */
|
|
3
|
+
const FigoChat = registerPlugin('FigoChat', {
|
|
4
|
+
web: () => import('./web').then((m) => new m.FigoChatWeb()),
|
|
5
|
+
});
|
|
6
|
+
export * from './definitions';
|
|
7
|
+
export { FigoChat };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
import type { FigoChatOptions, FigoChatPlugin } from './definitions';
|
|
3
|
+
/** In the browser (e.g. `ionic serve`) every call rejects with code `UNIMPLEMENTED`. */
|
|
4
|
+
export declare class FigoChatWeb extends WebPlugin implements FigoChatPlugin {
|
|
5
|
+
initialize(_options: FigoChatOptions): Promise<void>;
|
|
6
|
+
open(): Promise<void>;
|
|
7
|
+
getThreadId(): Promise<{
|
|
8
|
+
threadId: string | null;
|
|
9
|
+
}>;
|
|
10
|
+
resetConversation(): Promise<void>;
|
|
11
|
+
logout(): Promise<void>;
|
|
12
|
+
}
|
package/dist/esm/web.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { WebPlugin } from '@capacitor/core';
|
|
2
|
+
const UNAVAILABLE = 'FigoChat runs on iOS and Android only. It is not available in the browser.';
|
|
3
|
+
/** In the browser (e.g. `ionic serve`) every call rejects with code `UNIMPLEMENTED`. */
|
|
4
|
+
export class FigoChatWeb extends WebPlugin {
|
|
5
|
+
async initialize(_options) {
|
|
6
|
+
throw this.unimplemented(UNAVAILABLE);
|
|
7
|
+
}
|
|
8
|
+
async open() {
|
|
9
|
+
throw this.unimplemented(UNAVAILABLE);
|
|
10
|
+
}
|
|
11
|
+
async getThreadId() {
|
|
12
|
+
throw this.unimplemented(UNAVAILABLE);
|
|
13
|
+
}
|
|
14
|
+
async resetConversation() {
|
|
15
|
+
throw this.unimplemented(UNAVAILABLE);
|
|
16
|
+
}
|
|
17
|
+
async logout() {
|
|
18
|
+
throw this.unimplemented(UNAVAILABLE);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import Capacitor
|
|
2
|
+
import FigoChat
|
|
3
|
+
import Foundation
|
|
4
|
+
|
|
5
|
+
/// Bridges the FigoChat iOS SDK to JavaScript as `FigoChat`.
|
|
6
|
+
@objc(FigoChatPlugin)
|
|
7
|
+
public class FigoChatPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
8
|
+
public let identifier = "FigoChatPlugin"
|
|
9
|
+
public let jsName = "FigoChat"
|
|
10
|
+
public let pluginMethods: [CAPPluginMethod] = [
|
|
11
|
+
CAPPluginMethod(name: "initialize", returnType: CAPPluginReturnPromise),
|
|
12
|
+
CAPPluginMethod(name: "open", returnType: CAPPluginReturnPromise),
|
|
13
|
+
CAPPluginMethod(name: "getThreadId", returnType: CAPPluginReturnPromise),
|
|
14
|
+
CAPPluginMethod(name: "resetConversation", returnType: CAPPluginReturnPromise),
|
|
15
|
+
CAPPluginMethod(name: "logout", returnType: CAPPluginReturnPromise),
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
private var listenerToken: FigoChatListenerToken?
|
|
19
|
+
|
|
20
|
+
override public func load() {
|
|
21
|
+
listenerToken = FigoChat.addListener(
|
|
22
|
+
onMessageSent: { [weak self] text in self?.notifyListeners("messageSent", data: ["text": text]) },
|
|
23
|
+
onMessageReceived: { [weak self] text in self?.notifyListeners("messageReceived", data: ["text": text]) }
|
|
24
|
+
)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
deinit {
|
|
28
|
+
if let token = listenerToken { FigoChat.removeListener(token) }
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
@objc func initialize(_ call: CAPPluginCall) {
|
|
32
|
+
let baseURL = call.getString("baseUrl").flatMap(URL.init(string:)) ?? FigoChatConfig.defaultBaseURL
|
|
33
|
+
do {
|
|
34
|
+
try FigoChat.initialize(
|
|
35
|
+
apiKey: call.getString("apiKey") ?? "",
|
|
36
|
+
fullName: call.getString("fullName") ?? "",
|
|
37
|
+
emailAddress: call.getString("emailAddress") ?? "",
|
|
38
|
+
mobilePhone: call.getString("mobilePhone") ?? "",
|
|
39
|
+
assistantId: call.getString("assistantId") ?? "",
|
|
40
|
+
primaryColor: call.getString("primaryColor") ?? "",
|
|
41
|
+
baseURL: baseURL,
|
|
42
|
+
title: call.getString("title") ?? "Chat",
|
|
43
|
+
welcomeMessage: call.getString("welcomeMessage"),
|
|
44
|
+
threadId: call.getString("threadId"),
|
|
45
|
+
maxFiles: call.getInt("maxFiles") ?? 5,
|
|
46
|
+
maxFileSizeMB: call.getInt("maxFileSizeMB") ?? 10,
|
|
47
|
+
autoSendVoice: call.getBool("autoSendVoice") ?? true,
|
|
48
|
+
timeout: (call.getDouble("timeout") ?? 120_000) / 1000
|
|
49
|
+
)
|
|
50
|
+
call.resolve()
|
|
51
|
+
} catch let error as FigoChatError {
|
|
52
|
+
call.reject(error.message, error.code)
|
|
53
|
+
} catch {
|
|
54
|
+
call.reject(error.localizedDescription, "UNKNOWN")
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
@objc func open(_ call: CAPPluginCall) {
|
|
59
|
+
guard FigoChat.isInitialized else {
|
|
60
|
+
call.reject("FigoChat is not initialized. Call FigoChat.initialize(...) first.", "NOT_INITIALIZED")
|
|
61
|
+
return
|
|
62
|
+
}
|
|
63
|
+
Task { @MainActor [weak self] in
|
|
64
|
+
guard let presenter = self?.bridge?.viewController else {
|
|
65
|
+
call.reject("No view controller to present the chat from.", "UNAVAILABLE")
|
|
66
|
+
return
|
|
67
|
+
}
|
|
68
|
+
FigoChat.present(from: presenter)
|
|
69
|
+
call.resolve()
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
@objc func getThreadId(_ call: CAPPluginCall) {
|
|
74
|
+
if let threadId = FigoChat.threadId {
|
|
75
|
+
call.resolve(["threadId": threadId])
|
|
76
|
+
} else {
|
|
77
|
+
call.resolve(["threadId": NSNull()])
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
@objc func resetConversation(_ call: CAPPluginCall) {
|
|
82
|
+
FigoChat.resetConversation()
|
|
83
|
+
call.resolve()
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
@objc func logout(_ call: CAPPluginCall) {
|
|
87
|
+
FigoChat.logout()
|
|
88
|
+
call.resolve()
|
|
89
|
+
}
|
|
90
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,40 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@figoailabs/figochat-capacitor",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "FigoChat for Capacitor and Ionic apps (Angular, React, Vue): a native AI assistant chat with voice notes, file uploads and live agents, built on the FigoChat iOS and Android SDKs.",
|
|
5
|
+
"main": "dist/cjs/index.js",
|
|
6
|
+
"module": "dist/esm/index.js",
|
|
7
|
+
"types": "dist/esm/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"android/src/main/",
|
|
10
|
+
"android/build.gradle",
|
|
11
|
+
"dist/",
|
|
12
|
+
"ios/Sources",
|
|
13
|
+
"Package.swift",
|
|
14
|
+
"README.md",
|
|
15
|
+
"CHANGELOG.md",
|
|
16
|
+
"LICENSE"
|
|
17
|
+
],
|
|
18
|
+
"author": "Figo AI Labs <hello@figolabs.ai>",
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"homepage": "https://figolabs.ai",
|
|
21
|
+
"keywords": ["capacitor", "plugin", "native", "ionic", "angular", "figochat", "chat", "chatbot", "ai", "assistant"],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"clean": "rm -rf dist",
|
|
24
|
+
"build": "npm run clean && tsc -p tsconfig.json && tsc -p tsconfig.cjs.json",
|
|
25
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
26
|
+
"prepublishOnly": "npm run build"
|
|
27
|
+
},
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"@capacitor/core": ">=8.0.0"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@capacitor/core": "8.6.2",
|
|
33
|
+
"typescript": "~5.9.2"
|
|
34
|
+
},
|
|
35
|
+
"capacitor": {
|
|
36
|
+
"ios": { "src": "ios" },
|
|
37
|
+
"android": { "src": "android" }
|
|
38
|
+
},
|
|
39
|
+
"publishConfig": { "access": "public" }
|
|
40
|
+
}
|