@figoailabs/figochat-capacitor 0.0.0-stage → 2.0.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 ADDED
@@ -0,0 +1,15 @@
1
+ # Changelog
2
+
3
+ ## 2.0.0
4
+
5
+ - **Breaking:** `title` and `welcomeMessage` are removed from `initialize`. The header title, welcome message and waiting message now come from the chatbot's settings in the FigoChat admin (**Persona** or **Name**, **Welcome Message**, **Choose a Waiting Message**), loaded from the new `GET /api/v1/sdk/assistant/{assistantId}` API.
6
+ - New `firstCustomerMessage` option: sent for the customer as soon as `initialize` runs. The chat opens with it and its reply, and continues the same thread.
7
+ - While a reply is on its way, the chatbot's waiting message shows on the left with animated dots.
8
+ - Uses the native FigoChat SDKs 2.0.0 (figochat-ios and figochat-android).
9
+
10
+ ## 1.1.0
11
+
12
+ - First release: FigoChat for Capacitor 8 (Ionic Angular, React, Vue).
13
+ - `initialize`, `open`, `getThreadId`, `resetConversation`, `logout`.
14
+ - `messageSent` and `messageReceived` events.
15
+ - 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: "2.0.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,175 @@
1
- # Temporary Holding Version
1
+ # FigoChat for Capacitor
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
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
+ // optional: send the customer's first question for them
73
+ firstCustomerMessage: 'Where is my order #1042?',
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
+ | `firstCustomerMessage` | | Sent for the customer as soon as `initialize` runs; the chat opens with it and its reply |
139
+ | `threadId` | | Resume an earlier conversation |
140
+ | `maxFiles` | | Most files per message. Defaults to 5 |
141
+ | `maxFileSizeMB` | | Largest file. Defaults to 10 |
142
+ | `autoSendVoice` | | Send a transcribed voice note right away. Defaults to `true` |
143
+ | `timeout` | | Request timeout in milliseconds. Defaults to 120000 |
144
+ | `baseUrl` | | API host. Defaults to `https://api.figolabs.ai` |
145
+
146
+ The header title, welcome message and waiting message come from the chatbot's settings in the FigoChat admin (**AI Chatbots** → your chatbot → **Edit**: **Persona** or **Name**, **Welcome Message**, **Choose a Waiting Message**), so they aren't passed to `initialize`. `firstCustomerMessage` is sent for the customer straight away; the chat opens with it and its reply, and continues the same thread.
147
+
148
+
149
+ ### Errors
150
+
151
+ Calls reject with a `code`:
152
+
153
+ | Code | When |
154
+ |---|---|
155
+ | `CONFIG` | `initialize` is missing a required value, or `primaryColor` isn't hex |
156
+ | `NOT_INITIALIZED` | `open` was called before `initialize` |
157
+ | `UNIMPLEMENTED` | Called in a browser (for example `ionic serve`) |
158
+
159
+ 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.
160
+
161
+ ## What the chat does
162
+
163
+ - Assistant replies arrive as HTML and are shown as formatted text: bold, italics, lists and tappable links.
164
+ - Voice notes: tap the mic, speak, tap stop. The screen shows "Processing your voice message…" and then sends the text.
165
+ - Files and photos upload as soon as they're picked and go with the next message.
166
+ - Live agents (Tawk.to, Zoho SalesIQ, FreshChat) reply in the same chat.
167
+ - A small "Powered by Figo AI Labs" footer links to [figolabs.ai](https://figolabs.ai).
168
+
169
+ ## API key security
170
+
171
+ 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.
172
+
173
+ ## License
174
+
175
+ 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:2.0.0'
56
+ }
@@ -0,0 +1,3 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <!-- Permissions (internet, microphone) and the chat activity come from the FigoChat Android SDK's manifest. -->
3
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android" />
@@ -0,0 +1,99 @@
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
+ firstCustomerMessage = call.getString("firstCustomerMessage"),
46
+ threadId = call.getString("threadId"),
47
+ maxFiles = call.getInt("maxFiles") ?: 5,
48
+ maxFileSizeMB = call.getInt("maxFileSizeMB") ?: 10,
49
+ autoSendVoice = call.getBoolean("autoSendVoice") ?: true,
50
+ timeoutMillis = call.getDouble("timeout")?.toLong() ?: 120_000L,
51
+ )
52
+ call.resolve()
53
+ } catch (e: FigoChatException) {
54
+ call.reject(e.message, e.code)
55
+ } catch (e: Exception) {
56
+ call.reject(e.message, "UNKNOWN")
57
+ }
58
+ }
59
+
60
+ @PluginMethod
61
+ fun open(call: PluginCall) {
62
+ if (!FigoChat.isInitialized) {
63
+ call.reject("FigoChat is not initialized. Call FigoChat.initialize(...) first.", "NOT_INITIALIZED")
64
+ return
65
+ }
66
+ val activity = activity
67
+ if (activity == null) {
68
+ call.reject("No activity to open the chat from.", "UNAVAILABLE")
69
+ return
70
+ }
71
+ activity.runOnUiThread {
72
+ try {
73
+ FigoChat.open(activity)
74
+ call.resolve()
75
+ } catch (e: FigoChatException) {
76
+ call.reject(e.message, e.code)
77
+ }
78
+ }
79
+ }
80
+
81
+ @PluginMethod
82
+ fun getThreadId(call: PluginCall) {
83
+ val result = JSObject()
84
+ result.put("threadId", FigoChat.threadId ?: org.json.JSONObject.NULL)
85
+ call.resolve(result)
86
+ }
87
+
88
+ @PluginMethod
89
+ fun resetConversation(call: PluginCall) {
90
+ FigoChat.resetConversation()
91
+ call.resolve()
92
+ }
93
+
94
+ @PluginMethod
95
+ fun logout(call: PluginCall) {
96
+ FigoChat.logout()
97
+ call.resolve()
98
+ }
99
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -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);
@@ -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,61 @@
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
+ /**
19
+ * A message to send on the customer's behalf as soon as `initialize` runs, for example the question they typed
20
+ * on your own screen. The reply and the thread are kept, so the chat opens with both and continues from there.
21
+ */
22
+ firstCustomerMessage?: string;
23
+ /** Resume an earlier conversation with the value from `getThreadId()`. */
24
+ threadId?: string;
25
+ /** Most files per message. Defaults to 5. */
26
+ maxFiles?: number;
27
+ /** Largest file accepted, in megabytes. Defaults to 10. */
28
+ maxFileSizeMB?: number;
29
+ /** Send a transcribed voice note right away (true) or put the text in the input for editing (false). Defaults to true. */
30
+ autoSendVoice?: boolean;
31
+ /** Request timeout in milliseconds. Defaults to 120000. */
32
+ timeout?: number;
33
+ }
34
+ /** Payload of the `messageSent` and `messageReceived` events. */
35
+ export interface FigoChatMessageEvent {
36
+ /** `messageSent`: the text the user sent. `messageReceived`: the reply as plain text (HTML stripped). */
37
+ text: string;
38
+ }
39
+ export interface FigoChatPlugin {
40
+ /**
41
+ * Configures the SDK. Call it once, for example after the user signs in, and again whenever the user or the
42
+ * settings change. Rejects with code `CONFIG` when a required value is missing or the color isn't hex.
43
+ */
44
+ initialize(options: FigoChatOptions): Promise<void>;
45
+ /** Opens the native chat screen full screen. Rejects with code `NOT_INITIALIZED` before `initialize`. */
46
+ open(): Promise<void>;
47
+ /** Thread ID of the current conversation, or `null` before the first reply. Save it to resume later. */
48
+ getThreadId(): Promise<{
49
+ threadId: string | null;
50
+ }>;
51
+ /** The next message starts a new conversation. */
52
+ resetConversation(): Promise<void>;
53
+ /** Clears the settings, e.g. when the user signs out. */
54
+ logout(): Promise<void>;
55
+ /** Fired when the API accepts the user's message. */
56
+ addListener(eventName: 'messageSent', listenerFunc: (event: FigoChatMessageEvent) => void): Promise<PluginListenerHandle>;
57
+ /** Fired for each assistant reply and each live agent message, with the reply as plain text. */
58
+ addListener(eventName: 'messageReceived', listenerFunc: (event: FigoChatMessageEvent) => void): Promise<PluginListenerHandle>;
59
+ /** Removes every listener added with `addListener`. */
60
+ removeAllListeners(): Promise<void>;
61
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ import type { FigoChatPlugin } from './definitions';
2
+ /** FigoChat for Capacitor. Runs the native FigoChat SDK on iOS and Android. */
3
+ declare const FigoChat: FigoChatPlugin;
4
+ export * from './definitions';
5
+ export { FigoChat };
@@ -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
+ }
@@ -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,89 @@
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
+ firstCustomerMessage: call.getString("firstCustomerMessage"),
43
+ threadId: call.getString("threadId"),
44
+ maxFiles: call.getInt("maxFiles") ?? 5,
45
+ maxFileSizeMB: call.getInt("maxFileSizeMB") ?? 10,
46
+ autoSendVoice: call.getBool("autoSendVoice") ?? true,
47
+ timeout: (call.getDouble("timeout") ?? 120_000) / 1000
48
+ )
49
+ call.resolve()
50
+ } catch let error as FigoChatError {
51
+ call.reject(error.message, error.code)
52
+ } catch {
53
+ call.reject(error.localizedDescription, "UNKNOWN")
54
+ }
55
+ }
56
+
57
+ @objc func open(_ call: CAPPluginCall) {
58
+ guard FigoChat.isInitialized else {
59
+ call.reject("FigoChat is not initialized. Call FigoChat.initialize(...) first.", "NOT_INITIALIZED")
60
+ return
61
+ }
62
+ Task { @MainActor [weak self] in
63
+ guard let presenter = self?.bridge?.viewController else {
64
+ call.reject("No view controller to present the chat from.", "UNAVAILABLE")
65
+ return
66
+ }
67
+ FigoChat.present(from: presenter)
68
+ call.resolve()
69
+ }
70
+ }
71
+
72
+ @objc func getThreadId(_ call: CAPPluginCall) {
73
+ if let threadId = FigoChat.threadId {
74
+ call.resolve(["threadId": threadId])
75
+ } else {
76
+ call.resolve(["threadId": NSNull()])
77
+ }
78
+ }
79
+
80
+ @objc func resetConversation(_ call: CAPPluginCall) {
81
+ FigoChat.resetConversation()
82
+ call.resolve()
83
+ }
84
+
85
+ @objc func logout(_ call: CAPPluginCall) {
86
+ FigoChat.logout()
87
+ call.resolve()
88
+ }
89
+ }
package/package.json CHANGED
@@ -1,6 +1,40 @@
1
1
  {
2
2
  "name": "@figoailabs/figochat-capacitor",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "2.0.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
+ }