@livechatta/sdk 0.0.0-stage → 1.0.1
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 +228 -0
- package/LICENSE +21 -0
- package/README.md +2558 -2
- package/bin/chatta.mjs +7 -0
- package/bin/lib/cli.d.mts +46 -0
- package/bin/lib/cli.mjs +2088 -0
- package/dist/cjs/livechatta.cjs.js +7259 -0
- package/dist/cjs/livechatta.cjs.js.map +1 -0
- package/dist/cjs/livechatta.cjs.min.js +2 -0
- package/dist/cjs/livechatta.cjs.min.js.map +1 -0
- package/dist/esm/livechatta.esm.js +7078 -0
- package/dist/esm/livechatta.esm.js.map +1 -0
- package/dist/esm/livechatta.esm.min.js +2 -0
- package/dist/esm/livechatta.esm.min.js.map +1 -0
- package/dist/platforms/android/LiveChattaClient.kt +367 -0
- package/dist/platforms/android/LiveChattaHttpAPI.kt +2630 -0
- package/dist/platforms/android/LiveChattaJson.kt +83 -0
- package/dist/platforms/android/LiveChattaModels.kt +22805 -0
- package/dist/platforms/android/LiveChattaSentFrom.kt +30 -0
- package/dist/platforms/android/LiveChattaSocketAPI.kt +2113 -0
- package/dist/platforms/android/LiveChattaTyped.kt +239 -0
- package/dist/platforms/android/LiveChattaWebView.kt +158 -0
- package/dist/platforms/angular/livechatta-bridge.service.d.ts +35 -0
- package/dist/platforms/angular/livechatta-bridge.service.js +1 -0
- package/dist/platforms/angular/livechatta-bridge.service.js.map +1 -0
- package/dist/platforms/angular/livechatta-embed.component.d.ts +46 -0
- package/dist/platforms/angular/livechatta-embed.component.js +1 -0
- package/dist/platforms/angular/livechatta-embed.component.js.map +1 -0
- package/dist/platforms/angular/livechatta.service.d.ts +66 -0
- package/dist/platforms/angular/livechatta.service.js +1 -0
- package/dist/platforms/angular/livechatta.service.js.map +1 -0
- package/dist/platforms/capacitor/CapacitorBridge.d.ts +27 -0
- package/dist/platforms/capacitor/CapacitorBridge.js +1 -0
- package/dist/platforms/capacitor/CapacitorBridge.js.map +1 -0
- package/dist/platforms/capacitor/CapacitorDeepLinks.d.ts +23 -0
- package/dist/platforms/capacitor/CapacitorDeepLinks.js +1 -0
- package/dist/platforms/capacitor/CapacitorDeepLinks.js.map +1 -0
- package/dist/platforms/capacitor/CapacitorPermissions.d.ts +29 -0
- package/dist/platforms/capacitor/CapacitorPermissions.js +1 -0
- package/dist/platforms/capacitor/CapacitorPermissions.js.map +1 -0
- package/dist/platforms/capacitor/CapacitorPush.d.ts +33 -0
- package/dist/platforms/capacitor/CapacitorPush.js +1 -0
- package/dist/platforms/capacitor/CapacitorPush.js.map +1 -0
- package/dist/platforms/capacitor/index.d.ts +24 -0
- package/dist/platforms/capacitor/index.js +1 -0
- package/dist/platforms/capacitor/index.js.map +1 -0
- package/dist/platforms/flutter/livechatta_client.dart +359 -0
- package/dist/platforms/flutter/livechatta_http_api.dart +1942 -0
- package/dist/platforms/flutter/livechatta_json.dart +57 -0
- package/dist/platforms/flutter/livechatta_models.dart +23531 -0
- package/dist/platforms/flutter/livechatta_sent_from.dart +35 -0
- package/dist/platforms/flutter/livechatta_socket_api.dart +1504 -0
- package/dist/platforms/flutter/livechatta_typed.dart +234 -0
- package/dist/platforms/flutter/livechatta_webview.dart +190 -0
- package/dist/platforms/ios/LiveChattaClient.swift +374 -0
- package/dist/platforms/ios/LiveChattaHttpAPI.swift +2431 -0
- package/dist/platforms/ios/LiveChattaJSON.swift +84 -0
- package/dist/platforms/ios/LiveChattaModels.swift +27050 -0
- package/dist/platforms/ios/LiveChattaSentFrom.swift +32 -0
- package/dist/platforms/ios/LiveChattaSocketAPI.swift +1446 -0
- package/dist/platforms/ios/LiveChattaTyped.swift +268 -0
- package/dist/platforms/ios/LiveChattaWebView.swift +191 -0
- package/dist/platforms/nuxt/LiveChattaView.d.ts +1 -0
- package/dist/platforms/nuxt/LiveChattaView.js +1 -0
- package/dist/platforms/nuxt/LiveChattaView.js.map +1 -0
- package/dist/platforms/nuxt/useChattaBridge.d.ts +9 -0
- package/dist/platforms/nuxt/useChattaBridge.js +1 -0
- package/dist/platforms/nuxt/useChattaBridge.js.map +1 -0
- package/dist/platforms/nuxt/useLiveChatta.d.ts +63 -0
- package/dist/platforms/nuxt/useLiveChatta.js +1 -0
- package/dist/platforms/nuxt/useLiveChatta.js.map +1 -0
- package/dist/platforms/react/LiveChattaView.d.ts +58 -0
- package/dist/platforms/react/LiveChattaView.js +1 -0
- package/dist/platforms/react/LiveChattaView.js.map +1 -0
- package/dist/platforms/react/useChattaBridge.d.ts +1 -0
- package/dist/platforms/react/useChattaBridge.js +1 -0
- package/dist/platforms/react/useChattaBridge.js.map +1 -0
- package/dist/platforms/react/useChattaDeepLink.d.ts +2 -0
- package/dist/platforms/react/useChattaDeepLink.js +1 -0
- package/dist/platforms/react/useChattaDeepLink.js.map +1 -0
- package/dist/platforms/react/useChattaPermissions.d.ts +9 -0
- package/dist/platforms/react/useChattaPermissions.js +1 -0
- package/dist/platforms/react/useChattaPermissions.js.map +1 -0
- package/dist/platforms/react/useChattaUnread.d.ts +1 -0
- package/dist/platforms/react/useChattaUnread.js +1 -0
- package/dist/platforms/react/useChattaUnread.js.map +1 -0
- package/dist/platforms/react/useLiveChatta.d.ts +29 -0
- package/dist/platforms/react/useLiveChatta.js +1 -0
- package/dist/platforms/react/useLiveChatta.js.map +1 -0
- package/dist/platforms/react-native/LiveChattaView.d.ts +52 -0
- package/dist/platforms/react-native/LiveChattaView.js +1 -0
- package/dist/platforms/react-native/LiveChattaView.js.map +1 -0
- package/dist/platforms/react-native/useChattaBridge.d.ts +12 -0
- package/dist/platforms/react-native/useChattaBridge.js +1 -0
- package/dist/platforms/react-native/useChattaBridge.js.map +1 -0
- package/dist/platforms/react-native/useLiveChatta.d.ts +29 -0
- package/dist/platforms/react-native/useLiveChatta.js +1 -0
- package/dist/platforms/react-native/useLiveChatta.js.map +1 -0
- package/dist/platforms/svelte/LiveChattaEmbed.d.ts +54 -0
- package/dist/platforms/svelte/LiveChattaEmbed.js +1 -0
- package/dist/platforms/svelte/LiveChattaEmbed.js.map +1 -0
- package/dist/platforms/svelte/chattaBridgeStore.d.ts +19 -0
- package/dist/platforms/svelte/chattaBridgeStore.js +1 -0
- package/dist/platforms/svelte/chattaBridgeStore.js.map +1 -0
- package/dist/platforms/svelte/useLiveChatta.d.ts +61 -0
- package/dist/platforms/svelte/useLiveChatta.js +1 -0
- package/dist/platforms/svelte/useLiveChatta.js.map +1 -0
- package/dist/platforms/tauri/TauriBridge.d.ts +34 -0
- package/dist/platforms/tauri/TauriBridge.js +1 -0
- package/dist/platforms/tauri/TauriBridge.js.map +1 -0
- package/dist/platforms/tauri/TauriDeepLinks.d.ts +29 -0
- package/dist/platforms/tauri/TauriDeepLinks.js +1 -0
- package/dist/platforms/tauri/TauriDeepLinks.js.map +1 -0
- package/dist/platforms/tauri/TauriPermissions.d.ts +21 -0
- package/dist/platforms/tauri/TauriPermissions.js +1 -0
- package/dist/platforms/tauri/TauriPermissions.js.map +1 -0
- package/dist/platforms/tauri/TauriUpdater.d.ts +31 -0
- package/dist/platforms/tauri/TauriUpdater.js +1 -0
- package/dist/platforms/tauri/TauriUpdater.js.map +1 -0
- package/dist/platforms/tauri/index.d.ts +22 -0
- package/dist/platforms/tauri/index.js +1 -0
- package/dist/platforms/tauri/index.js.map +1 -0
- package/dist/platforms/vue/LiveChattaView.d.ts +1 -0
- package/dist/platforms/vue/LiveChattaView.js +1 -0
- package/dist/platforms/vue/LiveChattaView.js.map +1 -0
- package/dist/platforms/vue/useChattaBridge.d.ts +11 -0
- package/dist/platforms/vue/useChattaBridge.js +1 -0
- package/dist/platforms/vue/useChattaBridge.js.map +1 -0
- package/dist/platforms/vue/useChattaDeepLink.d.ts +2 -0
- package/dist/platforms/vue/useChattaDeepLink.js +1 -0
- package/dist/platforms/vue/useChattaDeepLink.js.map +1 -0
- package/dist/platforms/vue/useChattaPermissions.d.ts +9 -0
- package/dist/platforms/vue/useChattaPermissions.js +1 -0
- package/dist/platforms/vue/useChattaPermissions.js.map +1 -0
- package/dist/platforms/vue/useChattaUnread.d.ts +8 -0
- package/dist/platforms/vue/useChattaUnread.js +1 -0
- package/dist/platforms/vue/useChattaUnread.js.map +1 -0
- package/dist/platforms/vue/useLiveChatta.d.ts +58 -0
- package/dist/platforms/vue/useLiveChatta.js +1 -0
- package/dist/platforms/vue/useLiveChatta.js.map +1 -0
- package/dist/platforms/web/LiveChattaEmbed.d.ts +94 -0
- package/dist/platforms/web/LiveChattaEmbed.js +1 -0
- package/dist/platforms/web/LiveChattaEmbed.js.map +1 -0
- package/dist/platforms/web/bridge.d.ts +8 -0
- package/dist/platforms/web/bridge.js +1 -0
- package/dist/platforms/web/bridge.js.map +1 -0
- package/dist/platforms/web/permissions.d.ts +8 -0
- package/dist/platforms/web/permissions.js +1 -0
- package/dist/platforms/web/permissions.js.map +1 -0
- package/dist/types/billing.d.ts +355 -0
- package/dist/types/billing.js +53 -0
- package/dist/types/billing.js.map +1 -0
- package/dist/types/calendar.d.ts +132 -0
- package/dist/types/calendar.js +15 -0
- package/dist/types/calendar.js.map +1 -0
- package/dist/types/chat-core.d.ts +901 -0
- package/dist/types/chat-core.js +98 -0
- package/dist/types/chat-core.js.map +1 -0
- package/dist/types/chat-features.d.ts +775 -0
- package/dist/types/chat-features.js +50 -0
- package/dist/types/chat-features.js.map +1 -0
- package/dist/types/content.d.ts +138 -0
- package/dist/types/content.js +2 -0
- package/dist/types/content.js.map +1 -0
- package/dist/types/core/AutoRefresh.d.ts +68 -0
- package/dist/types/core/Bridge.d.ts +124 -0
- package/dist/types/core/Config.d.ts +26 -0
- package/dist/types/core/DeepLinks.d.ts +38 -0
- package/dist/types/core/EventBus.d.ts +15 -0
- package/dist/types/core/GrantStore.d.ts +29 -0
- package/dist/types/core/LiveChatta.d.ts +128 -0
- package/dist/types/core/Permissions.d.ts +34 -0
- package/dist/types/core/TokenManager.d.ts +25 -0
- package/dist/types/core/events.d.ts +140 -0
- package/dist/types/csat.d.ts +110 -0
- package/dist/types/csat.js +12 -0
- package/dist/types/csat.js.map +1 -0
- package/dist/types/events.d.ts +242 -0
- package/dist/types/events.js +275 -0
- package/dist/types/events.js.map +1 -0
- package/dist/types/extras.d.ts +353 -0
- package/dist/types/extras.js +31 -0
- package/dist/types/extras.js.map +1 -0
- package/dist/types/http/HttpAPI.d.ts +944 -0
- package/dist/types/http/HttpTransport.d.ts +66 -0
- package/dist/types/http/incomingWebhook.d.ts +17 -0
- package/dist/types/incoming-webhooks.d.ts +78 -0
- package/dist/types/incoming-webhooks.js +16 -0
- package/dist/types/incoming-webhooks.js.map +1 -0
- package/dist/types/index.d.ts +15 -0
- package/dist/types/index.js +16 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/liveflex.d.ts +578 -0
- package/dist/types/liveflex.js +7 -0
- package/dist/types/liveflex.js.map +1 -0
- package/dist/types/models.d.ts +1753 -0
- package/dist/types/models.js +148 -0
- package/dist/types/models.js.map +1 -0
- package/dist/types/options.d.ts +190 -0
- package/dist/types/options.js +43 -0
- package/dist/types/options.js.map +1 -0
- package/dist/types/shared-channels.d.ts +236 -0
- package/dist/types/shared-channels.js +50 -0
- package/dist/types/shared-channels.js.map +1 -0
- package/dist/types/socket/SocketAPI.d.ts +1026 -0
- package/dist/types/socket/SocketTransport.d.ts +44 -0
- package/dist/types/types/billing.d.ts +355 -0
- package/dist/types/types/calendar.d.ts +132 -0
- package/dist/types/types/chat-core.d.ts +901 -0
- package/dist/types/types/chat-features.d.ts +775 -0
- package/dist/types/types/content.d.ts +138 -0
- package/dist/types/types/csat.d.ts +110 -0
- package/dist/types/types/events.d.ts +242 -0
- package/dist/types/types/extras.d.ts +353 -0
- package/dist/types/types/incoming-webhooks.d.ts +78 -0
- package/dist/types/types/index.d.ts +15 -0
- package/dist/types/types/liveflex.d.ts +578 -0
- package/dist/types/types/models.d.ts +1753 -0
- package/dist/types/types/options.d.ts +190 -0
- package/dist/types/types/shared-channels.d.ts +236 -0
- package/dist/types/types/workspace-gifs.d.ts +95 -0
- package/dist/types/types/workspace.d.ts +390 -0
- package/dist/types/ui/EmbedConfig.d.ts +38 -0
- package/dist/types/ui/EmbedUI.d.ts +44 -0
- package/dist/types/ui/Launcher.d.ts +122 -0
- package/dist/types/ui/brand.d.ts +27 -0
- package/dist/types/ui/embedMessages.d.ts +23 -0
- package/dist/types/ui/hours.d.ts +35 -0
- package/dist/types/ui/prechat.d.ts +35 -0
- package/dist/types/ui/widgetConfig.d.ts +4 -0
- package/dist/types/utils/crypto.d.ts +6 -0
- package/dist/types/utils/hmac.d.ts +40 -0
- package/dist/types/utils/permissions.d.ts +5 -0
- package/dist/types/utils/platform.d.ts +18 -0
- package/dist/types/utils/visitor.d.ts +2 -0
- package/dist/types/workspace-gifs.d.ts +95 -0
- package/dist/types/workspace-gifs.js +3 -0
- package/dist/types/workspace-gifs.js.map +1 -0
- package/dist/types/workspace.d.ts +390 -0
- package/dist/types/workspace.js +13 -0
- package/dist/types/workspace.js.map +1 -0
- package/dist/umd/livechatta.umd.js +7263 -0
- package/dist/umd/livechatta.umd.js.map +1 -0
- package/dist/umd/livechatta.umd.min.js +2 -0
- package/dist/umd/livechatta.umd.min.js.map +1 -0
- package/package.json +274 -4
|
@@ -0,0 +1,2630 @@
|
|
|
1
|
+
package com.livechatta.sdk
|
|
2
|
+
|
|
3
|
+
import android.os.Handler
|
|
4
|
+
import android.os.Looper
|
|
5
|
+
import android.util.Log
|
|
6
|
+
import org.json.JSONArray
|
|
7
|
+
import org.json.JSONObject
|
|
8
|
+
import java.io.BufferedReader
|
|
9
|
+
import java.io.InputStreamReader
|
|
10
|
+
import java.io.OutputStreamWriter
|
|
11
|
+
import java.net.HttpURLConnection
|
|
12
|
+
import java.net.URL
|
|
13
|
+
import java.net.URLEncoder
|
|
14
|
+
import java.util.concurrent.Executors
|
|
15
|
+
|
|
16
|
+
/** A <500 HTTP error; [code] is the server's UPPER_SNAKE code when it sent one (e.g. LINK_MEMBER_BLOCKED). */
|
|
17
|
+
data class LiveChattaApiError(
|
|
18
|
+
val message: String,
|
|
19
|
+
val statusCode: Int,
|
|
20
|
+
val code: String? = null,
|
|
21
|
+
val path: String? = null,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
/** Machine-readable server error codes. */
|
|
25
|
+
object LiveChattaErrorCode {
|
|
26
|
+
/** 403 from POST /in/:code/join-exist: the member is blocked from the link and gets no token. */
|
|
27
|
+
const val LINK_MEMBER_BLOCKED = "LINK_MEMBER_BLOCKED"
|
|
28
|
+
|
|
29
|
+
/** 400 from join / join-exist: the link reached its member cap; show the "This space is full" state. */
|
|
30
|
+
const val LINK_FULL = "LINK_FULL"
|
|
31
|
+
|
|
32
|
+
/** 400 from join-new / join-guest: that email already has an account; sign in with join-exist instead. */
|
|
33
|
+
const val ACCOUNT_EXISTS = "ACCOUNT_EXISTS"
|
|
34
|
+
|
|
35
|
+
/** 400 from join-guest: this link's mode needs a real email. */
|
|
36
|
+
const val EMAIL_REQUIRED = "EMAIL_REQUIRED"
|
|
37
|
+
|
|
38
|
+
/** 403 from join-guest / join-new / join-exist / sign-in: invite only (not on the list), or guests not allowed. */
|
|
39
|
+
const val INVITE_ONLY = "INVITE_ONLY"
|
|
40
|
+
|
|
41
|
+
/** 403 from join-guest: guests are off but members may sign in or join as new (e.g. school links). */
|
|
42
|
+
const val SIGN_IN_REQUIRED = "SIGN_IN_REQUIRED"
|
|
43
|
+
|
|
44
|
+
/** 403 from requestToJoinLink: the link doesn't take requests to join. */
|
|
45
|
+
const val APPROVAL_OFF = "APPROVAL_OFF"
|
|
46
|
+
|
|
47
|
+
/** 400 from join-new: that @handle is already used in this workspace. */
|
|
48
|
+
const val HANDLE_TAKEN = "HANDLE_TAKEN"
|
|
49
|
+
|
|
50
|
+
/** 403 on an /admin/… console page the admin role can't open. */
|
|
51
|
+
const val ADMIN_NO_ACCESS = "ADMIN_NO_ACCESS"
|
|
52
|
+
|
|
53
|
+
/** Socket ack error on hop reaction / vote / raise-hand / poll-vote over the cap (10 s window). */
|
|
54
|
+
const val HOP_RATE_LIMITED = "RATE_LIMITED"
|
|
55
|
+
|
|
56
|
+
/** 429 chat-error when messages are sent too fast; keep the message as not sent and offer Retry. */
|
|
57
|
+
const val RATE_LIMITED = "RATE_LIMITED"
|
|
58
|
+
|
|
59
|
+
/** 403 from getRecordingDownloadLink (and the download) while the link's "Download call recordings" is off. */
|
|
60
|
+
const val RECORDING_DOWNLOAD_OFF = "RECORDING_DOWNLOAD_OFF"
|
|
61
|
+
|
|
62
|
+
/** 403 when a recording download link has expired; ask for a new one. */
|
|
63
|
+
const val RECORDING_DOWNLOAD_EXPIRED = "RECORDING_DOWNLOAD_EXPIRED"
|
|
64
|
+
|
|
65
|
+
/** Plan refusal codes (chatta #396): PLAN_NOT_FOUND is 404, the other two 400. */
|
|
66
|
+
const val PLAN_NOT_FOUND = "PLAN_NOT_FOUND"
|
|
67
|
+
const val PLAN_NOT_AVAILABLE = "PLAN_NOT_AVAILABLE"
|
|
68
|
+
const val PLAN_TEAM_ACTIVATED = "PLAN_TEAM_ACTIVATED"
|
|
69
|
+
|
|
70
|
+
/** 400 on an upload past the month's storage allowance (body adds resetsAt; chatta #420). */
|
|
71
|
+
const val STORAGE_LIMIT = "STORAGE_LIMIT"
|
|
72
|
+
|
|
73
|
+
/** 400 on `editMessage` after the edit window (24 h from sending); the socket ack's body carries this code. */
|
|
74
|
+
const val EDIT_WINDOW_CLOSED = "EDIT_WINDOW_CLOSED"
|
|
75
|
+
|
|
76
|
+
/** 400 from calendar native complete: the sign-in was started by a different member or workspace. */
|
|
77
|
+
const val CALENDAR_ACCOUNT_MISMATCH = "CALENDAR_ACCOUNT_MISMATCH"
|
|
78
|
+
|
|
79
|
+
/** 400 from calendar native complete: the one-time code expired or was already used; connect again. */
|
|
80
|
+
const val CALENDAR_SIGNIN_EXPIRED = "CALENDAR_SIGNIN_EXPIRED"
|
|
81
|
+
|
|
82
|
+
/** Meeting-guest email codes (verify): expired or used, wrong (400); locked, cooling down, hourly cap (429). */
|
|
83
|
+
const val GUEST_CODE_EXPIRED = "GUEST_CODE_EXPIRED"
|
|
84
|
+
const val GUEST_CODE_INVALID = "GUEST_CODE_INVALID"
|
|
85
|
+
const val GUEST_CODE_LOCKED = "GUEST_CODE_LOCKED"
|
|
86
|
+
const val GUEST_CODE_COOLDOWN = "GUEST_CODE_COOLDOWN"
|
|
87
|
+
const val GUEST_CODE_RATE_LIMITED = "GUEST_CODE_RATE_LIMITED"
|
|
88
|
+
|
|
89
|
+
/** 400 from link create with a custom `code` the server refuses (chatta #489); the message says what to change. */
|
|
90
|
+
const val LINK_CODE_TOO_SHORT = "LINK_CODE_TOO_SHORT"
|
|
91
|
+
const val LINK_CODE_TOO_LONG = "LINK_CODE_TOO_LONG"
|
|
92
|
+
const val LINK_CODE_INVALID = "LINK_CODE_INVALID"
|
|
93
|
+
const val LINK_CODE_RESERVED = "LINK_CODE_RESERVED"
|
|
94
|
+
const val LINK_CODE_TAKEN = "LINK_CODE_TAKEN"
|
|
95
|
+
val LINK_CODE_ERRORS = listOf(LINK_CODE_TOO_SHORT, LINK_CODE_TOO_LONG, LINK_CODE_INVALID, LINK_CODE_RESERVED, LINK_CODE_TAKEN)
|
|
96
|
+
const val LINK_CODE_MIN = 3
|
|
97
|
+
const val LINK_CODE_MAX = 40
|
|
98
|
+
|
|
99
|
+
/** Part of the message when an API key with allowed origins is used from another site (HTTP 403, socket connect_error). */
|
|
100
|
+
const val API_KEY_ORIGIN_ERROR_MARKER = "isn't allowed from"
|
|
101
|
+
|
|
102
|
+
/** Most origins one API key can list. */
|
|
103
|
+
const val API_KEY_MAX_ORIGINS = 20
|
|
104
|
+
|
|
105
|
+
/** True for a refused custom link address code. */
|
|
106
|
+
fun isLinkCodeError(code: String?): Boolean = code != null && code in LINK_CODE_ERRORS
|
|
107
|
+
|
|
108
|
+
/** True for the error raised when an API key is used from a site that is not on its allowed origins. */
|
|
109
|
+
fun isApiKeyOriginError(message: String?): Boolean = message?.contains(API_KEY_ORIGIN_ERROR_MARKER) == true
|
|
110
|
+
|
|
111
|
+
/** The same refusals' messages, for servers older than chatta #396 that send no code. */
|
|
112
|
+
const val PLAN_NOT_FOUND_MESSAGE = "Plan not found."
|
|
113
|
+
const val PLAN_NOT_AVAILABLE_MESSAGE = "This plan is not available."
|
|
114
|
+
const val PLAN_TEAM_ACTIVATED_MESSAGE = "This plan is activated by the LiveChatta team. Contact support to switch to it."
|
|
115
|
+
|
|
116
|
+
private val SERVER_CODE = Regex("^[A-Z][A-Z0-9_]{2,47}$")
|
|
117
|
+
|
|
118
|
+
/** The `code` of an error body, only when it is UPPER_SNAKE (same rule as the backend). */
|
|
119
|
+
fun fromBody(body: JSONObject?): String? = (body?.opt("code") as? String)?.takeIf { SERVER_CODE.matches(it) }
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** Result callback — receives (response, errorMessage); top level because Kotlin has no nested typealiases. */
|
|
123
|
+
typealias ApiCallback = (JSONObject?, String?) -> Unit
|
|
124
|
+
|
|
125
|
+
// Android REST client mirroring the TypeScript HttpAPI (java.net.HttpURLConnection, no deps).
|
|
126
|
+
// API-key calls hit /api/v1/external; owner-console calls need ownerToken; see README "Android".
|
|
127
|
+
class LiveChattaHttpAPI internal constructor(
|
|
128
|
+
private val baseUrl: String,
|
|
129
|
+
private val apiKey: String,
|
|
130
|
+
private val debug: Boolean = false,
|
|
131
|
+
) {
|
|
132
|
+
private val executor = Executors.newCachedThreadPool()
|
|
133
|
+
private val mainHandler = Handler(Looper.getMainLooper())
|
|
134
|
+
private val maxRetries = 2
|
|
135
|
+
private val timeout = 30000
|
|
136
|
+
|
|
137
|
+
/** Owner account token (JWT) for owner-console methods; keep it server-side or in secure storage. */
|
|
138
|
+
@Volatile var ownerToken: String? = null
|
|
139
|
+
|
|
140
|
+
/** Chat-member token (JWT, e.g. from the embed's onLoginSuccess) for member routes. */
|
|
141
|
+
@Volatile var memberToken: String? = null
|
|
142
|
+
|
|
143
|
+
/** Called on the main thread with every 4xx (status, server code, path) just before that call's callback. */
|
|
144
|
+
@Volatile var onApiError: ((LiveChattaApiError) -> Unit)? = null
|
|
145
|
+
|
|
146
|
+
/** Server root and /api/v1, derived from the external base URL. */
|
|
147
|
+
private val rootUrl = baseUrl.removeSuffix("/api/v1/external")
|
|
148
|
+
private val apiUrl = "$rootUrl/api/v1"
|
|
149
|
+
|
|
150
|
+
/** URL root and credential for a request. */
|
|
151
|
+
enum class Base { EXTERNAL, API, ROOT }
|
|
152
|
+
|
|
153
|
+
enum class Auth { API_KEY, OWNER, MEMBER, NONE }
|
|
154
|
+
|
|
155
|
+
// ===================
|
|
156
|
+
// MEMBERS
|
|
157
|
+
// ===================
|
|
158
|
+
|
|
159
|
+
/** Register multiple members at once (up to 100). A taken `handle` gets the next free `-N`; the response shows the final one. */
|
|
160
|
+
fun registerMembers(
|
|
161
|
+
payload: JSONObject,
|
|
162
|
+
callback: ApiCallback? = null,
|
|
163
|
+
) {
|
|
164
|
+
post("/members", payload, callback)
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** Register a single member. A taken `handle` gets the next free `-N`; the response shows the final one. */
|
|
168
|
+
fun registerMember(
|
|
169
|
+
payload: JSONObject,
|
|
170
|
+
callback: ApiCallback? = null,
|
|
171
|
+
) {
|
|
172
|
+
post("/members/single", payload, callback)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** List members with optional filters */
|
|
176
|
+
fun listMembers(
|
|
177
|
+
query: Map<String, String>? = null,
|
|
178
|
+
callback: ApiCallback? = null,
|
|
179
|
+
) {
|
|
180
|
+
get("/members", query, callback)
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** Get a member by ID or username */
|
|
184
|
+
fun getMember(
|
|
185
|
+
memberIdOrUsername: String,
|
|
186
|
+
callback: ApiCallback? = null,
|
|
187
|
+
) {
|
|
188
|
+
get("/members/$memberIdOrUsername", callback = callback)
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// ===================
|
|
192
|
+
// CHAT LINKS
|
|
193
|
+
// ===================
|
|
194
|
+
|
|
195
|
+
/** Create a new chat link; mode? (standard|support|creator|school|community|tech|public|private|webinar). Then setLinkMode applies the full preset */
|
|
196
|
+
fun createChatLink(
|
|
197
|
+
payload: JSONObject,
|
|
198
|
+
callback: ApiCallback? = null,
|
|
199
|
+
) {
|
|
200
|
+
post("/chat-links", payload, callback)
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** List chat links with optional filters */
|
|
204
|
+
fun listChatLinks(
|
|
205
|
+
query: Map<String, String>? = null,
|
|
206
|
+
callback: ApiCallback? = null,
|
|
207
|
+
) {
|
|
208
|
+
get("/chat-links", query, callback)
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/** Get a chat link by ID */
|
|
212
|
+
fun getChatLink(
|
|
213
|
+
linkId: String,
|
|
214
|
+
callback: ApiCallback? = null,
|
|
215
|
+
) {
|
|
216
|
+
get("/chat-links/$linkId", callback = callback)
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/** Update a chat link; `settings` merges key by key (maxMembers, allow*, welcomeMessage, defaultLayout, hideRunsOn), other keys are dropped */
|
|
220
|
+
fun updateChatLink(
|
|
221
|
+
linkId: String,
|
|
222
|
+
payload: JSONObject,
|
|
223
|
+
callback: ApiCallback? = null,
|
|
224
|
+
) {
|
|
225
|
+
request("PATCH", "/chat-links/$linkId", payload, null, callback)
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// ===================
|
|
229
|
+
// CONVERSATIONS
|
|
230
|
+
// ===================
|
|
231
|
+
|
|
232
|
+
/** Create a conversation within a chat link */
|
|
233
|
+
fun createConversation(
|
|
234
|
+
linkId: String,
|
|
235
|
+
payload: JSONObject,
|
|
236
|
+
callback: ApiCallback? = null,
|
|
237
|
+
) {
|
|
238
|
+
post("/chat-links/$linkId/conversations", payload, callback)
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/** Get a member's conversations */
|
|
242
|
+
fun getMemberConversations(
|
|
243
|
+
memberId: String,
|
|
244
|
+
query: Map<String, String>? = null,
|
|
245
|
+
callback: ApiCallback? = null,
|
|
246
|
+
) {
|
|
247
|
+
get("/members/$memberId/conversations", query, callback)
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/** Get users in a conversation */
|
|
251
|
+
fun getConversationUsers(
|
|
252
|
+
conversationId: String,
|
|
253
|
+
query: Map<String, String>? = null,
|
|
254
|
+
callback: ApiCallback? = null,
|
|
255
|
+
) {
|
|
256
|
+
get("/conversations/$conversationId/users", query, callback)
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/** Public channels and groups only (no DMs, private groups, support groups or meetings); 400 for an expired or off link. */
|
|
260
|
+
fun listPublicConversations(
|
|
261
|
+
linkCode: String,
|
|
262
|
+
query: Map<String, String>? = null,
|
|
263
|
+
callback: ApiCallback? = null,
|
|
264
|
+
) {
|
|
265
|
+
get("/public/$linkCode/conversations", query, callback)
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// ===================
|
|
269
|
+
// MESSAGES
|
|
270
|
+
// ===================
|
|
271
|
+
|
|
272
|
+
/** Get messages in a conversation */
|
|
273
|
+
fun getMessages(
|
|
274
|
+
memberId: String,
|
|
275
|
+
conversationId: String,
|
|
276
|
+
query: Map<String, String>? = null,
|
|
277
|
+
callback: ApiCallback? = null,
|
|
278
|
+
) {
|
|
279
|
+
get("/members/$memberId/conversations/$conversationId/messages", query, callback)
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/** Send a message via HTTP. Prefer [sendMessageTyped] (LiveChattaTyped.kt). */
|
|
283
|
+
@Deprecated("Use sendMessageTyped(LiveChattaSendMessagePayload) for a typed request and result.", ReplaceWith("sendMessageTyped"))
|
|
284
|
+
fun sendMessage(
|
|
285
|
+
payload: JSONObject,
|
|
286
|
+
callback: ApiCallback? = null,
|
|
287
|
+
) {
|
|
288
|
+
post("/chats/messages/send", payload, callback)
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/** Messages sent by the key owner, newest first, excluding scheduled and thread children. Prefer [listSentMessagesTyped]. */
|
|
292
|
+
@Deprecated("Use listSentMessagesTyped for typed messages.", ReplaceWith("listSentMessagesTyped"))
|
|
293
|
+
fun listSentMessages(
|
|
294
|
+
query: Map<String, String>? = null,
|
|
295
|
+
callback: ApiCallback? = null,
|
|
296
|
+
) {
|
|
297
|
+
get("/chats/messages", query, callback)
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/** Cancel (soft-delete) a scheduled message; body must carry conversationId. */
|
|
301
|
+
fun cancelScheduledMessage(
|
|
302
|
+
messageId: String,
|
|
303
|
+
conversationId: String,
|
|
304
|
+
callback: ApiCallback? = null,
|
|
305
|
+
) {
|
|
306
|
+
request("DELETE", "/chats/messages/$messageId", JSONObject().put("conversationId", conversationId), null, callback)
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/** Reschedule a scheduled message; body needs a future scheduledAt and conversationId. */
|
|
310
|
+
fun rescheduleMessage(
|
|
311
|
+
messageId: String,
|
|
312
|
+
conversationId: String,
|
|
313
|
+
scheduledAt: String,
|
|
314
|
+
callback: ApiCallback? = null,
|
|
315
|
+
) {
|
|
316
|
+
val body = JSONObject().put("scheduledAt", scheduledAt).put("conversationId", conversationId)
|
|
317
|
+
request("PATCH", "/chats/messages/$messageId", body, null, callback)
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// ===================
|
|
321
|
+
// PUSH NOTIFICATIONS
|
|
322
|
+
// ===================
|
|
323
|
+
|
|
324
|
+
/** Send a push notification */
|
|
325
|
+
fun sendPushNotification(
|
|
326
|
+
payload: JSONObject,
|
|
327
|
+
callback: ApiCallback? = null,
|
|
328
|
+
) {
|
|
329
|
+
post("/chats/push-notification", payload, callback)
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// ===================
|
|
333
|
+
// EXPORTS
|
|
334
|
+
// ===================
|
|
335
|
+
|
|
336
|
+
/** Export chat data */
|
|
337
|
+
fun exportChat(
|
|
338
|
+
payload: JSONObject,
|
|
339
|
+
callback: ApiCallback? = null,
|
|
340
|
+
) {
|
|
341
|
+
post("/chats/exports", payload, callback)
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/** Get exports list */
|
|
345
|
+
fun getExports(
|
|
346
|
+
query: Map<String, String>? = null,
|
|
347
|
+
callback: ApiCallback? = null,
|
|
348
|
+
) {
|
|
349
|
+
get("/chats/exports", query, callback)
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
// ===================
|
|
353
|
+
// CANNED RESPONSES
|
|
354
|
+
// ===================
|
|
355
|
+
|
|
356
|
+
fun getCannedResponses(callback: ApiCallback? = null) = get("/chats/canned-responses", null, callback)
|
|
357
|
+
|
|
358
|
+
fun createCannedResponse(payload: JSONObject, callback: ApiCallback? = null) =
|
|
359
|
+
post("/chats/canned-responses", payload, callback)
|
|
360
|
+
|
|
361
|
+
fun updateCannedResponse(id: String, payload: JSONObject, callback: ApiCallback? = null) =
|
|
362
|
+
request("PATCH", "/chats/canned-responses/$id", payload, null, callback)
|
|
363
|
+
|
|
364
|
+
/** Backend returns { success: true }, not a { status } envelope. */
|
|
365
|
+
fun deleteCannedResponse(id: String, callback: ApiCallback? = null) =
|
|
366
|
+
request("DELETE", "/chats/canned-responses/$id", null, null, callback)
|
|
367
|
+
|
|
368
|
+
/** Count one use when a composer inserts the reply (feeds the dashboard "Used" column). */
|
|
369
|
+
fun markCannedResponseUsed(id: String, callback: ApiCallback? = null) =
|
|
370
|
+
post("/chats/canned-responses/${enc(id)}/used", JSONObject(), callback)
|
|
371
|
+
|
|
372
|
+
// ===================
|
|
373
|
+
// WEBHOOKS
|
|
374
|
+
// ===================
|
|
375
|
+
|
|
376
|
+
fun getWebhooks(query: Map<String, String>? = null, callback: ApiCallback? = null) =
|
|
377
|
+
get("/chats/webhooks", query, callback)
|
|
378
|
+
|
|
379
|
+
fun getWebhook(webhookId: String, callback: ApiCallback? = null) =
|
|
380
|
+
get("/chats/webhooks/$webhookId", null, callback)
|
|
381
|
+
|
|
382
|
+
fun createWebhook(payload: JSONObject, callback: ApiCallback? = null) =
|
|
383
|
+
post("/chats/webhooks", payload, callback)
|
|
384
|
+
|
|
385
|
+
fun updateWebhook(webhookId: String, payload: JSONObject, callback: ApiCallback? = null) =
|
|
386
|
+
request("PATCH", "/chats/webhooks/$webhookId", payload, null, callback)
|
|
387
|
+
|
|
388
|
+
/** Backend returns { success: true }, not a { status } envelope. */
|
|
389
|
+
fun deleteWebhook(webhookId: String, callback: ApiCallback? = null) =
|
|
390
|
+
request("DELETE", "/chats/webhooks/$webhookId", null, null, callback)
|
|
391
|
+
|
|
392
|
+
// ===================
|
|
393
|
+
// INCOMING WEBHOOKS
|
|
394
|
+
// ===================
|
|
395
|
+
|
|
396
|
+
/** API key; a group or channel's incoming webhooks, status active (default) | revoked | all: { results: [{ id, name, status, tokenHint, lastUsedAt, messageCount, ... }], nextCursor, hasMore } (the secret url is never in it) */
|
|
397
|
+
fun listIncomingWebhooks(
|
|
398
|
+
conversationId: String,
|
|
399
|
+
status: String? = null,
|
|
400
|
+
limit: Int? = null,
|
|
401
|
+
nextCursor: String? = null,
|
|
402
|
+
callback: ApiCallback? = null,
|
|
403
|
+
) = request("GET", "/chats/conversations/${enc(conversationId)}/incoming-webhooks", null, incomingHookQuery(status, limit, nextCursor), callback)
|
|
404
|
+
|
|
405
|
+
/** API key; make a hook from { name, botName?, botAvatar? }: the result carries the one-time url, store it now (never retried) */
|
|
406
|
+
fun createIncomingWebhook(conversationId: String, payload: JSONObject, callback: ApiCallback? = null) =
|
|
407
|
+
request("POST", "/chats/conversations/${enc(conversationId)}/incoming-webhooks", payload, null, callback, retry = false)
|
|
408
|
+
|
|
409
|
+
/** API key; rename a hook or change the name and picture of its posts; the url does not change */
|
|
410
|
+
fun updateIncomingWebhook(conversationId: String, hookId: String, payload: JSONObject, callback: ApiCallback? = null) =
|
|
411
|
+
request("PATCH", "/chats/conversations/${enc(conversationId)}/incoming-webhooks/${enc(hookId)}", payload, null, callback, retry = false)
|
|
412
|
+
|
|
413
|
+
/** API key; swap the secret: the old url answers 404 at once and the result carries the new one-time url */
|
|
414
|
+
fun regenerateIncomingWebhook(conversationId: String, hookId: String, callback: ApiCallback? = null) =
|
|
415
|
+
request("POST", "/chats/conversations/${enc(conversationId)}/incoming-webhooks/${enc(hookId)}/regenerate", JSONObject(), null, callback, retry = false)
|
|
416
|
+
|
|
417
|
+
/** API key; stop a hook for good (its url answers 404); messages it posted stay */
|
|
418
|
+
fun revokeIncomingWebhook(conversationId: String, hookId: String, callback: ApiCallback? = null) =
|
|
419
|
+
request("DELETE", "/chats/conversations/${enc(conversationId)}/incoming-webhooks/${enc(hookId)}", null, null, callback, retry = false)
|
|
420
|
+
|
|
421
|
+
private fun incomingHookQuery(status: String?, limit: Int?, nextCursor: String?): Map<String, String>? =
|
|
422
|
+
listOfNotNull(status?.let { "status" to it }, nextCursor?.let { "nextCursor" to it }, limit?.let { "limit" to it.toString() }).toMap().ifEmpty { null }
|
|
423
|
+
|
|
424
|
+
// ===================
|
|
425
|
+
// TRANSLATION
|
|
426
|
+
// ===================
|
|
427
|
+
|
|
428
|
+
fun translateMessage(messageId: String, targetLanguage: String, callback: ApiCallback? = null) =
|
|
429
|
+
post(
|
|
430
|
+
"/chats/translate",
|
|
431
|
+
JSONObject().put("messageId", messageId).put("targetLanguage", targetLanguage),
|
|
432
|
+
callback,
|
|
433
|
+
)
|
|
434
|
+
|
|
435
|
+
// ===================
|
|
436
|
+
// CHAT USER PROFILE
|
|
437
|
+
// ===================
|
|
438
|
+
|
|
439
|
+
/** The signed-in chat user, incl. hasBusinessAccount. */
|
|
440
|
+
fun getChatUserProfile(callback: ApiCallback? = null) = get("/chat-users/me", null, callback)
|
|
441
|
+
|
|
442
|
+
fun updateChatUserProfile(payload: JSONObject, callback: ApiCallback? = null) =
|
|
443
|
+
request("PATCH", "/chat-users/me", payload, null, callback)
|
|
444
|
+
|
|
445
|
+
fun getHandleEditInfo(callback: ApiCallback? = null) = get("/chat-users/me/handle-edits", null, callback)
|
|
446
|
+
|
|
447
|
+
// ===================
|
|
448
|
+
// ADMIN REPLY
|
|
449
|
+
// ===================
|
|
450
|
+
|
|
451
|
+
fun sendAdminReply(payload: JSONObject, callback: ApiCallback? = null) =
|
|
452
|
+
post("/chats/messages/admin-reply", payload, callback)
|
|
453
|
+
|
|
454
|
+
// ===================
|
|
455
|
+
// SUGGESTED CANNED RESPONSES
|
|
456
|
+
// ===================
|
|
457
|
+
|
|
458
|
+
fun getCannedResponseSuggested(category: String? = null, callback: ApiCallback? = null) =
|
|
459
|
+
get("/chats/canned-responses/suggested", category?.let { mapOf("category" to it) }, callback)
|
|
460
|
+
|
|
461
|
+
/** Clones the suggestion into a real canned response and returns the created CannedResponse. */
|
|
462
|
+
fun useSuggestedCannedResponse(suggestedId: String, callback: ApiCallback? = null) =
|
|
463
|
+
post("/chats/canned-responses/use-suggested", JSONObject().put("suggestedId", suggestedId), callback)
|
|
464
|
+
|
|
465
|
+
// ===================
|
|
466
|
+
// GLOBAL SEARCH
|
|
467
|
+
// ===================
|
|
468
|
+
|
|
469
|
+
fun globalSearch(q: String, callback: ApiCallback? = null) = get("/chats/global-search", mapOf("q" to q), callback)
|
|
470
|
+
|
|
471
|
+
// ===================
|
|
472
|
+
// BULK EXPORT
|
|
473
|
+
// ===================
|
|
474
|
+
|
|
475
|
+
fun bulkExportChat(payload: JSONObject, callback: ApiCallback? = null) =
|
|
476
|
+
post("/chats/conversations/bulk-export", payload, callback)
|
|
477
|
+
|
|
478
|
+
// ===================
|
|
479
|
+
// EXTERNAL WORKSPACE INFO (no auth required)
|
|
480
|
+
// ===================
|
|
481
|
+
|
|
482
|
+
fun getLinkWorkspaceInfo(code: String, callback: ApiCallback? = null) = get("/chat-links/$code/info", null, callback)
|
|
483
|
+
|
|
484
|
+
// ===================
|
|
485
|
+
// APP VERSION (no auth required)
|
|
486
|
+
// ===================
|
|
487
|
+
|
|
488
|
+
/** transport base is already .../api/v1/external; the version controller lives at .../external/version. */
|
|
489
|
+
fun getAppVersion(callback: ApiCallback? = null) = get("/version", null, callback)
|
|
490
|
+
|
|
491
|
+
// ===================
|
|
492
|
+
// CUSTOM EMOJI & STICKERS (owner console — needs ownerToken)
|
|
493
|
+
// ===================
|
|
494
|
+
|
|
495
|
+
/** payload: { kind: "emoji"|"sticker", shortcode, image: "data:image/png;base64,…" } */
|
|
496
|
+
fun createLinkEmoji(
|
|
497
|
+
linkId: String,
|
|
498
|
+
payload: JSONObject,
|
|
499
|
+
callback: ApiCallback? = null,
|
|
500
|
+
) = owner("POST", "/chats/links/${enc(linkId)}/emojis", payload, null, callback)
|
|
501
|
+
|
|
502
|
+
/** query: kind, enabled ("0"|"1"), nextCursor, prevCursor, limit (≤100) */
|
|
503
|
+
fun listLinkEmojis(
|
|
504
|
+
linkId: String,
|
|
505
|
+
query: Map<String, String>? = null,
|
|
506
|
+
callback: ApiCallback? = null,
|
|
507
|
+
) = owner("GET", "/chats/links/${enc(linkId)}/emojis", null, query, callback)
|
|
508
|
+
|
|
509
|
+
/** payload: { shortcode?, enabled? } */
|
|
510
|
+
fun updateLinkEmoji(
|
|
511
|
+
linkId: String,
|
|
512
|
+
emojiId: String,
|
|
513
|
+
payload: JSONObject,
|
|
514
|
+
callback: ApiCallback? = null,
|
|
515
|
+
) = owner("PATCH", "/chats/links/${enc(linkId)}/emojis/${enc(emojiId)}", payload, null, callback)
|
|
516
|
+
|
|
517
|
+
fun enableLinkEmoji(
|
|
518
|
+
linkId: String,
|
|
519
|
+
emojiId: String,
|
|
520
|
+
callback: ApiCallback? = null,
|
|
521
|
+
) = owner("POST", "/chats/links/${enc(linkId)}/emojis/${enc(emojiId)}/enable", null, null, callback)
|
|
522
|
+
|
|
523
|
+
fun disableLinkEmoji(
|
|
524
|
+
linkId: String,
|
|
525
|
+
emojiId: String,
|
|
526
|
+
callback: ApiCallback? = null,
|
|
527
|
+
) = owner("POST", "/chats/links/${enc(linkId)}/emojis/${enc(emojiId)}/disable", null, null, callback)
|
|
528
|
+
|
|
529
|
+
fun deleteLinkEmoji(
|
|
530
|
+
linkId: String,
|
|
531
|
+
emojiId: String,
|
|
532
|
+
callback: ApiCallback? = null,
|
|
533
|
+
) = owner("DELETE", "/chats/links/${enc(linkId)}/emojis/${enc(emojiId)}", null, null, callback)
|
|
534
|
+
|
|
535
|
+
/** Public member pack (GET /in/:linkCode/emoji-pack, no auth). */
|
|
536
|
+
fun getLinkEmojiPack(
|
|
537
|
+
linkCode: String,
|
|
538
|
+
callback: ApiCallback? = null,
|
|
539
|
+
) = request("GET", "/in/${enc(linkCode)}/emoji-pack", null, null, callback, Base.ROOT, Auth.NONE)
|
|
540
|
+
|
|
541
|
+
// ===================
|
|
542
|
+
// POSTS: DRAFTS, SCHEDULE, PUBLISH (owner console — needs ownerToken)
|
|
543
|
+
// ===================
|
|
544
|
+
|
|
545
|
+
/** Owner POST /posts; payload may include scheduledAt (ISO), asDraft, allowReplies, background (STORY: ink|brand|lagoon|sun), visibility (LINK_MEMBERS|PUBLIC|FOLLOWERS). */
|
|
546
|
+
fun createPost(
|
|
547
|
+
payload: JSONObject,
|
|
548
|
+
callback: ApiCallback? = null,
|
|
549
|
+
) = owner("POST", "/posts", payload, null, callback)
|
|
550
|
+
|
|
551
|
+
/** query: postByStatuses ("SCHEDULED"|"DRAFT"|…), postByTypes, nextCursor, limit */
|
|
552
|
+
fun listPosts(
|
|
553
|
+
query: Map<String, String>? = null,
|
|
554
|
+
callback: ApiCallback? = null,
|
|
555
|
+
) = owner("GET", "/posts", null, query, callback)
|
|
556
|
+
|
|
557
|
+
/** payload: { scheduledAt, expiresAt? } */
|
|
558
|
+
fun schedulePost(
|
|
559
|
+
postId: String,
|
|
560
|
+
payload: JSONObject,
|
|
561
|
+
callback: ApiCallback? = null,
|
|
562
|
+
) = owner("POST", "/posts/${enc(postId)}/schedule", payload, null, callback)
|
|
563
|
+
|
|
564
|
+
fun publishPost(
|
|
565
|
+
postId: String,
|
|
566
|
+
callback: ApiCallback? = null,
|
|
567
|
+
) = owner("POST", "/posts/${enc(postId)}/publish", null, null, callback)
|
|
568
|
+
|
|
569
|
+
fun cancelPostSchedule(
|
|
570
|
+
postId: String,
|
|
571
|
+
callback: ApiCallback? = null,
|
|
572
|
+
) = owner("POST", "/posts/${enc(postId)}/cancel-schedule", null, null, callback)
|
|
573
|
+
|
|
574
|
+
// ===================
|
|
575
|
+
// PROMO ANALYTICS
|
|
576
|
+
// ===================
|
|
577
|
+
|
|
578
|
+
/** 30-day + lifetime stats for a PROMOTION post (owner console — needs ownerToken). */
|
|
579
|
+
fun getPromoAnalytics(
|
|
580
|
+
postId: String,
|
|
581
|
+
callback: ApiCallback? = null,
|
|
582
|
+
) = owner("GET", "/posts/${enc(postId)}/analytics", null, null, callback)
|
|
583
|
+
|
|
584
|
+
/** Public CTA click; call before opening result "url". visitorId: [A-Za-z0-9_-]{8,64}. */
|
|
585
|
+
fun trackPromoClick(
|
|
586
|
+
postId: String,
|
|
587
|
+
visitorId: String? = null,
|
|
588
|
+
callback: ApiCallback? = null,
|
|
589
|
+
) {
|
|
590
|
+
val body = JSONObject()
|
|
591
|
+
if (visitorId != null && VISITOR_ID.matches(visitorId)) body.put("visitorId", visitorId)
|
|
592
|
+
request("POST", "/promos/${enc(postId)}/click", body, null, callback, Base.API, Auth.NONE, retry = false)
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
// ===================
|
|
596
|
+
// CHAT FEATURES — member = memberToken; user = memberToken, else ownerToken; owner = ownerToken
|
|
597
|
+
// ===================
|
|
598
|
+
|
|
599
|
+
/** Seen-by / delivered list (sender or conversation admin; owner org-scoped). */
|
|
600
|
+
/** A message's edit history (prior versions + current), gated by editHistoryAdminsOnly */
|
|
601
|
+
fun getMessageEditHistory(conversationId: String, messageId: String, callback: ApiCallback? = null) =
|
|
602
|
+
userRoute("GET", "/chats/conversations/${enc(conversationId)}/messages/${enc(messageId)}/history", null, null, callback)
|
|
603
|
+
|
|
604
|
+
fun getMessageInfo(
|
|
605
|
+
conversationId: String,
|
|
606
|
+
messageId: String,
|
|
607
|
+
query: Map<String, String>? = null,
|
|
608
|
+
callback: ApiCallback? = null,
|
|
609
|
+
) = userRoute("GET", "/chats/conversations/${enc(conversationId)}/messages/${enc(messageId)}/info", null, query, callback)
|
|
610
|
+
|
|
611
|
+
/** Conversation admins: export to your own account email. format: "CSV" | "PDF" | "JSON" | "ZIP". */
|
|
612
|
+
fun exportConversationAsAdmin(
|
|
613
|
+
conversationId: String,
|
|
614
|
+
format: String? = null,
|
|
615
|
+
callback: ApiCallback? = null,
|
|
616
|
+
) = member(
|
|
617
|
+
"POST",
|
|
618
|
+
"/chats/conversations/${enc(conversationId)}/member-export",
|
|
619
|
+
JSONObject().apply { if (format != null) put("format", format) },
|
|
620
|
+
null,
|
|
621
|
+
callback,
|
|
622
|
+
)
|
|
623
|
+
|
|
624
|
+
/** body: { format?, scope? ("mine"|"all"), includeMedia?, from?, to? (ISO or YYYY-MM-DD), emailMe? }; returns { exportId, email, scope } */
|
|
625
|
+
fun exportConversationAsMember(
|
|
626
|
+
conversationId: String,
|
|
627
|
+
payload: JSONObject,
|
|
628
|
+
callback: ApiCallback? = null,
|
|
629
|
+
) = member("POST", "/chats/conversations/${enc(conversationId)}/member-export", payload, null, callback)
|
|
630
|
+
|
|
631
|
+
/** Your own member export: { exportId, status, format, totalMessages, downloadUrl, error } */
|
|
632
|
+
fun getMemberExportStatus(
|
|
633
|
+
conversationId: String,
|
|
634
|
+
exportId: String,
|
|
635
|
+
callback: ApiCallback? = null,
|
|
636
|
+
) = member("GET", "/chats/conversations/${enc(conversationId)}/member-export/${enc(exportId)}", null, null, callback)
|
|
637
|
+
|
|
638
|
+
/** ownerToken; body: { email, format?, includeMedia?, from?, to? }: { success, exportId, message } */
|
|
639
|
+
fun exportConversationAsOwner(
|
|
640
|
+
conversationId: String,
|
|
641
|
+
payload: JSONObject,
|
|
642
|
+
callback: ApiCallback? = null,
|
|
643
|
+
) = owner("POST", "/chats/conversations/${enc(conversationId)}/export", payload, null, callback)
|
|
644
|
+
|
|
645
|
+
/** body: { duration: 1h|8h|1w|forever|off } */
|
|
646
|
+
fun muteConversation(
|
|
647
|
+
conversationId: String,
|
|
648
|
+
payload: JSONObject,
|
|
649
|
+
callback: ApiCallback? = null,
|
|
650
|
+
) = member("POST", "/chats/conversations/${enc(conversationId)}/mute", payload, null, callback)
|
|
651
|
+
|
|
652
|
+
/** Your quiet hours plus "account" (linked business window, or null). */
|
|
653
|
+
/** Every unsent draft this member has, for cross-device sync on load → { drafts } */
|
|
654
|
+
fun getDrafts(callback: ApiCallback? = null) =
|
|
655
|
+
member("GET", "/chats/drafts", null, null, callback)
|
|
656
|
+
|
|
657
|
+
fun getQuietHours(
|
|
658
|
+
callback: ApiCallback? = null,
|
|
659
|
+
) = member("GET", "/chats/settings/quiet-hours", null, null, callback)
|
|
660
|
+
|
|
661
|
+
/** body: { enabled, start: HH:mm, end: HH:mm, timezone } */
|
|
662
|
+
fun setQuietHours(
|
|
663
|
+
payload: JSONObject,
|
|
664
|
+
callback: ApiCallback? = null,
|
|
665
|
+
) = member("POST", "/chats/settings/quiet-hours", payload, null, callback)
|
|
666
|
+
|
|
667
|
+
/** body: { conversationId, messageId, kind, preset?, remindAt?, note? } */
|
|
668
|
+
fun createReminder(
|
|
669
|
+
payload: JSONObject,
|
|
670
|
+
callback: ApiCallback? = null,
|
|
671
|
+
) = member("POST", "/chats/reminders", payload, null, callback)
|
|
672
|
+
|
|
673
|
+
/** query: kind, nextCursor, limit (≤50) — pending only. */
|
|
674
|
+
fun listReminders(
|
|
675
|
+
query: Map<String, String>? = null,
|
|
676
|
+
callback: ApiCallback? = null,
|
|
677
|
+
) = member("GET", "/chats/reminders", null, query, callback)
|
|
678
|
+
|
|
679
|
+
/** Cancel a reminder. */
|
|
680
|
+
fun cancelReminder(
|
|
681
|
+
reminderId: String,
|
|
682
|
+
callback: ApiCallback? = null,
|
|
683
|
+
) = member("DELETE", "/chats/reminders/${enc(reminderId)}", null, null, callback)
|
|
684
|
+
|
|
685
|
+
/** Mark a reminder / read-later item done. */
|
|
686
|
+
fun completeReminder(
|
|
687
|
+
reminderId: String,
|
|
688
|
+
callback: ApiCallback? = null,
|
|
689
|
+
) = member("POST", "/chats/reminders/${enc(reminderId)}/done", null, null, callback)
|
|
690
|
+
|
|
691
|
+
/** Conversation permissions + slow mode. */
|
|
692
|
+
fun getConversationPermissions(
|
|
693
|
+
conversationId: String,
|
|
694
|
+
callback: ApiCallback? = null,
|
|
695
|
+
) = userRoute("GET", "/chats/conversations/${enc(conversationId)}/permissions", null, null, callback)
|
|
696
|
+
|
|
697
|
+
/** Conversation admin or owner; body: membersCan*?, slowModeSeconds?, allowScreenshots?, isPrivate? */
|
|
698
|
+
fun updateConversationPermissions(
|
|
699
|
+
conversationId: String,
|
|
700
|
+
payload: JSONObject,
|
|
701
|
+
callback: ApiCallback? = null,
|
|
702
|
+
) = userRoute("PATCH", "/chats/conversations/${enc(conversationId)}/permissions", payload, null, callback)
|
|
703
|
+
|
|
704
|
+
/** { enabled, audio, video } — hide Transcribe when disabled. */
|
|
705
|
+
fun getTranscribeAvailability(
|
|
706
|
+
callback: ApiCallback? = null,
|
|
707
|
+
) = userRoute("GET", "/chats/transcription/availability", null, null, callback)
|
|
708
|
+
|
|
709
|
+
/** Failures come back as transcript.errorCode. */
|
|
710
|
+
fun transcribeMessage(
|
|
711
|
+
conversationId: String,
|
|
712
|
+
messageId: String,
|
|
713
|
+
callback: ApiCallback? = null,
|
|
714
|
+
) = userRoute("POST", "/chats/conversations/${enc(conversationId)}/messages/${enc(messageId)}/transcribe", null, null, callback)
|
|
715
|
+
|
|
716
|
+
/** Current transcript. */
|
|
717
|
+
fun getTranscript(
|
|
718
|
+
conversationId: String,
|
|
719
|
+
messageId: String,
|
|
720
|
+
callback: ApiCallback? = null,
|
|
721
|
+
) = userRoute("GET", "/chats/conversations/${enc(conversationId)}/messages/${enc(messageId)}/transcript", null, null, callback)
|
|
722
|
+
|
|
723
|
+
/** Summary (or errorCode). */
|
|
724
|
+
fun summarizeTranscript(
|
|
725
|
+
conversationId: String,
|
|
726
|
+
messageId: String,
|
|
727
|
+
callback: ApiCallback? = null,
|
|
728
|
+
) = userRoute("POST", "/chats/conversations/${enc(conversationId)}/messages/${enc(messageId)}/transcript/summary", null, null, callback)
|
|
729
|
+
|
|
730
|
+
/** body: { targetLanguage: "fr" } */
|
|
731
|
+
fun translateTranscript(
|
|
732
|
+
conversationId: String,
|
|
733
|
+
messageId: String,
|
|
734
|
+
payload: JSONObject,
|
|
735
|
+
callback: ApiCallback? = null,
|
|
736
|
+
) = userRoute("POST", "/chats/conversations/${enc(conversationId)}/messages/${enc(messageId)}/transcript/translate", payload, null, callback)
|
|
737
|
+
|
|
738
|
+
/** body: { initialMediaKind?: audio|video } — then sock().joinHop */
|
|
739
|
+
fun startHuddle(
|
|
740
|
+
conversationId: String,
|
|
741
|
+
payload: JSONObject,
|
|
742
|
+
callback: ApiCallback? = null,
|
|
743
|
+
) = member("POST", "/hops/huddles/${enc(conversationId)}/start", payload, null, callback)
|
|
744
|
+
|
|
745
|
+
/** Huddle status. */
|
|
746
|
+
fun getHuddle(
|
|
747
|
+
conversationId: String,
|
|
748
|
+
callback: ApiCallback? = null,
|
|
749
|
+
) = member("GET", "/hops/huddles/${enc(conversationId)}", null, null, callback)
|
|
750
|
+
|
|
751
|
+
/** Host/co-host or conversation admin. */
|
|
752
|
+
fun endHuddle(
|
|
753
|
+
conversationId: String,
|
|
754
|
+
callback: ApiCallback? = null,
|
|
755
|
+
) = member("POST", "/hops/huddles/${enc(conversationId)}/end", null, null, callback)
|
|
756
|
+
|
|
757
|
+
/** Owner; body: { enabled } */
|
|
758
|
+
fun setLinkAutoTranscribe(
|
|
759
|
+
linkId: String,
|
|
760
|
+
payload: JSONObject,
|
|
761
|
+
callback: ApiCallback? = null,
|
|
762
|
+
) = owner("POST", "/chats/links/${enc(linkId)}/auto-transcribe", payload, null, callback)
|
|
763
|
+
|
|
764
|
+
/** Owner; body: { enabled } */
|
|
765
|
+
fun setLinkAgentInbox(
|
|
766
|
+
linkId: String,
|
|
767
|
+
payload: JSONObject,
|
|
768
|
+
callback: ApiCallback? = null,
|
|
769
|
+
) = owner("POST", "/chats/links/${enc(linkId)}/agent-inbox", payload, null, callback)
|
|
770
|
+
|
|
771
|
+
/** Owner; query: lane (waiting|mine|unassigned|resolved), chatLinkId?, nextCursor, limit (≤20) */
|
|
772
|
+
fun listInbox(
|
|
773
|
+
query: Map<String, String>? = null,
|
|
774
|
+
callback: ApiCallback? = null,
|
|
775
|
+
) = owner("GET", "/chats/inbox", null, query, callback)
|
|
776
|
+
|
|
777
|
+
/** Owner; body: { assigneeId } (JSONObject.NULL / NSNull / null unassigns) */
|
|
778
|
+
fun assignInbox(
|
|
779
|
+
conversationId: String,
|
|
780
|
+
payload: JSONObject,
|
|
781
|
+
callback: ApiCallback? = null,
|
|
782
|
+
) = owner("POST", "/chats/inbox/${enc(conversationId)}/assign", payload, null, callback)
|
|
783
|
+
|
|
784
|
+
/** Owner; body: { status: open|waiting|resolved } */
|
|
785
|
+
fun setInboxStatus(
|
|
786
|
+
conversationId: String,
|
|
787
|
+
payload: JSONObject,
|
|
788
|
+
callback: ApiCallback? = null,
|
|
789
|
+
) = owner("POST", "/chats/inbox/${enc(conversationId)}/status", payload, null, callback)
|
|
790
|
+
|
|
791
|
+
/** Owner; body: { slaTargetMinutes?: Int|null, topics?: [{ id?, label, tag?, assigneeId? }] (≤8) } */
|
|
792
|
+
fun setLinkInboxSettings(
|
|
793
|
+
linkId: String,
|
|
794
|
+
payload: JSONObject,
|
|
795
|
+
callback: ApiCallback? = null,
|
|
796
|
+
) = owner("POST", "/chats/links/${enc(linkId)}/inbox-settings", payload, null, callback)
|
|
797
|
+
|
|
798
|
+
/** Owner; body: { enabled } — offer the link in "Did you mean" suggestions */
|
|
799
|
+
fun setLinkDiscoverable(
|
|
800
|
+
linkId: String,
|
|
801
|
+
payload: JSONObject,
|
|
802
|
+
callback: ApiCallback? = null,
|
|
803
|
+
) = owner("POST", "/chats/links/${enc(linkId)}/discoverable", payload, null, callback)
|
|
804
|
+
|
|
805
|
+
// ===================
|
|
806
|
+
// SUPPORT CSAT
|
|
807
|
+
// ===================
|
|
808
|
+
|
|
809
|
+
/** memberToken (the conversation's customer); body { score: 1-5, comment? (≤500), ratingId? }: the rating; never retried */
|
|
810
|
+
fun submitCsat(conversationId: String, payload: JSONObject, callback: ApiCallback? = null) =
|
|
811
|
+
member("POST", "/chats/conversations/${enc(conversationId)}/csat", payload, null, callback, retry = false)
|
|
812
|
+
|
|
813
|
+
/** API key; rated requests newest first. query: from?, to? (ISO), chatLinkId?, nextCursor?, limit? (≤20): { results, nextCursor, hasMore } */
|
|
814
|
+
fun listCsatRatings(query: Map<String, String>? = null, callback: ApiCallback? = null) = get("/chats/csat", query, callback)
|
|
815
|
+
|
|
816
|
+
/** API key; query: from?, to?, chatLinkId?: { requests, responses, average, satisfiedPct, responseRatePct, agents, teams } */
|
|
817
|
+
fun getCsatSummary(query: Map<String, String>? = null, callback: ApiCallback? = null) = get("/chats/csat/summary", query, callback)
|
|
818
|
+
|
|
819
|
+
/** Owner; listCsatRatings with the owner token */
|
|
820
|
+
fun listCsatRatingsAsOwner(query: Map<String, String>? = null, callback: ApiCallback? = null) =
|
|
821
|
+
owner("GET", "/chats/csat", null, query, callback)
|
|
822
|
+
|
|
823
|
+
/** Owner; getCsatSummary with the owner token */
|
|
824
|
+
fun getCsatSummaryAsOwner(query: Map<String, String>? = null, callback: ApiCallback? = null) =
|
|
825
|
+
owner("GET", "/chats/csat/summary", null, query, callback)
|
|
826
|
+
|
|
827
|
+
// ===================
|
|
828
|
+
// LINK MEMBERS (owner)
|
|
829
|
+
// ===================
|
|
830
|
+
|
|
831
|
+
/** Owner; query: q?, status? (all|active|blocked|invited), limit? (≤100), nextCursor?: { results, nextCursor, hasMore, total } */
|
|
832
|
+
fun getLinkMemberList(linkId: String, query: Map<String, String>? = null, callback: ApiCallback? = null) =
|
|
833
|
+
owner("GET", "/chats/links/${enc(linkId)}/member-list", null, query, callback)
|
|
834
|
+
|
|
835
|
+
/** Owner; off the invite list, and blocked if they already joined: { status: true, blocked } */
|
|
836
|
+
fun revokeLinkInvite(linkId: String, memberId: String, callback: ApiCallback? = null) =
|
|
837
|
+
ownerNoRetry("DELETE", "/chats/links/${enc(linkId)}/members/${enc(memberId)}/invite", null, callback)
|
|
838
|
+
|
|
839
|
+
/** Owner; body: { preChat: { enabled, intro, fields }, businessHours: { enabled, timezone, awayMessage, week } } */
|
|
840
|
+
fun setWidgetConfig(
|
|
841
|
+
linkId: String,
|
|
842
|
+
payload: JSONObject,
|
|
843
|
+
callback: ApiCallback? = null,
|
|
844
|
+
) = owner("PUT", "/chats/links/${enc(linkId)}/widget", payload, null, callback)
|
|
845
|
+
|
|
846
|
+
// ===================
|
|
847
|
+
// SUPPORT INBOX — chat-UI agents (memberToken; the server re-checks team + membership)
|
|
848
|
+
// ===================
|
|
849
|
+
|
|
850
|
+
/** { agent, userId?, teamRole?, team } — agent: false for non-team chat users */
|
|
851
|
+
fun getInboxAgentProfile(
|
|
852
|
+
callback: ApiCallback? = null,
|
|
853
|
+
) = member("GET", "/chats/agent-inbox/me", null, null, callback)
|
|
854
|
+
|
|
855
|
+
/** query: nextCursor, limit (≤20) */
|
|
856
|
+
fun listInternalNotes(
|
|
857
|
+
conversationId: String,
|
|
858
|
+
query: Map<String, String>? = null,
|
|
859
|
+
callback: ApiCallback? = null,
|
|
860
|
+
) = member("GET", "/chats/agent-inbox/${enc(conversationId)}/internal-notes", null, query, callback)
|
|
861
|
+
|
|
862
|
+
/** body: { message (≤3000), referenceId? } — agents only, never sent to the customer */
|
|
863
|
+
fun createInternalNote(
|
|
864
|
+
conversationId: String,
|
|
865
|
+
payload: JSONObject,
|
|
866
|
+
callback: ApiCallback? = null,
|
|
867
|
+
) = member("POST", "/chats/agent-inbox/${enc(conversationId)}/internal-notes", payload, null, callback)
|
|
868
|
+
|
|
869
|
+
/** Delete an internal note (own; owner/admin agents any). */
|
|
870
|
+
fun deleteInternalNote(
|
|
871
|
+
conversationId: String,
|
|
872
|
+
noteId: String,
|
|
873
|
+
callback: ApiCallback? = null,
|
|
874
|
+
) = member("DELETE", "/chats/agent-inbox/${enc(conversationId)}/internal-notes/${enc(noteId)}", null, null, callback)
|
|
875
|
+
|
|
876
|
+
/** { inbox, slaTargetMinutes, sla, topic, tag } */
|
|
877
|
+
fun getAgentInboxState(
|
|
878
|
+
conversationId: String,
|
|
879
|
+
callback: ApiCallback? = null,
|
|
880
|
+
) = member("GET", "/chats/agent-inbox/${enc(conversationId)}/state", null, null, callback)
|
|
881
|
+
|
|
882
|
+
/** body: { assigneeId } (JSONObject.NULL unassigns) */
|
|
883
|
+
fun agentAssignConversation(
|
|
884
|
+
conversationId: String,
|
|
885
|
+
payload: JSONObject,
|
|
886
|
+
callback: ApiCallback? = null,
|
|
887
|
+
) = member("POST", "/chats/agent-inbox/${enc(conversationId)}/assign", payload, null, callback)
|
|
888
|
+
|
|
889
|
+
/** body: { status: open|waiting|resolved } */
|
|
890
|
+
fun agentSetInboxStatus(
|
|
891
|
+
conversationId: String,
|
|
892
|
+
payload: JSONObject,
|
|
893
|
+
callback: ApiCallback? = null,
|
|
894
|
+
) = member("POST", "/chats/agent-inbox/${enc(conversationId)}/status", payload, null, callback)
|
|
895
|
+
|
|
896
|
+
/** Customer notes; query: nextCursor, limit (≤20) */
|
|
897
|
+
fun listConversationNotes(
|
|
898
|
+
conversationId: String,
|
|
899
|
+
query: Map<String, String>? = null,
|
|
900
|
+
callback: ApiCallback? = null,
|
|
901
|
+
) = member("GET", "/chats/agent-inbox/${enc(conversationId)}/notes", null, query, callback)
|
|
902
|
+
|
|
903
|
+
/** body: { text (≤2000) } */
|
|
904
|
+
fun createConversationNote(
|
|
905
|
+
conversationId: String,
|
|
906
|
+
payload: JSONObject,
|
|
907
|
+
callback: ApiCallback? = null,
|
|
908
|
+
) = member("POST", "/chats/agent-inbox/${enc(conversationId)}/notes", payload, null, callback)
|
|
909
|
+
|
|
910
|
+
/** body: { text } — PATCH goes out as POST + X-HTTP-Method-Override */
|
|
911
|
+
fun updateConversationNote(
|
|
912
|
+
conversationId: String,
|
|
913
|
+
noteId: String,
|
|
914
|
+
payload: JSONObject,
|
|
915
|
+
callback: ApiCallback? = null,
|
|
916
|
+
) = member("PATCH", "/chats/agent-inbox/${enc(conversationId)}/notes/${enc(noteId)}", payload, null, callback)
|
|
917
|
+
|
|
918
|
+
/** Delete a customer note. */
|
|
919
|
+
fun deleteConversationNote(
|
|
920
|
+
conversationId: String,
|
|
921
|
+
noteId: String,
|
|
922
|
+
callback: ApiCallback? = null,
|
|
923
|
+
) = member("DELETE", "/chats/agent-inbox/${enc(conversationId)}/notes/${enc(noteId)}", null, null, callback)
|
|
924
|
+
|
|
925
|
+
/** AI summary; failures come back as errorCode (OUT_OF_AI_CREDITS|NOT_ENOUGH_MESSAGES|PROVIDER_FAILED). */
|
|
926
|
+
fun getConversationSummary(
|
|
927
|
+
conversationId: String,
|
|
928
|
+
callback: ApiCallback? = null,
|
|
929
|
+
) = member("GET", "/chats/agent-inbox/${enc(conversationId)}/summary", null, null, callback)
|
|
930
|
+
|
|
931
|
+
/** Any member: private AI draft { draft, errorCode? } for your next message; nothing is posted. */
|
|
932
|
+
fun draftConversationReply(
|
|
933
|
+
conversationId: String,
|
|
934
|
+
note: String? = null,
|
|
935
|
+
callback: ApiCallback? = null,
|
|
936
|
+
) = member("POST", "/chats/conversations/${enc(conversationId)}/draft-reply", if (note != null) JSONObject().put("note", note) else JSONObject(), null, callback, retry = false)
|
|
937
|
+
|
|
938
|
+
/** Agents: AI reply draft { draft, errorCode? }; spends the owner's AI credits. */
|
|
939
|
+
fun getDraftReply(
|
|
940
|
+
conversationId: String,
|
|
941
|
+
callback: ApiCallback? = null,
|
|
942
|
+
) = member("POST", "/chats/agent-inbox/${enc(conversationId)}/draft-reply", null, null, callback)
|
|
943
|
+
|
|
944
|
+
/** body: { unreadCount (≥8 for a summary) } */
|
|
945
|
+
fun getConversationCatchUp(
|
|
946
|
+
conversationId: String,
|
|
947
|
+
payload: JSONObject,
|
|
948
|
+
callback: ApiCallback? = null,
|
|
949
|
+
) = member("POST", "/chats/conversations/${enc(conversationId)}/catch-up", payload, null, callback)
|
|
950
|
+
|
|
951
|
+
/** body: { topicId } — first pick wins for customers; may auto-assign */
|
|
952
|
+
fun setConversationTopic(
|
|
953
|
+
conversationId: String,
|
|
954
|
+
payload: JSONObject,
|
|
955
|
+
callback: ApiCallback? = null,
|
|
956
|
+
) = member("POST", "/chats/conversations/${enc(conversationId)}/topic", payload, null, callback)
|
|
957
|
+
|
|
958
|
+
/** Public (no auth): { enabled, agentsOnline, typicalReplyMinutes } */
|
|
959
|
+
fun getPresenceStats(
|
|
960
|
+
linkCode: String,
|
|
961
|
+
callback: ApiCallback? = null,
|
|
962
|
+
) = request("GET", "/in/${enc(linkCode)}/presence-stats", null, null, callback, Base.ROOT, Auth.NONE)
|
|
963
|
+
|
|
964
|
+
// ===================
|
|
965
|
+
// CHAT CORE — my links, availability, gifts (chat-features-api.md §14)
|
|
966
|
+
// ===================
|
|
967
|
+
|
|
968
|
+
/** query: search?, status? (ACTIVE|DISABLED|EXPIRED|ARCHIVED), nextCursor?, limit? (≤20); rows carry memberCount and role (owner|admin|agent|member) */
|
|
969
|
+
fun listMyChatLinks(
|
|
970
|
+
query: Map<String, String>? = null,
|
|
971
|
+
callback: ApiCallback? = null,
|
|
972
|
+
) = member("GET", "/chat-users/me/links", null, query, callback)
|
|
973
|
+
|
|
974
|
+
/** Leave every conversation in the link (history kept) and drop it from your links: { left } */
|
|
975
|
+
fun leaveMyLink(
|
|
976
|
+
linkId: String,
|
|
977
|
+
callback: ApiCallback? = null,
|
|
978
|
+
) = member("POST", "/chat-users/me/links/${enc(linkId)}/leave", null, null, callback)
|
|
979
|
+
|
|
980
|
+
/** Fold the no-email guest this device held into the signed-in member; guestToken is the guest's live access token (10 a minute): { merged, outcome?, moved?, folded?, dropped? } */
|
|
981
|
+
fun claimGuest(
|
|
982
|
+
guestToken: String,
|
|
983
|
+
callback: ApiCallback? = null,
|
|
984
|
+
) = member("POST", "/chat-users/me/claim-guest", JSONObject().put("guestToken", guestToken), null, callback, retry = false)
|
|
985
|
+
|
|
986
|
+
/** Your push level for one link: "all" | "mentions" | "off" → { chatLinkId, level } */
|
|
987
|
+
fun setMyLinkNotify(
|
|
988
|
+
linkId: String,
|
|
989
|
+
level: String,
|
|
990
|
+
callback: ApiCallback? = null,
|
|
991
|
+
) = member("PUT", "/chat-users/me/links/${enc(linkId)}/notify", JSONObject().put("level", level), null, callback)
|
|
992
|
+
|
|
993
|
+
/** Teammates on one of your links, online first (limit 1–5): { results } */
|
|
994
|
+
fun listLinkMembers(
|
|
995
|
+
chatLinkId: String,
|
|
996
|
+
limit: Int? = null,
|
|
997
|
+
callback: ApiCallback? = null,
|
|
998
|
+
) = member("GET", "/chat-users/me/link-members", null,
|
|
999
|
+
if (limit == null) mapOf("chatLinkId" to chatLinkId) else mapOf("chatLinkId" to chatLinkId, "limit" to limit.toString()), callback)
|
|
1000
|
+
|
|
1001
|
+
/** ownerToken; keywords (≤10) tried on the link's last 7 days: { matched, scanned, total, capped, keywords } */
|
|
1002
|
+
fun testAutomationKeywords(
|
|
1003
|
+
chatLinkId: String,
|
|
1004
|
+
keywords: List<String>,
|
|
1005
|
+
callback: ApiCallback? = null,
|
|
1006
|
+
) = owner("POST", "/chats/automations/test", JSONObject().put("chatLinkId", chatLinkId).put("keywords", JSONArray(keywords)), null, callback)
|
|
1007
|
+
|
|
1008
|
+
/** Public (no auth): { enabled, open, timezone, nextOpenLabel, awayMessage } */
|
|
1009
|
+
fun getLinkAvailability(
|
|
1010
|
+
linkCode: String,
|
|
1011
|
+
callback: ApiCallback? = null,
|
|
1012
|
+
) = request("GET", "/in/${enc(linkCode)}/availability", null, null, callback, Base.ROOT, Auth.NONE)
|
|
1013
|
+
|
|
1014
|
+
/** body: { reference, note? (≤140) } — share a verified gift you paid for */
|
|
1015
|
+
fun announceGift(
|
|
1016
|
+
conversationId: String,
|
|
1017
|
+
payload: JSONObject,
|
|
1018
|
+
callback: ApiCallback? = null,
|
|
1019
|
+
) = member("POST", "/chats/conversations/${enc(conversationId)}/gift-announce", payload, null, callback)
|
|
1020
|
+
|
|
1021
|
+
// ===================
|
|
1022
|
+
// SIGNED-IN SESSIONS + ACCOUNT QUIET HOURS
|
|
1023
|
+
// ===================
|
|
1024
|
+
|
|
1025
|
+
/** Business devices (ownerToken): { results: [{ id, browser, os, deviceType, client, country, city, createdAt, lastActiveAt, current }], currentId } */
|
|
1026
|
+
fun listAccountSessions(
|
|
1027
|
+
callback: ApiCallback? = null,
|
|
1028
|
+
) = owner("GET", "/users/sessions", null, null, callback)
|
|
1029
|
+
|
|
1030
|
+
/** { revoked: 1 }; 400 for the calling session, 404 if not yours. */
|
|
1031
|
+
fun revokeAccountSession(
|
|
1032
|
+
sessionId: String,
|
|
1033
|
+
callback: ApiCallback? = null,
|
|
1034
|
+
) = owner("DELETE", "/users/sessions/${enc(sessionId)}", null, null, callback)
|
|
1035
|
+
|
|
1036
|
+
/** Sign out every other business device: { revoked } */
|
|
1037
|
+
fun revokeOtherAccountSessions(
|
|
1038
|
+
callback: ApiCallback? = null,
|
|
1039
|
+
) = owner("POST", "/users/sessions/revoke-others", null, null, callback)
|
|
1040
|
+
|
|
1041
|
+
/** Chat-user devices (memberToken); same shape as listAccountSessions. */
|
|
1042
|
+
fun listMySessions(
|
|
1043
|
+
callback: ApiCallback? = null,
|
|
1044
|
+
) = member("GET", "/chat-users/me/sessions", null, null, callback)
|
|
1045
|
+
|
|
1046
|
+
/** { revoked: 1 }; 400 for the calling session, 404 if not yours. */
|
|
1047
|
+
fun revokeMySession(
|
|
1048
|
+
sessionId: String,
|
|
1049
|
+
callback: ApiCallback? = null,
|
|
1050
|
+
) = member("DELETE", "/chat-users/me/sessions/${enc(sessionId)}", null, null, callback)
|
|
1051
|
+
|
|
1052
|
+
/** Sign out every other chat-user device: { revoked } */
|
|
1053
|
+
fun revokeMyOtherSessions(
|
|
1054
|
+
callback: ApiCallback? = null,
|
|
1055
|
+
) = member("POST", "/chat-users/me/sessions/revoke-others", null, null, callback)
|
|
1056
|
+
|
|
1057
|
+
/** Business quiet hours (ownerToken): { enabled, start, end, timezone } */
|
|
1058
|
+
fun getAccountQuietHours(
|
|
1059
|
+
callback: ApiCallback? = null,
|
|
1060
|
+
) = owner("GET", "/users/me/quiet-hours", null, null, callback)
|
|
1061
|
+
|
|
1062
|
+
/** body: { enabled, start: HH:mm, end: HH:mm, timezone } — also quiets the same-e-mail chat identity */
|
|
1063
|
+
fun setAccountQuietHours(
|
|
1064
|
+
payload: JSONObject,
|
|
1065
|
+
callback: ApiCallback? = null,
|
|
1066
|
+
) = owner("PUT", "/users/me/quiet-hours", payload, null, callback)
|
|
1067
|
+
|
|
1068
|
+
// ===================
|
|
1069
|
+
// SCHEDULED SEND NOW, CALL DECLINE, LINK REOPEN, STATUS, WEBHOOK TEST, PUBLIC WEBINAR
|
|
1070
|
+
// ===================
|
|
1071
|
+
|
|
1072
|
+
/** Send one of your scheduled messages now (≤ 1 min): { _id, scheduledAt, queued: true }; 400 if already sent. */
|
|
1073
|
+
fun sendScheduledMessageNow(
|
|
1074
|
+
messageId: String,
|
|
1075
|
+
callback: ApiCallback? = null,
|
|
1076
|
+
) = member("POST", "/chats/messages/${enc(messageId)}/send-now", null, null, callback)
|
|
1077
|
+
|
|
1078
|
+
/** Decline a ringing call from the lock screen (no socket): { ok: true, sessionId } */
|
|
1079
|
+
fun declineHopInvite(
|
|
1080
|
+
sessionId: String,
|
|
1081
|
+
callback: ApiCallback? = null,
|
|
1082
|
+
) = member("POST", "/hops/${enc(sessionId)}/decline", null, null, callback)
|
|
1083
|
+
|
|
1084
|
+
/** Public; the call push's declineToken from the native call screen: { ok, sessionId }; 401 used / expired, 403 call ended */
|
|
1085
|
+
fun pushDeclineCall(token: String, callback: ApiCallback? = null) =
|
|
1086
|
+
request("POST", "/hops/push-decline", JSONObject().put("token", token), null, callback, Base.API, Auth.NONE, retry = false)
|
|
1087
|
+
|
|
1088
|
+
/** Member or owner token; body: { deviceToken?, webToken?, voipToken? (iOS hex), platform?, inlineReply? }: { success } */
|
|
1089
|
+
fun registerDevice(payload: JSONObject, callback: ApiCallback? = null) =
|
|
1090
|
+
userRoute("POST", "/notifications/register-device", payload, null, callback)
|
|
1091
|
+
|
|
1092
|
+
/** memberToken; ring up to 50 chat users into a call you are in (socket + push): { ok, invited } */
|
|
1093
|
+
fun inviteToHop(
|
|
1094
|
+
sessionId: String,
|
|
1095
|
+
chatUserIds: List<String>,
|
|
1096
|
+
callback: ApiCallback? = null,
|
|
1097
|
+
) {
|
|
1098
|
+
if (memberToken.isNullOrBlank()) {
|
|
1099
|
+
deliverResult(callback, null, "Member token required — set api().memberToken")
|
|
1100
|
+
return
|
|
1101
|
+
}
|
|
1102
|
+
val body = JSONObject().put("chatUserIds", JSONArray(chatUserIds))
|
|
1103
|
+
request("POST", "/hops/${enc(sessionId)}/invite", body, null, callback, Base.API, Auth.MEMBER, retry = false)
|
|
1104
|
+
}
|
|
1105
|
+
|
|
1106
|
+
/** Public "Live now · N online": { online } */
|
|
1107
|
+
fun getLinkOnlineCount(
|
|
1108
|
+
linkCode: String,
|
|
1109
|
+
callback: ApiCallback? = null,
|
|
1110
|
+
) = request("GET", "/in/${enc(linkCode)}/online-count", null, null, callback, Base.ROOT, Auth.NONE)
|
|
1111
|
+
|
|
1112
|
+
/** Public one-step guest join (displayName 2–30, email optional): { chatUser, accessToken, refreshToken, expireInSeconds, chatLink }; 400 LINK_FULL / ACCOUNT_EXISTS */
|
|
1113
|
+
fun joinLinkAsGuest(
|
|
1114
|
+
linkCode: String,
|
|
1115
|
+
displayName: String,
|
|
1116
|
+
email: String? = null,
|
|
1117
|
+
callback: ApiCallback? = null,
|
|
1118
|
+
meetingCode: String? = null,
|
|
1119
|
+
) {
|
|
1120
|
+
val body = JSONObject().put("displayName", displayName)
|
|
1121
|
+
if (!email.isNullOrBlank()) body.put("email", email)
|
|
1122
|
+
if (!meetingCode.isNullOrBlank()) body.put("meetingCode", meetingCode)
|
|
1123
|
+
request("POST", "/in/${enc(linkCode)}/join-guest", body, null, callback, Base.ROOT, Auth.NONE, retry = false)
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1126
|
+
/** Public: a returning meeting guest's emailed 6-digit code → the same session shape as joinLinkAsGuest */
|
|
1127
|
+
fun verifyMeetingGuest(
|
|
1128
|
+
linkCode: String,
|
|
1129
|
+
email: String,
|
|
1130
|
+
code: String,
|
|
1131
|
+
meetingCode: String,
|
|
1132
|
+
callback: ApiCallback? = null,
|
|
1133
|
+
) = request(
|
|
1134
|
+
"POST", "/in/${enc(linkCode)}/join-guest/verify",
|
|
1135
|
+
JSONObject().put("email", email).put("code", code).put("meetingCode", meetingCode),
|
|
1136
|
+
null, callback, Base.ROOT, Auth.NONE, retry = false,
|
|
1137
|
+
)
|
|
1138
|
+
|
|
1139
|
+
/** Public: email me once when this paused link reopens: { ok: true }; 400 if the link is not paused. */
|
|
1140
|
+
fun notifyWhenLinkReopens(
|
|
1141
|
+
linkCode: String,
|
|
1142
|
+
email: String,
|
|
1143
|
+
callback: ApiCallback? = null,
|
|
1144
|
+
) = request("POST", "/in/${enc(linkCode)}/notify-reopen", JSONObject().put("email", email), null, callback, Base.ROOT, Auth.NONE)
|
|
1145
|
+
|
|
1146
|
+
/** Public status updates by email: { subscribed: true } */
|
|
1147
|
+
fun subscribeToStatusUpdates(
|
|
1148
|
+
email: String,
|
|
1149
|
+
callback: ApiCallback? = null,
|
|
1150
|
+
) = request("POST", "/health/subscribe", JSONObject().put("email", email), null, callback, Base.API, Auth.NONE)
|
|
1151
|
+
|
|
1152
|
+
/** token = the signed one from the email's unsubscribe link: { unsubscribed } */
|
|
1153
|
+
fun unsubscribeFromStatusUpdates(
|
|
1154
|
+
email: String,
|
|
1155
|
+
token: String,
|
|
1156
|
+
callback: ApiCallback? = null,
|
|
1157
|
+
) = request("GET", "/health/unsubscribe", null, mapOf("email" to email, "token" to token), callback, Base.API, Auth.NONE)
|
|
1158
|
+
|
|
1159
|
+
/** API key: one immediate webhook.test delivery: { ok, status, durationMs, error } */
|
|
1160
|
+
fun testWebhook(
|
|
1161
|
+
webhookId: String,
|
|
1162
|
+
callback: ApiCallback? = null,
|
|
1163
|
+
) = post("/chats/webhooks/${enc(webhookId)}/test", null, callback)
|
|
1164
|
+
|
|
1165
|
+
/** Owner-console twin of testWebhook (ownerToken). */
|
|
1166
|
+
fun testWebhookAsOwner(
|
|
1167
|
+
webhookId: String,
|
|
1168
|
+
callback: ApiCallback? = null,
|
|
1169
|
+
) = owner("POST", "/chats/webhooks/${enc(webhookId)}/test", null, null, callback)
|
|
1170
|
+
|
|
1171
|
+
/** ownerToken; limit 1–20 (default 10): { results: [{ id, event, code, at, attempt, ok, canRetry }] } */
|
|
1172
|
+
fun getWebhookDeliveries(
|
|
1173
|
+
webhookId: String,
|
|
1174
|
+
limit: Int? = null,
|
|
1175
|
+
callback: ApiCallback? = null,
|
|
1176
|
+
) = owner("GET", "/chats/webhooks/${enc(webhookId)}/deliveries", null, limit?.let { mapOf("limit" to it.toString()) }, callback)
|
|
1177
|
+
|
|
1178
|
+
/** ownerToken; a row with canRetry: { queued: true } (next run, ≤ 30 s) */
|
|
1179
|
+
fun retryWebhookDelivery(
|
|
1180
|
+
webhookId: String,
|
|
1181
|
+
deliveryId: String,
|
|
1182
|
+
callback: ApiCallback? = null,
|
|
1183
|
+
) = ownerNoRetry("POST", "/chats/webhooks/${enc(webhookId)}/deliveries/${enc(deliveryId)}/retry", null, callback)
|
|
1184
|
+
|
|
1185
|
+
/** ownerToken; new signing secret, shown once: { secret, hint } */
|
|
1186
|
+
fun rotateWebhookSecret(
|
|
1187
|
+
webhookId: String,
|
|
1188
|
+
callback: ApiCallback? = null,
|
|
1189
|
+
) = ownerNoRetry("POST", "/chats/webhooks/${enc(webhookId)}/rotate-secret", null, callback)
|
|
1190
|
+
|
|
1191
|
+
/** ownerToken; start (or extend) listening: the next deliveries are kept 30 min, last 50: { active, expiresAt, results, lastSeq } */
|
|
1192
|
+
fun startWebhookCapture(
|
|
1193
|
+
webhookId: String,
|
|
1194
|
+
callback: ApiCallback? = null,
|
|
1195
|
+
) = ownerNoRetry("POST", "/chats/webhooks/${enc(webhookId)}/capture", null, callback)
|
|
1196
|
+
|
|
1197
|
+
/** ownerToken; deliveries after sequence [after], oldest first: { active, expiresAt, lastSeq, results: [{ seq, at, event, attempt, signature, body, truncated }] } */
|
|
1198
|
+
fun readWebhookCapture(
|
|
1199
|
+
webhookId: String,
|
|
1200
|
+
after: Int = 0,
|
|
1201
|
+
callback: ApiCallback? = null,
|
|
1202
|
+
) = owner("GET", "/chats/webhooks/${enc(webhookId)}/capture", null, mapOf("after" to after.toString()), callback)
|
|
1203
|
+
|
|
1204
|
+
/** ownerToken; stop listening and delete what was kept: { stopped: true } */
|
|
1205
|
+
fun stopWebhookCapture(
|
|
1206
|
+
webhookId: String,
|
|
1207
|
+
callback: ApiCallback? = null,
|
|
1208
|
+
) = ownerNoRetry("DELETE", "/chats/webhooks/${enc(webhookId)}/capture", null, callback)
|
|
1209
|
+
|
|
1210
|
+
/** ownerToken; a link's meetings, status upcoming (default) | live | ended | all (only `all` lists cancelled), limit up to 100: { results: [{ id, code, title, startAt, endAt, durationMinutes, status, joinUrl, ... }], nextCursor, hasMore } */
|
|
1211
|
+
fun listMeetings(
|
|
1212
|
+
linkId: String,
|
|
1213
|
+
status: String? = null,
|
|
1214
|
+
limit: Int? = null,
|
|
1215
|
+
nextCursor: String? = null,
|
|
1216
|
+
callback: ApiCallback? = null,
|
|
1217
|
+
) = owner("GET", "/hops/owner/meetings", null, meetingQuery(linkId, status, limit, nextCursor), callback)
|
|
1218
|
+
|
|
1219
|
+
/** ownerToken; body: { linkId, title, startAt (future ISO), durationMinutes (5-1440), invitees (1-70 emails or member ids), description?, requireAdmit?, timezone? }; idempotencyKey replays the first result for 24 h */
|
|
1220
|
+
fun scheduleMeeting(
|
|
1221
|
+
payload: JSONObject,
|
|
1222
|
+
idempotencyKey: String? = null,
|
|
1223
|
+
callback: ApiCallback? = null,
|
|
1224
|
+
) = request(
|
|
1225
|
+
"POST", "/hops/owner/meetings", payload, null, callback, Base.API, Auth.OWNER,
|
|
1226
|
+
retry = idempotencyKey != null, headers = idempotencyHeader(idempotencyKey), requireOwner = true,
|
|
1227
|
+
)
|
|
1228
|
+
|
|
1229
|
+
/** ownerToken; cancel a meeting (reason up to 300 characters), invitees are told; safe to repeat: { ok, id, status, alreadyCancelled } */
|
|
1230
|
+
fun cancelMeeting(
|
|
1231
|
+
meetingId: String,
|
|
1232
|
+
reason: String? = null,
|
|
1233
|
+
callback: ApiCallback? = null,
|
|
1234
|
+
) = request(
|
|
1235
|
+
"DELETE", "/hops/owner/meetings/${enc(meetingId)}", null, reason?.let { mapOf("reason" to it) }, callback, Base.API, Auth.OWNER,
|
|
1236
|
+
retry = false, requireOwner = true,
|
|
1237
|
+
)
|
|
1238
|
+
|
|
1239
|
+
/** API key; same as listMeetings through /external/meetings */
|
|
1240
|
+
fun listMeetingsWithKey(
|
|
1241
|
+
linkId: String,
|
|
1242
|
+
status: String? = null,
|
|
1243
|
+
limit: Int? = null,
|
|
1244
|
+
nextCursor: String? = null,
|
|
1245
|
+
callback: ApiCallback? = null,
|
|
1246
|
+
) = request("GET", "/meetings", null, meetingQuery(linkId, status, limit, nextCursor), callback)
|
|
1247
|
+
|
|
1248
|
+
/** API key; same as scheduleMeeting through /external/meetings */
|
|
1249
|
+
fun scheduleMeetingWithKey(
|
|
1250
|
+
payload: JSONObject,
|
|
1251
|
+
idempotencyKey: String? = null,
|
|
1252
|
+
callback: ApiCallback? = null,
|
|
1253
|
+
) = request("POST", "/meetings", payload, null, callback, retry = idempotencyKey != null, headers = idempotencyHeader(idempotencyKey))
|
|
1254
|
+
|
|
1255
|
+
/** API key; same as cancelMeeting through /external/meetings */
|
|
1256
|
+
fun cancelMeetingWithKey(
|
|
1257
|
+
meetingId: String,
|
|
1258
|
+
reason: String? = null,
|
|
1259
|
+
callback: ApiCallback? = null,
|
|
1260
|
+
) = request("DELETE", "/meetings/${enc(meetingId)}", null, reason?.let { mapOf("reason" to it) }, callback, retry = false)
|
|
1261
|
+
|
|
1262
|
+
private fun meetingQuery(linkId: String, status: String?, limit: Int?, nextCursor: String?): Map<String, String> =
|
|
1263
|
+
listOfNotNull("linkId" to linkId, status?.let { "status" to it }, nextCursor?.let { "nextCursor" to it }, limit?.let { "limit" to it.toString() }).toMap()
|
|
1264
|
+
|
|
1265
|
+
private fun idempotencyHeader(key: String?): Map<String, String> = if (key.isNullOrBlank()) emptyMap() else mapOf("Idempotency-Key" to key)
|
|
1266
|
+
|
|
1267
|
+
/** Your links (ownerToken); query: chatLinkExpiringDays (1–365) = ACTIVE links expiring within N days, chatLinkSearch, limit, … */
|
|
1268
|
+
fun listAccountChatLinks(
|
|
1269
|
+
query: Map<String, String>? = null,
|
|
1270
|
+
callback: ApiCallback? = null,
|
|
1271
|
+
) = owner("GET", "/chats/links", null, query, callback)
|
|
1272
|
+
|
|
1273
|
+
/** ownerToken; body: { firstName?, …, preferences?: { notifyTopics, language, translateIncomingTo ("off" disables), soundPreferences } }, merged by key */
|
|
1274
|
+
fun updateAccountProfile(
|
|
1275
|
+
payload: JSONObject,
|
|
1276
|
+
callback: ApiCallback? = null,
|
|
1277
|
+
) = owner("PATCH", "/users/me", payload, null, callback)
|
|
1278
|
+
|
|
1279
|
+
// ===================
|
|
1280
|
+
// TEAMS, INVITES, FOLLOWERS, PUSH REPLY, MEETINGS, WEBINAR RECORDINGS, GIFTS
|
|
1281
|
+
// ===================
|
|
1282
|
+
|
|
1283
|
+
/** Named teams (ownerToken): { results: [{ _id, name, description, chatLink, members, memberCount }], max } */
|
|
1284
|
+
fun listWorkspaceTeams(
|
|
1285
|
+
callback: ApiCallback? = null,
|
|
1286
|
+
) = owner("GET", "/users/teams", null, null, callback)
|
|
1287
|
+
|
|
1288
|
+
/** ownerToken; body: { name (≤40), description?, chatLinkId?, memberIds? (≤50) } */
|
|
1289
|
+
fun createWorkspaceTeam(
|
|
1290
|
+
payload: JSONObject,
|
|
1291
|
+
callback: ApiCallback? = null,
|
|
1292
|
+
) = owner("POST", "/users/teams", payload, null, callback)
|
|
1293
|
+
|
|
1294
|
+
/** ownerToken; memberIds replaces the list, chatLinkId null clears the scope */
|
|
1295
|
+
fun updateWorkspaceTeam(
|
|
1296
|
+
teamId: String,
|
|
1297
|
+
payload: JSONObject,
|
|
1298
|
+
callback: ApiCallback? = null,
|
|
1299
|
+
) = owner("PATCH", "/users/teams/${enc(teamId)}", payload, null, callback)
|
|
1300
|
+
|
|
1301
|
+
/** ownerToken: { status } */
|
|
1302
|
+
fun deleteWorkspaceTeam(
|
|
1303
|
+
teamId: String,
|
|
1304
|
+
callback: ApiCallback? = null,
|
|
1305
|
+
) = owner("DELETE", "/users/teams/${enc(teamId)}", null, null, callback)
|
|
1306
|
+
|
|
1307
|
+
/** ownerToken; body: { firstName, lastName?, username (email), teamRole? ADMIN|AGENT, answerLinks? }: { _id, firstName, lastName, username, handle, teamRole, answerLinks, invitePending, invitedAt, createdAt } */
|
|
1308
|
+
fun inviteTeamMember(
|
|
1309
|
+
payload: JSONObject,
|
|
1310
|
+
callback: ApiCallback? = null,
|
|
1311
|
+
) = ownerNoRetry("POST", "/users/team/invite", payload, callback)
|
|
1312
|
+
|
|
1313
|
+
/** ownerToken; body: { firstName, lastName?, email, chatLinkId, sendWelcome? }: { _id, existed, emailed } */
|
|
1314
|
+
fun inviteChatUser(
|
|
1315
|
+
payload: JSONObject,
|
|
1316
|
+
callback: ApiCallback? = null,
|
|
1317
|
+
) = ownerNoRetry("POST", "/chats/chat-users/invite", payload, callback)
|
|
1318
|
+
|
|
1319
|
+
/** ownerToken: { title, results: [{ id, manifestUrl, durationSec, startedAt }] } */
|
|
1320
|
+
fun getWebinarRecordingsAsOwner(
|
|
1321
|
+
conversationId: String,
|
|
1322
|
+
callback: ApiCallback? = null,
|
|
1323
|
+
) = owner("GET", "/chats/conversations/${enc(conversationId)}/webinar/recordings", null, null, callback)
|
|
1324
|
+
|
|
1325
|
+
/** memberToken: { chatLinkId, memberId, followers, following, isFollowing, followsYou, canFollow } */
|
|
1326
|
+
fun getMemberFollowStatus(
|
|
1327
|
+
linkId: String,
|
|
1328
|
+
memberId: String,
|
|
1329
|
+
callback: ApiCallback? = null,
|
|
1330
|
+
) = member("GET", "/chat-users/links/${enc(linkId)}/members/${enc(memberId)}/follow", null, null, callback)
|
|
1331
|
+
|
|
1332
|
+
/** memberToken; same shape as getMemberFollowStatus */
|
|
1333
|
+
fun followMember(
|
|
1334
|
+
linkId: String,
|
|
1335
|
+
memberId: String,
|
|
1336
|
+
callback: ApiCallback? = null,
|
|
1337
|
+
) = member("POST", "/chat-users/links/${enc(linkId)}/members/${enc(memberId)}/follow", null, null, callback)
|
|
1338
|
+
|
|
1339
|
+
/** memberToken; same shape as getMemberFollowStatus */
|
|
1340
|
+
fun unfollowMember(
|
|
1341
|
+
linkId: String,
|
|
1342
|
+
memberId: String,
|
|
1343
|
+
callback: ApiCallback? = null,
|
|
1344
|
+
) = member("DELETE", "/chat-users/links/${enc(linkId)}/members/${enc(memberId)}/follow", null, null, callback)
|
|
1345
|
+
|
|
1346
|
+
/** memberToken; the ?guest= pass from a meeting invite: { conversationId, conversationCode } */
|
|
1347
|
+
fun redeemMeetingGuestPass(
|
|
1348
|
+
code: String,
|
|
1349
|
+
token: String,
|
|
1350
|
+
callback: ApiCallback? = null,
|
|
1351
|
+
) = member("POST", "/hops/meetings/guest-pass", JSONObject().put("code", code).put("token", token), null, callback)
|
|
1352
|
+
|
|
1353
|
+
/** memberToken; plain /hop/{code} meeting link, host admits from the lobby: { conversationId, conversationCode } */
|
|
1354
|
+
fun joinMeetingByLink(
|
|
1355
|
+
code: String,
|
|
1356
|
+
callback: ApiCallback? = null,
|
|
1357
|
+
) = member("POST", "/hops/meetings/join-by-link", JSONObject().put("code", code), null, callback)
|
|
1358
|
+
|
|
1359
|
+
/** memberToken; Join on a HOP_MEETING card: { conversationId, conversationCode } */
|
|
1360
|
+
fun joinMeetingFromChannel(
|
|
1361
|
+
meetingConversationId: String,
|
|
1362
|
+
callback: ApiCallback? = null,
|
|
1363
|
+
) = member("POST", "/hops/meetings/${enc(meetingConversationId)}/join-from-channel", null, null, callback)
|
|
1364
|
+
|
|
1365
|
+
/** memberToken; calendars the workspace offers and yours: { enabled, providers: [{ id, label }], connections: [{ provider, label, status: active|needs_reauth, accountHint, connectedAt, lastSyncAt, lastError, shareBusy, realtime }] } */
|
|
1366
|
+
fun getCalendarSyncStatus(
|
|
1367
|
+
callback: ApiCallback? = null,
|
|
1368
|
+
) = member("GET", "/calendar-sync/status", null, null, callback)
|
|
1369
|
+
|
|
1370
|
+
/** memberToken; provider google | microsoft; open the returned { authUrl }; native = true from an app (system browser, one-time code back) */
|
|
1371
|
+
fun connectCalendar(
|
|
1372
|
+
provider: String,
|
|
1373
|
+
returnTo: String? = null,
|
|
1374
|
+
native: Boolean? = null,
|
|
1375
|
+
callback: ApiCallback? = null,
|
|
1376
|
+
) = member(
|
|
1377
|
+
"POST", "/calendar-sync/${enc(provider)}/connect",
|
|
1378
|
+
JSONObject().also { b -> returnTo?.let { b.put("returnTo", it) }; native?.let { b.put("native", it) } }, null, callback, retry = false,
|
|
1379
|
+
)
|
|
1380
|
+
|
|
1381
|
+
/** memberToken; apps redeem the one-time code from livechatta://calendar-sync/done?code=: { ok }; 400 CALENDAR_ACCOUNT_MISMATCH | CALENDAR_SIGNIN_EXPIRED */
|
|
1382
|
+
fun completeNativeCalendarConnect(
|
|
1383
|
+
code: String,
|
|
1384
|
+
callback: ApiCallback? = null,
|
|
1385
|
+
) = member("POST", "/calendar-sync/native/complete", JSONObject().put("code", code), null, callback, retry = false)
|
|
1386
|
+
|
|
1387
|
+
/** memberToken; disconnect and take upcoming synced events off that calendar: { ok } */
|
|
1388
|
+
fun disconnectCalendar(
|
|
1389
|
+
provider: String,
|
|
1390
|
+
callback: ApiCallback? = null,
|
|
1391
|
+
) = member("DELETE", "/calendar-sync/${enc(provider)}", null, null, callback)
|
|
1392
|
+
|
|
1393
|
+
/** memberToken; show your busy times (never titles) to members who share a conversation with you: { ok } */
|
|
1394
|
+
fun setCalendarShareBusy(
|
|
1395
|
+
provider: String,
|
|
1396
|
+
shareBusy: Boolean,
|
|
1397
|
+
callback: ApiCallback? = null,
|
|
1398
|
+
) = member("PATCH", "/calendar-sync/${enc(provider)}/settings", JSONObject().put("shareBusy", shareBusy), null, callback)
|
|
1399
|
+
|
|
1400
|
+
/** memberToken; sync your active calendars now (429 after 4 a minute): { queued } */
|
|
1401
|
+
fun syncCalendarNow(
|
|
1402
|
+
callback: ApiCallback? = null,
|
|
1403
|
+
) = member("POST", "/calendar-sync/sync", null, null, callback, retry = false)
|
|
1404
|
+
|
|
1405
|
+
/** memberToken; busy blocks of up to 20 members who share a conversation with you (window at most 14 days): { members: [{ userId, connected, busy: [{ start, end }] }] } */
|
|
1406
|
+
fun getCalendarBusy(
|
|
1407
|
+
userIds: List<String>,
|
|
1408
|
+
from: String,
|
|
1409
|
+
to: String,
|
|
1410
|
+
callback: ApiCallback? = null,
|
|
1411
|
+
) = member("GET", "/calendar-sync/busy", null, mapOf("userIds" to userIds.joinToString(","), "from" to from, "to" to to), callback)
|
|
1412
|
+
|
|
1413
|
+
/** Member or owner token; mentions and reactions, newest first; query: prevCursor?, nextCursor?, limit? */
|
|
1414
|
+
fun listActivity(
|
|
1415
|
+
query: Map<String, String>? = null,
|
|
1416
|
+
callback: ApiCallback? = null,
|
|
1417
|
+
) = userRoute("GET", "/notifications/activity", null, query, callback)
|
|
1418
|
+
|
|
1419
|
+
/** Member or owner token: { count } */
|
|
1420
|
+
fun getActivityUnreadCount(
|
|
1421
|
+
callback: ApiCallback? = null,
|
|
1422
|
+
) = userRoute("GET", "/notifications/activity/unread-count", null, null, callback)
|
|
1423
|
+
|
|
1424
|
+
/** Member or owner token: { success } */
|
|
1425
|
+
fun markAllActivityRead(
|
|
1426
|
+
callback: ApiCallback? = null,
|
|
1427
|
+
) = userRoute("PATCH", "/notifications/activity/read-all", null, null, callback)
|
|
1428
|
+
|
|
1429
|
+
/** Member or owner token; GIF settings: { enabled, providers, rating, providerLabel } (enabled=false when GIF search is off; the other GIF routes answer 404) */
|
|
1430
|
+
fun getGifConfig(
|
|
1431
|
+
callback: ApiCallback? = null,
|
|
1432
|
+
) = userRoute("GET", "/chats/gifs/config", null, null, callback)
|
|
1433
|
+
|
|
1434
|
+
/** Member or owner token; search GIFs (q up to 60 characters, empty = trending): { results: [GifItem], nextCursor, hasMore, source: provider|default, fallback, hasProviders, providerLabel, switched }. source=livechatta pins the LiveChatta pack (100+ GIFs); a pack search with no match hands over to the provider with switched=true. The pack also answers when no provider is set or it fails. */
|
|
1435
|
+
fun searchGifs(
|
|
1436
|
+
q: String? = null,
|
|
1437
|
+
nextCursor: String? = null,
|
|
1438
|
+
source: String? = null,
|
|
1439
|
+
callback: ApiCallback? = null,
|
|
1440
|
+
) = userRoute("GET", "/chats/gifs/search", null, listOfNotNull(q?.takeIf { it.isNotEmpty() }?.let { "q" to it }, nextCursor?.takeIf { it.isNotEmpty() }?.let { "nextCursor" to it }, source?.takeIf { it.isNotEmpty() }?.let { "source" to it }).toMap().ifEmpty { null }, callback)
|
|
1441
|
+
|
|
1442
|
+
/** Member or owner token; trending GIFs (the default pack when no provider is set), same page shape as searchGifs */
|
|
1443
|
+
fun trendingGifs(
|
|
1444
|
+
nextCursor: String? = null,
|
|
1445
|
+
source: String? = null,
|
|
1446
|
+
callback: ApiCallback? = null,
|
|
1447
|
+
) = userRoute("GET", "/chats/gifs/trending", null, listOfNotNull(nextCursor?.takeIf { it.isNotEmpty() }?.let { "nextCursor" to it }, source?.takeIf { it.isNotEmpty() }?.let { "source" to it }).toMap().ifEmpty { null }, callback)
|
|
1448
|
+
|
|
1449
|
+
/** Member or owner token; tell the provider a GIF was sent (once a day per member and GIF): { ok, counted } */
|
|
1450
|
+
fun registerGifShare(
|
|
1451
|
+
provider: String,
|
|
1452
|
+
id: String,
|
|
1453
|
+
q: String? = null,
|
|
1454
|
+
callback: ApiCallback? = null,
|
|
1455
|
+
) = userRoute("POST", "/chats/gifs/share", JSONObject().put("provider", provider).put("id", id).also { b -> q?.let { b.put("q", it) } }, null, callback, retry = false)
|
|
1456
|
+
|
|
1457
|
+
/** Member or owner token; report a GIF (reason: sexual|violent|hateful|spam|other; note up to 300 characters): { ok } */
|
|
1458
|
+
fun reportGif(
|
|
1459
|
+
provider: String,
|
|
1460
|
+
id: String,
|
|
1461
|
+
reason: String,
|
|
1462
|
+
note: String? = null,
|
|
1463
|
+
messageId: String? = null,
|
|
1464
|
+
callback: ApiCallback? = null,
|
|
1465
|
+
) = userRoute("POST", "/chats/gifs/report", JSONObject().put("provider", provider).put("id", id).put("reason", reason).also { b -> note?.let { b.put("note", it) }; messageId?.let { b.put("messageId", it) } }, null, callback, retry = false)
|
|
1466
|
+
|
|
1467
|
+
/** Member token; invite another workspace to a channel (owner or team admin). No partnerLinkCode = single-use link, token in the response once: { sharedChannel, inviteToken?, inviteUrl? } */
|
|
1468
|
+
fun inviteSharedChannel(
|
|
1469
|
+
chatLinkId: String,
|
|
1470
|
+
conversationId: String,
|
|
1471
|
+
partnerLinkCode: String? = null,
|
|
1472
|
+
expiresInHours: Int? = null,
|
|
1473
|
+
callback: ApiCallback? = null,
|
|
1474
|
+
) = member("POST", "/shared-channels", JSONObject().put("chatLinkId", chatLinkId).put("conversationId", conversationId).also { b -> partnerLinkCode?.let { b.put("partnerLinkCode", it) }; expiresInHours?.let { b.put("expiresInHours", it) } }, null, callback, retry = false)
|
|
1475
|
+
|
|
1476
|
+
/** Member token; shares of your workspace, live and ended in the last 30 days: { results: [SharedChannelView], nextCursor } */
|
|
1477
|
+
fun listSharedChannels(
|
|
1478
|
+
chatLinkId: String,
|
|
1479
|
+
nextCursor: String? = null,
|
|
1480
|
+
callback: ApiCallback? = null,
|
|
1481
|
+
) = member("GET", "/shared-channels", null, listOfNotNull("chatLinkId" to chatLinkId, nextCursor?.takeIf { it.isNotEmpty() }?.let { "nextCursor" to it }).toMap(), callback)
|
|
1482
|
+
|
|
1483
|
+
/** Member token; look at an invite link before accepting (owner or team admin; does not use it up): { hostName, channelName, invitedByName, expiresAt } */
|
|
1484
|
+
fun previewSharedChannelInvite(
|
|
1485
|
+
token: String,
|
|
1486
|
+
callback: ApiCallback? = null,
|
|
1487
|
+
) = member("POST", "/shared-channels/preview", JSONObject().put("token", token), null, callback, retry = false)
|
|
1488
|
+
|
|
1489
|
+
/** Member token; people of your workspace to pick for a PICKED audience (name and handle only): { results, nextCursor } */
|
|
1490
|
+
fun listSharedChannelMembers(
|
|
1491
|
+
chatLinkId: String,
|
|
1492
|
+
q: String? = null,
|
|
1493
|
+
sharedChannelId: String? = null,
|
|
1494
|
+
nextCursor: String? = null,
|
|
1495
|
+
callback: ApiCallback? = null,
|
|
1496
|
+
) = member("GET", "/shared-channels/members", null, listOfNotNull("chatLinkId" to chatLinkId, q?.takeIf { it.isNotEmpty() }?.let { "q" to it }, sharedChannelId?.takeIf { it.isNotEmpty() }?.let { "sharedChannelId" to it }, nextCursor?.takeIf { it.isNotEmpty() }?.let { "nextCursor" to it }).toMap(), callback)
|
|
1497
|
+
|
|
1498
|
+
/** Member token; the shares of one of your channels (channel admin or workspace admin). The server sends a list, so it arrives as { results: [SharedChannelView] } */
|
|
1499
|
+
fun getConversationSharedChannels(
|
|
1500
|
+
conversationId: String,
|
|
1501
|
+
chatLinkId: String,
|
|
1502
|
+
callback: ApiCallback? = null,
|
|
1503
|
+
) = member("GET", "/shared-channels/conversations/${enc(conversationId)}", null, mapOf("chatLinkId" to chatLinkId), callback)
|
|
1504
|
+
|
|
1505
|
+
/** Member token; what your workspace may do here: { side (null when not shared with you), canRemoveMessages, canRemoveMembers, externalIds } */
|
|
1506
|
+
fun getSharedChannelPermissions(
|
|
1507
|
+
conversationId: String,
|
|
1508
|
+
chatLinkId: String,
|
|
1509
|
+
callback: ApiCallback? = null,
|
|
1510
|
+
) = member("GET", "/shared-channels/conversations/${enc(conversationId)}/permissions", null, mapOf("chatLinkId" to chatLinkId), callback)
|
|
1511
|
+
|
|
1512
|
+
/** Member token; accept an invite sent to your link code (partner owner or team admin; audience ALL or PICKED with memberIds): SharedChannelView */
|
|
1513
|
+
fun acceptSharedChannel(
|
|
1514
|
+
sharedChannelId: String,
|
|
1515
|
+
chatLinkId: String,
|
|
1516
|
+
audience: String,
|
|
1517
|
+
memberIds: List<String>? = null,
|
|
1518
|
+
callback: ApiCallback? = null,
|
|
1519
|
+
) = member("POST", "/shared-channels/${enc(sharedChannelId)}/accept", acceptBody(chatLinkId, audience, memberIds), null, callback, retry = false)
|
|
1520
|
+
|
|
1521
|
+
/** Member token; accept a single-use invite link with its token (works once): SharedChannelView */
|
|
1522
|
+
fun acceptSharedChannelByToken(
|
|
1523
|
+
token: String,
|
|
1524
|
+
chatLinkId: String,
|
|
1525
|
+
audience: String,
|
|
1526
|
+
memberIds: List<String>? = null,
|
|
1527
|
+
callback: ApiCallback? = null,
|
|
1528
|
+
) = member("POST", "/shared-channels/accept-token", acceptBody(chatLinkId, audience, memberIds).put("token", token), null, callback, retry = false)
|
|
1529
|
+
|
|
1530
|
+
/** Member token; host removes the partner, partner leaves, or either side cancels or declines a pending invite: SharedChannelView */
|
|
1531
|
+
fun endSharedChannel(
|
|
1532
|
+
sharedChannelId: String,
|
|
1533
|
+
chatLinkId: String,
|
|
1534
|
+
callback: ApiCallback? = null,
|
|
1535
|
+
) = member("POST", "/shared-channels/${enc(sharedChannelId)}/end", JSONObject().put("chatLinkId", chatLinkId), null, callback, retry = false)
|
|
1536
|
+
|
|
1537
|
+
/** Member token; partner owner or team admin changes who has the channel (same body as accepting): SharedChannelView */
|
|
1538
|
+
fun updateSharedChannelMembers(
|
|
1539
|
+
sharedChannelId: String,
|
|
1540
|
+
chatLinkId: String,
|
|
1541
|
+
audience: String,
|
|
1542
|
+
memberIds: List<String>? = null,
|
|
1543
|
+
callback: ApiCallback? = null,
|
|
1544
|
+
) = member("PUT", "/shared-channels/${enc(sharedChannelId)}/members", acceptBody(chatLinkId, audience, memberIds), null, callback, retry = false)
|
|
1545
|
+
|
|
1546
|
+
/** Member token; your workspace's activity log for one share: { results: [{ _id, action, actorName, detail, createdAt }], nextCursor } */
|
|
1547
|
+
fun getSharedChannelAudit(
|
|
1548
|
+
sharedChannelId: String,
|
|
1549
|
+
chatLinkId: String,
|
|
1550
|
+
nextCursor: String? = null,
|
|
1551
|
+
callback: ApiCallback? = null,
|
|
1552
|
+
) = member("GET", "/shared-channels/${enc(sharedChannelId)}/audit", null, listOfNotNull("chatLinkId" to chatLinkId, nextCursor?.takeIf { it.isNotEmpty() }?.let { "nextCursor" to it }).toMap(), callback)
|
|
1553
|
+
|
|
1554
|
+
/** Member token; message a person of a partner workspace (allowSharedDms on both links, an active shared channel you are both in): { conversationId, created } or { internal: true } */
|
|
1555
|
+
fun openSharedDirect(
|
|
1556
|
+
chatLinkId: String,
|
|
1557
|
+
conversationId: String,
|
|
1558
|
+
memberId: String,
|
|
1559
|
+
callback: ApiCallback? = null,
|
|
1560
|
+
) = member("POST", "/shared-channels/direct", JSONObject().put("chatLinkId", chatLinkId).put("conversationId", conversationId).put("memberId", memberId), null, callback, retry = false)
|
|
1561
|
+
|
|
1562
|
+
/** Member token; host only: remove one partner member (they stay out if the channel is shared again): SharedChannelView */
|
|
1563
|
+
fun removeSharedChannelMember(
|
|
1564
|
+
chatLinkId: String,
|
|
1565
|
+
conversationId: String,
|
|
1566
|
+
memberId: String,
|
|
1567
|
+
callback: ApiCallback? = null,
|
|
1568
|
+
) = member("POST", "/shared-channels/remove-member", JSONObject().put("chatLinkId", chatLinkId).put("conversationId", conversationId).put("memberId", memberId), null, callback, retry = false)
|
|
1569
|
+
|
|
1570
|
+
/** Member token; wipe a message for everyone (workspace owners and admins; partner staff only for their own people): { messageId } */
|
|
1571
|
+
fun removeSharedChannelMessage(
|
|
1572
|
+
chatLinkId: String,
|
|
1573
|
+
conversationId: String,
|
|
1574
|
+
messageId: String,
|
|
1575
|
+
callback: ApiCallback? = null,
|
|
1576
|
+
) = member("POST", "/shared-channels/remove-message", JSONObject().put("chatLinkId", chatLinkId).put("conversationId", conversationId).put("messageId", messageId), null, callback, retry = false)
|
|
1577
|
+
|
|
1578
|
+
/** Owner token; bind a verified teammate to the chat user that is theirs (they then count as staff for shared channels): { linked: true } */
|
|
1579
|
+
fun linkChatUserToAccount(
|
|
1580
|
+
accountId: String,
|
|
1581
|
+
chatUserId: String,
|
|
1582
|
+
callback: ApiCallback? = null,
|
|
1583
|
+
) = ownerNoRetry("POST", "/chats/chat-users/link-account", JSONObject().put("accountId", accountId).put("chatUserId", chatUserId), callback)
|
|
1584
|
+
|
|
1585
|
+
private fun acceptBody(chatLinkId: String, audience: String, memberIds: List<String>?): JSONObject =
|
|
1586
|
+
JSONObject().put("chatLinkId", chatLinkId).put("audience", audience).also { b -> memberIds?.let { b.put("memberIds", JSONArray(it)) } }
|
|
1587
|
+
|
|
1588
|
+
/** Member or owner token; your own sidebar category names (one link when chatLinkId is set): { categories } */
|
|
1589
|
+
fun getSidebarCategories(
|
|
1590
|
+
chatLinkId: String? = null,
|
|
1591
|
+
callback: ApiCallback? = null,
|
|
1592
|
+
) = userRoute("GET", "/chats/categories", null, chatLinkId?.let { mapOf("chatLinkId" to it) }, callback)
|
|
1593
|
+
|
|
1594
|
+
/** Member or owner token; category ≤ 40 characters, empty removes it: { conversationId, category, categories } */
|
|
1595
|
+
fun setConversationCategory(
|
|
1596
|
+
conversationId: String,
|
|
1597
|
+
category: String,
|
|
1598
|
+
callback: ApiCallback? = null,
|
|
1599
|
+
) = userRoute("PUT", "/chats/conversations/${enc(conversationId)}/category", JSONObject().put("category", category), null, callback)
|
|
1600
|
+
|
|
1601
|
+
/** Member or owner token; rename one of your categories (400 when missing or the new name is used): { categories } */
|
|
1602
|
+
fun renameSidebarCategory(
|
|
1603
|
+
from: String,
|
|
1604
|
+
to: String,
|
|
1605
|
+
chatLinkId: String? = null,
|
|
1606
|
+
callback: ApiCallback? = null,
|
|
1607
|
+
) = userRoute("PATCH", "/chats/categories", JSONObject().put("from", from).put("to", to).also { b -> chatLinkId?.let { b.put("chatLinkId", it) } }, null, callback)
|
|
1608
|
+
|
|
1609
|
+
/** Member or owner token; delete a category, its conversations return to Channels, Groups and People: { categories } */
|
|
1610
|
+
fun deleteSidebarCategory(
|
|
1611
|
+
name: String,
|
|
1612
|
+
chatLinkId: String? = null,
|
|
1613
|
+
callback: ApiCallback? = null,
|
|
1614
|
+
) = userRoute("DELETE", "/chats/categories", null, listOfNotNull("name" to name, chatLinkId?.let { "chatLinkId" to it }).toMap(), callback)
|
|
1615
|
+
|
|
1616
|
+
/** Member or owner token: [{ id, key, name, emoji, description, priceMinor, currency }] (no fee fields since chatta #416) */
|
|
1617
|
+
fun getGiftCatalog(
|
|
1618
|
+
callback: ApiCallback? = null,
|
|
1619
|
+
) = userRoute("GET", "/gifts/catalog", null, null, callback)
|
|
1620
|
+
|
|
1621
|
+
/** memberToken; body: { conversationId, recipientId, giftKey, note? }: { authorizationUrl, reference, … } */
|
|
1622
|
+
fun sendPeerGift(
|
|
1623
|
+
payload: JSONObject,
|
|
1624
|
+
callback: ApiCallback? = null,
|
|
1625
|
+
) = member("POST", "/gifts/peer", payload, null, callback, retry = false)
|
|
1626
|
+
|
|
1627
|
+
/** memberToken; query: nextCursor?, prevCursor?, limit?: { balance, openPayout, results (amountMinor, netMinor; no feeMinor), nextCursor, … } */
|
|
1628
|
+
fun listReceivedGifts(
|
|
1629
|
+
query: Map<String, String>? = null,
|
|
1630
|
+
callback: ApiCallback? = null,
|
|
1631
|
+
) = member("GET", "/gifts/received", null, query, callback)
|
|
1632
|
+
|
|
1633
|
+
/** memberToken: { currency, availableMinor, pendingPayoutMinor, lifetimeMinor } */
|
|
1634
|
+
fun getGiftBalance(
|
|
1635
|
+
callback: ApiCallback? = null,
|
|
1636
|
+
) = member("GET", "/gifts/balance", null, null, callback)
|
|
1637
|
+
|
|
1638
|
+
/** memberToken; pay out the available balance (min 1000): { payout, balance } */
|
|
1639
|
+
fun requestGiftPayout(
|
|
1640
|
+
callback: ApiCallback? = null,
|
|
1641
|
+
) = member("POST", "/gifts/payouts", null, null, callback, retry = false)
|
|
1642
|
+
|
|
1643
|
+
/** ownerToken; body: { mode, applyDefaults? }: { linkId, mode, linkType, joinPolicy, created } */
|
|
1644
|
+
fun setLinkMode(
|
|
1645
|
+
linkId: String,
|
|
1646
|
+
payload: JSONObject,
|
|
1647
|
+
callback: ApiCallback? = null,
|
|
1648
|
+
) = owner("PATCH", "/chats/links/${enc(linkId)}/mode", payload, null, callback)
|
|
1649
|
+
|
|
1650
|
+
/** Conversation admin or owner; mode: standard|broadcast|announcement|qa|voice|support. Returns permissions + mode */
|
|
1651
|
+
fun setConversationMode(
|
|
1652
|
+
conversationId: String,
|
|
1653
|
+
mode: String,
|
|
1654
|
+
callback: ApiCallback? = null,
|
|
1655
|
+
) = userRoute("PATCH", "/chats/conversations/${enc(conversationId)}/mode", JSONObject().put("mode", mode), null, callback)
|
|
1656
|
+
|
|
1657
|
+
/** Public link card: { _id, code, name, mode?, joinPolicy: { guests, emailRequired, signInRequired, inviteOnly, approval }, settings (display only) } */
|
|
1658
|
+
fun getPublicLinkInfo(
|
|
1659
|
+
linkCode: String,
|
|
1660
|
+
callback: ApiCallback? = null,
|
|
1661
|
+
) = request("GET", "/in/${enc(linkCode)}", null, null, callback, Base.ROOT, Auth.NONE)
|
|
1662
|
+
|
|
1663
|
+
/** API key; query: nextCursor?, prevCursor?, limit?, handles? (comma-separated lanes, default admin), q? (search, ≤ 80 chars) */
|
|
1664
|
+
fun getAdminMentions(
|
|
1665
|
+
query: Map<String, String>? = null,
|
|
1666
|
+
callback: ApiCallback? = null,
|
|
1667
|
+
) = get("/chats/messages/admin-mentions", query, callback)
|
|
1668
|
+
|
|
1669
|
+
/** ownerToken; query adds handles (comma-separated lanes, unknown = 400) and q (search, ≤ 80 chars) */
|
|
1670
|
+
fun getAdminMentionsAsOwner(
|
|
1671
|
+
query: Map<String, String>? = null,
|
|
1672
|
+
callback: ApiCallback? = null,
|
|
1673
|
+
) = owner("GET", "/chats/messages/admin-mentions", null, query, callback)
|
|
1674
|
+
|
|
1675
|
+
/** ownerToken; console link create (POST chats/links) honouring modeOptions: link + modeResult { applied, warning? } */
|
|
1676
|
+
fun createAccountChatLink(
|
|
1677
|
+
payload: JSONObject,
|
|
1678
|
+
callback: ApiCallback? = null,
|
|
1679
|
+
) = ownerNoRetry("POST", "/chats/links", payload, callback)
|
|
1680
|
+
|
|
1681
|
+
/** Public join-card preview: { members, online, channels: [{ name, type, mode, category, members, live }] } */
|
|
1682
|
+
fun getLinkChannels(
|
|
1683
|
+
linkCode: String,
|
|
1684
|
+
callback: ApiCallback? = null,
|
|
1685
|
+
) = request("GET", "/in/${enc(linkCode)}/channels", null, null, callback, Base.ROOT, Auth.NONE)
|
|
1686
|
+
|
|
1687
|
+
/** Public gift store: { giftPlans, features, currentPlanId } (public plans only) */
|
|
1688
|
+
fun getGiftStoreData(
|
|
1689
|
+
linkCode: String,
|
|
1690
|
+
callback: ApiCallback? = null,
|
|
1691
|
+
) = request("GET", "/in/${enc(linkCode)}/gift-store-data", null, null, callback, Base.ROOT, Auth.NONE)
|
|
1692
|
+
|
|
1693
|
+
/** ownerToken (business console); body: any of { guests, emailRequired, signInRequired, approval }: the resolved JoinPolicy */
|
|
1694
|
+
fun setLinkJoinPolicy(
|
|
1695
|
+
linkId: String,
|
|
1696
|
+
payload: JSONObject,
|
|
1697
|
+
callback: ApiCallback? = null,
|
|
1698
|
+
) = owner("PATCH", "/chats/links/${enc(linkId)}/join-policy", payload, null, callback)
|
|
1699
|
+
|
|
1700
|
+
/** Public Ask to join (5/min): { status: pending|approved|member }; 403 APPROVAL_OFF when off */
|
|
1701
|
+
fun requestToJoinLink(
|
|
1702
|
+
linkCode: String,
|
|
1703
|
+
name: String,
|
|
1704
|
+
email: String,
|
|
1705
|
+
message: String? = null,
|
|
1706
|
+
callback: ApiCallback? = null,
|
|
1707
|
+
) = request(
|
|
1708
|
+
"POST", "/in/${enc(linkCode)}/join-request",
|
|
1709
|
+
JSONObject().put("name", name).put("email", email).apply { if (message != null) put("message", message) },
|
|
1710
|
+
null, callback, Base.ROOT, Auth.NONE, retry = false,
|
|
1711
|
+
)
|
|
1712
|
+
|
|
1713
|
+
/** ownerToken; query: status? (pending|approved|denied), nextCursor?, limit? (1–20): { results, nextCursor, hasMore, pending } */
|
|
1714
|
+
fun listJoinRequests(
|
|
1715
|
+
linkId: String,
|
|
1716
|
+
query: Map<String, String>? = null,
|
|
1717
|
+
callback: ApiCallback? = null,
|
|
1718
|
+
) = owner("GET", "/chats/links/${enc(linkId)}/join-requests", null, query, callback)
|
|
1719
|
+
|
|
1720
|
+
/** ownerToken; the updated request (the requester is emailed) */
|
|
1721
|
+
fun approveJoinRequest(
|
|
1722
|
+
linkId: String,
|
|
1723
|
+
requestId: String,
|
|
1724
|
+
callback: ApiCallback? = null,
|
|
1725
|
+
) = ownerNoRetry("POST", "/chats/links/${enc(linkId)}/join-requests/${enc(requestId)}/approve", null, callback)
|
|
1726
|
+
|
|
1727
|
+
/** ownerToken; the updated request (the requester is emailed) */
|
|
1728
|
+
fun denyJoinRequest(
|
|
1729
|
+
linkId: String,
|
|
1730
|
+
requestId: String,
|
|
1731
|
+
callback: ApiCallback? = null,
|
|
1732
|
+
) = ownerNoRetry("POST", "/chats/links/${enc(linkId)}/join-requests/${enc(requestId)}/deny", null, callback)
|
|
1733
|
+
|
|
1734
|
+
/** memberToken of a support-group admin: { conversationId, topicId, teamId, name, teams: [{ _id, name, memberCount }] } */
|
|
1735
|
+
fun getSupportGroupTeam(
|
|
1736
|
+
conversationId: String,
|
|
1737
|
+
callback: ApiCallback? = null,
|
|
1738
|
+
) = member("GET", "/chats/conversations/${enc(conversationId)}/support-team", null, null, callback)
|
|
1739
|
+
|
|
1740
|
+
/** memberToken; teamId null stops routing; same shape as getSupportGroupTeam */
|
|
1741
|
+
fun setSupportGroupTeam(
|
|
1742
|
+
conversationId: String,
|
|
1743
|
+
teamId: String?,
|
|
1744
|
+
callback: ApiCallback? = null,
|
|
1745
|
+
) = member("PATCH", "/chats/conversations/${enc(conversationId)}/support-team", JSONObject().put("teamId", teamId ?: JSONObject.NULL), null, callback)
|
|
1746
|
+
|
|
1747
|
+
/** ownerToken; websites allowed to frame the embed chat (≤ 20; empty = any site): { domains } */
|
|
1748
|
+
fun setLinkEmbedDomains(
|
|
1749
|
+
linkId: String,
|
|
1750
|
+
domains: List<String>,
|
|
1751
|
+
callback: ApiCallback? = null,
|
|
1752
|
+
) = owner("PUT", "/chats/links/${enc(linkId)}/embed-domains", JSONObject().put("domains", JSONArray(domains)), null, callback)
|
|
1753
|
+
|
|
1754
|
+
/** ownerToken; native app origins that may frame the app embed (≤ 10: capacitor://localhost, ionic://localhost, app://name, https://localhost; empty = none): { origins } */
|
|
1755
|
+
fun setLinkAppOrigins(
|
|
1756
|
+
linkId: String,
|
|
1757
|
+
origins: List<String>,
|
|
1758
|
+
callback: ApiCallback? = null,
|
|
1759
|
+
) = owner("PUT", "/chats/links/${enc(linkId)}/app-origins", JSONObject().put("origins", JSONArray(origins)), null, callback)
|
|
1760
|
+
|
|
1761
|
+
// ===================
|
|
1762
|
+
// PLANS + FEATURE STORE
|
|
1763
|
+
// ===================
|
|
1764
|
+
|
|
1765
|
+
/** Public (owner token sent when set): plans as { results: [...] }. CUSTOM plans only for their client */
|
|
1766
|
+
fun listPlans(callback: ApiCallback? = null) =
|
|
1767
|
+
request("GET", "/subscriptions/plans", null, null, callback, Base.API, if (ownerToken.isNullOrBlank()) Auth.NONE else Auth.OWNER)
|
|
1768
|
+
|
|
1769
|
+
/** Public (owner token sent when set); 404 PLAN_NOT_FOUND_MESSAGE for plans you may not see */
|
|
1770
|
+
fun getPlan(planId: String, callback: ApiCallback? = null) =
|
|
1771
|
+
request("GET", "/subscriptions/plans/${enc(planId)}", null, null, callback, Base.API, if (ownerToken.isNullOrBlank()) Auth.NONE else Auth.OWNER)
|
|
1772
|
+
|
|
1773
|
+
/** ownerToken; billingCycle: MONTHLY|QUARTERLY|SEMI_YEARLY|YEARLY; paymentMethod: card (default) | bank_transfer: { authorizationUrl, reference, accessCode, paymentMethod } */
|
|
1774
|
+
fun subscribeToPlan(planId: String, billingCycle: String, paymentMethod: String? = null, callback: ApiCallback? = null) =
|
|
1775
|
+
ownerNoRetry(
|
|
1776
|
+
"POST", "/subscriptions/subscribe",
|
|
1777
|
+
JSONObject().put("planId", planId).put("billingCycle", billingCycle).apply { if (paymentMethod != null) put("paymentMethod", paymentMethod) },
|
|
1778
|
+
callback,
|
|
1779
|
+
)
|
|
1780
|
+
|
|
1781
|
+
/** ownerToken: { eligible, trial: null | { subscriptionId, planName, status, endsAt, daysLeft, hasCard, amountUsd } } */
|
|
1782
|
+
fun getTrialStatus(callback: ApiCallback? = null) = owner("GET", "/subscriptions/trial", null, null, callback)
|
|
1783
|
+
|
|
1784
|
+
/** ownerToken; plan with trialDays > 0, one per account: { subscriptionId, planName, trialEndsAt, days } */
|
|
1785
|
+
fun startTrial(planId: String, billingCycle: String? = null, callback: ApiCallback? = null) =
|
|
1786
|
+
ownerNoRetry("POST", "/subscriptions/trial", JSONObject().put("planId", planId).apply { if (billingCycle != null) put("billingCycle", billingCycle) }, callback)
|
|
1787
|
+
|
|
1788
|
+
/** ownerToken: { renewal: null | { state: current|due-soon|due|grace|lapsed, subscriptionId, periodEnd, graceEndsAt, daysLeft, amountUsd } } */
|
|
1789
|
+
fun getRenewalStatus(callback: ApiCallback? = null) = owner("GET", "/subscriptions/renewal", null, null, callback)
|
|
1790
|
+
|
|
1791
|
+
/** ownerToken; paymentMethod bank_transfer (default) | card: { authorizationUrl, reference, paymentMethod }; verify with verifySubscription */
|
|
1792
|
+
fun renewSubscription(subscriptionId: String, paymentMethod: String? = null, callback: ApiCallback? = null) =
|
|
1793
|
+
ownerNoRetry("POST", "/subscriptions/${enc(subscriptionId)}/renew", JSONObject().apply { if (paymentMethod != null) put("paymentMethod", paymentMethod) }, callback)
|
|
1794
|
+
|
|
1795
|
+
/** ownerToken; stop auto-charging the card, every active plan renews by transfer: { paymentChannel } */
|
|
1796
|
+
fun useBankTransferRenewals(callback: ApiCallback? = null) =
|
|
1797
|
+
ownerNoRetry("POST", "/subscriptions/payment-method/bank-transfer", null, callback)
|
|
1798
|
+
|
|
1799
|
+
/** Member or owner token: { monthBytes, totalBytes, capGB (0 unlimited, -1 none), planGB, addonGB, pct, remainingBytes, state, periodStart, resetsAt } */
|
|
1800
|
+
fun getStorageUsage(callback: ApiCallback? = null) = userRoute("GET", "/subscriptions/storage", null, null, callback)
|
|
1801
|
+
|
|
1802
|
+
/** ownerToken (owner or team admin); query: nextCursor?, prevCursor?, limit? (≤ 20): { results: [{ staffName, mode: view|act, reason, … }], … } */
|
|
1803
|
+
fun listStaffAccess(query: Map<String, String>? = null, callback: ApiCallback? = null) =
|
|
1804
|
+
owner("GET", "/staff-access", null, query, callback)
|
|
1805
|
+
|
|
1806
|
+
/** ownerToken; paid gifts in your links: { totals: { count, grossMinor, feeMinor, netMinor }, results: [{ platformFeeBps, feeMinor, netMinor, … }], … } */
|
|
1807
|
+
fun getOwnerGifts(query: Map<String, String>? = null, callback: ApiCallback? = null) =
|
|
1808
|
+
owner("GET", "/gifts/owner", null, query, callback)
|
|
1809
|
+
|
|
1810
|
+
/** Public, after checkout: the subscription, or { status: pending } for bank transfers */
|
|
1811
|
+
fun verifySubscription(reference: String, callback: ApiCallback? = null) =
|
|
1812
|
+
request("POST", "/subscriptions/verify", JSONObject().put("reference", reference), null, callback, Base.API, Auth.NONE, retry = false)
|
|
1813
|
+
|
|
1814
|
+
/** ownerToken: active subscriptions as { results: [...] } */
|
|
1815
|
+
fun listMySubscriptions(callback: ApiCallback? = null) = owner("GET", "/subscriptions/my-subscriptions", null, null, callback)
|
|
1816
|
+
|
|
1817
|
+
/** ownerToken; body: { planId, billingCycle, scheduleForPeriodEnd? }: checkout + credit/netAmount, or { scheduled, effectiveAt } */
|
|
1818
|
+
fun changePlan(subscriptionId: String, payload: JSONObject, callback: ApiCallback? = null) =
|
|
1819
|
+
ownerNoRetry("POST", "/subscriptions/${enc(subscriptionId)}/change-plan", payload, callback)
|
|
1820
|
+
|
|
1821
|
+
/** ownerToken */
|
|
1822
|
+
fun cancelSubscription(subscriptionId: String, callback: ApiCallback? = null) =
|
|
1823
|
+
owner("DELETE", "/subscriptions/${enc(subscriptionId)}", null, null, callback)
|
|
1824
|
+
|
|
1825
|
+
/** ownerToken; drops a scheduled downgrade */
|
|
1826
|
+
fun cancelScheduledPlanChange(subscriptionId: String, callback: ApiCallback? = null) =
|
|
1827
|
+
owner("DELETE", "/subscriptions/${enc(subscriptionId)}/scheduled-change", null, null, callback)
|
|
1828
|
+
|
|
1829
|
+
/** Member or owner token; pay for a plan for the workspace: { authorizationUrl, reference, accessCode } */
|
|
1830
|
+
fun giftPlan(planId: String, billingCycle: String, callback: ApiCallback? = null) =
|
|
1831
|
+
userRoute("POST", "/subscriptions/plan/gift", JSONObject().put("planId", planId).put("billingCycle", billingCycle), null, callback, retry = false)
|
|
1832
|
+
|
|
1833
|
+
/** Public, after a plan-gift checkout */
|
|
1834
|
+
fun verifyPlanGift(reference: String, callback: ApiCallback? = null) =
|
|
1835
|
+
request("POST", "/subscriptions/plan/gift/verify", JSONObject().put("reference", reference), null, callback, Base.API, Auth.NONE, retry = false)
|
|
1836
|
+
|
|
1837
|
+
/** Public; body: { contactName, contactEmail, company?, expectedChatLinks?, membersPerLink?, aiCredits?, features?, message?, source? } */
|
|
1838
|
+
fun requestCustomPlan(payload: JSONObject, callback: ApiCallback? = null) =
|
|
1839
|
+
request("POST", "/plan-requests", payload, null, callback, Base.API, Auth.NONE, retry = false)
|
|
1840
|
+
|
|
1841
|
+
/** ownerToken; same body, linked to your business: { id, status, createdAt, statusUpdatedAt } */
|
|
1842
|
+
fun requestCustomPlanAsOwner(payload: JSONObject, callback: ApiCallback? = null) =
|
|
1843
|
+
ownerNoRetry("POST", "/plan-requests/me", payload, callback)
|
|
1844
|
+
|
|
1845
|
+
/** ownerToken: { request: { id, status: NEW|CONTACTED|QUOTED|ASSIGNED|CLOSED, … } | null } */
|
|
1846
|
+
fun getMyLatestPlanRequest(callback: ApiCallback? = null) = owner("GET", "/plan-requests/me/latest", null, null, callback)
|
|
1847
|
+
|
|
1848
|
+
/** Public: add-ons and AI credit packs as { results: [{ _id, featureKey, name, pricePerDay, usageLimit, category }] } */
|
|
1849
|
+
fun listStoreFeatures(callback: ApiCallback? = null) =
|
|
1850
|
+
request("GET", "/subscriptions/features", null, null, callback, Base.API, Auth.NONE)
|
|
1851
|
+
|
|
1852
|
+
/** ownerToken; durationDays 1–365, needs an active plan: { authorizationUrl, reference, accessCode } */
|
|
1853
|
+
fun purchaseFeature(featurePricingId: String, durationDays: Int, callback: ApiCallback? = null) =
|
|
1854
|
+
ownerNoRetry("POST", "/subscriptions/features/purchase", JSONObject().put("featurePricingId", featurePricingId).put("durationDays", durationDays), callback)
|
|
1855
|
+
|
|
1856
|
+
/** Public, after a feature checkout */
|
|
1857
|
+
fun verifyFeaturePurchase(reference: String, callback: ApiCallback? = null) =
|
|
1858
|
+
request("POST", "/subscriptions/features/verify", JSONObject().put("reference", reference), null, callback, Base.API, Auth.NONE, retry = false)
|
|
1859
|
+
|
|
1860
|
+
/** Member or owner token: the workspace's purchases as { results: [...] } */
|
|
1861
|
+
fun listMyFeaturePurchases(callback: ApiCallback? = null) =
|
|
1862
|
+
userRoute("GET", "/subscriptions/features/my-purchases", null, null, callback)
|
|
1863
|
+
|
|
1864
|
+
/** Member or owner token; gift an add-on to the workspace: { authorizationUrl, reference, accessCode } */
|
|
1865
|
+
fun giftWorkspaceFeature(featurePricingId: String, durationDays: Int, callback: ApiCallback? = null) =
|
|
1866
|
+
userRoute("POST", "/subscriptions/features/gift", JSONObject().put("featurePricingId", featurePricingId).put("durationDays", durationDays), null, callback, retry = false)
|
|
1867
|
+
|
|
1868
|
+
/** Public, after a feature-gift checkout */
|
|
1869
|
+
fun verifyWorkspaceFeatureGift(reference: String, callback: ApiCallback? = null) =
|
|
1870
|
+
request("POST", "/subscriptions/features/gift/verify", JSONObject().put("reference", reference), null, callback, Base.API, Auth.NONE, retry = false)
|
|
1871
|
+
|
|
1872
|
+
/** Public; the replyToken from an inline-Reply chat push + the text: { sent, messageId, replyToken? } */
|
|
1873
|
+
fun sendPushReply(
|
|
1874
|
+
token: String,
|
|
1875
|
+
message: String,
|
|
1876
|
+
callback: ApiCallback? = null,
|
|
1877
|
+
) = request("POST", "/chats/push-reply", JSONObject().put("token", token).put("message", message), null, callback, Base.API, Auth.NONE, retry = false)
|
|
1878
|
+
|
|
1879
|
+
/** As above, plus [deviceHint] ("android-app") for `sentFrom`; the server checks it against the user agent. */
|
|
1880
|
+
fun sendPushReply(
|
|
1881
|
+
token: String,
|
|
1882
|
+
message: String,
|
|
1883
|
+
deviceHint: String,
|
|
1884
|
+
callback: ApiCallback? = null,
|
|
1885
|
+
) = request("POST", "/chats/push-reply", JSONObject().put("token", token).put("message", message).apply { if (deviceHint.isNotEmpty()) put("deviceHint", deviceHint) }, null, callback, Base.API, Auth.NONE, retry = false)
|
|
1886
|
+
|
|
1887
|
+
/** Public; email a registrant their Watch recording link: always { sent: true } */
|
|
1888
|
+
fun requestWebinarRecordingLink(
|
|
1889
|
+
conversationId: String,
|
|
1890
|
+
email: String,
|
|
1891
|
+
callback: ApiCallback? = null,
|
|
1892
|
+
) = request("POST", "/chats/conversations/${enc(conversationId)}/webinar/recording-link", JSONObject().put("email", email), null, callback, Base.API, Auth.NONE, retry = false)
|
|
1893
|
+
|
|
1894
|
+
/** Public; playback for the signed token from that email: { title, results }. Token goes in X-Recording-Token */
|
|
1895
|
+
fun getWebinarRecording(
|
|
1896
|
+
conversationId: String,
|
|
1897
|
+
token: String,
|
|
1898
|
+
callback: ApiCallback? = null,
|
|
1899
|
+
) = request(
|
|
1900
|
+
"GET", "/chats/conversations/${enc(conversationId)}/webinar/recording", null, null, callback, Base.API, Auth.NONE,
|
|
1901
|
+
headers = mapOf("X-Recording-Token" to token),
|
|
1902
|
+
)
|
|
1903
|
+
|
|
1904
|
+
/** Public, idempotent after checkout: { status: success|pending, reference, messageId? } */
|
|
1905
|
+
fun verifyPeerGift(
|
|
1906
|
+
reference: String,
|
|
1907
|
+
callback: ApiCallback? = null,
|
|
1908
|
+
) = request("POST", "/gifts/peer/verify", JSONObject().put("reference", reference), null, callback, Base.API, Auth.NONE)
|
|
1909
|
+
|
|
1910
|
+
/** Public webinar landing: { title, startAt, state, registeredCount, maxAttendees, isFull, hostName, joinPath, … } */
|
|
1911
|
+
fun getWebinarInfo(
|
|
1912
|
+
conversationId: String,
|
|
1913
|
+
callback: ApiCallback? = null,
|
|
1914
|
+
) = request("GET", "/chats/conversations/${enc(conversationId)}/webinar/info", null, null, callback, Base.API, Auth.NONE)
|
|
1915
|
+
|
|
1916
|
+
/** Public; body: { name, email, notes?, company?, wantsRecording?, waitlist? } */
|
|
1917
|
+
fun registerForWebinar(
|
|
1918
|
+
conversationId: String,
|
|
1919
|
+
payload: JSONObject,
|
|
1920
|
+
callback: ApiCallback? = null,
|
|
1921
|
+
) = request("POST", "/chats/conversations/${enc(conversationId)}/webinar/register", payload, null, callback, Base.API, Auth.NONE, retry = false)
|
|
1922
|
+
|
|
1923
|
+
// ===================
|
|
1924
|
+
// FORGOT / RESET PASSWORD (public; reset replies { status, message, audience, loginUrl, signedOut })
|
|
1925
|
+
// ===================
|
|
1926
|
+
|
|
1927
|
+
/** Business or admin account: same generic { status, message } whether or not it exists */
|
|
1928
|
+
fun requestBusinessPasswordReset(identifier: String, callback: ApiCallback? = null) =
|
|
1929
|
+
request("POST", "/users/forgot-password", JSONObject().put("identifier", identifier), null, callback, Base.API, Auth.NONE, retry = false)
|
|
1930
|
+
|
|
1931
|
+
/** Business / admin codes; newPassword 8–200 and equal to confirmPassword */
|
|
1932
|
+
fun resetBusinessPassword(token: String, newPassword: String, confirmPassword: String, callback: ApiCallback? = null) =
|
|
1933
|
+
request("POST", "/users/reset-password", resetBody(token, newPassword, confirmPassword), null, callback, Base.API, Auth.NONE, retry = false)
|
|
1934
|
+
|
|
1935
|
+
/** { state: valid|used|expired|invalid, audience?, purpose?: reset|set, linkCode?, email? (masked) } */
|
|
1936
|
+
fun getPasswordResetStatus(token: String, callback: ApiCallback? = null) =
|
|
1937
|
+
request("GET", "/users/reset-password/status", null, mapOf("token" to token), callback, Base.API, Auth.NONE)
|
|
1938
|
+
|
|
1939
|
+
/** Chat user of one chat space; chatLinkCode is required (nothing is sent without it) */
|
|
1940
|
+
fun requestChatPasswordReset(identifier: String, chatLinkCode: String, callback: ApiCallback? = null) =
|
|
1941
|
+
request("POST", "/chat-users/forgot-password", JSONObject().put("identifier", identifier).put("chatLinkCode", chatLinkCode), null, callback, Base.API, Auth.NONE, retry = false)
|
|
1942
|
+
|
|
1943
|
+
/** Chat codes only; signs out that chat user's sessions */
|
|
1944
|
+
fun resetChatPassword(token: String, newPassword: String, confirmPassword: String, callback: ApiCallback? = null) =
|
|
1945
|
+
request("POST", "/chat-users/reset-password", resetBody(token, newPassword, confirmPassword), null, callback, Base.API, Auth.NONE, retry = false)
|
|
1946
|
+
|
|
1947
|
+
/** The chat page's door (link from the path, 5/min) */
|
|
1948
|
+
fun requestLinkPasswordReset(linkCode: String, identifier: String, callback: ApiCallback? = null) =
|
|
1949
|
+
request("POST", "/in/${enc(linkCode)}/forgot-password", JSONObject().put("identifier", identifier), null, callback, Base.ROOT, Auth.NONE, retry = false)
|
|
1950
|
+
|
|
1951
|
+
/** Code must belong to a member of this link's owner */
|
|
1952
|
+
fun resetLinkPassword(linkCode: String, token: String, newPassword: String, confirmPassword: String, callback: ApiCallback? = null) =
|
|
1953
|
+
request("POST", "/in/${enc(linkCode)}/reset-password", resetBody(token, newPassword, confirmPassword), null, callback, Base.ROOT, Auth.NONE, retry = false)
|
|
1954
|
+
|
|
1955
|
+
private fun resetBody(token: String, newPassword: String, confirmPassword: String) =
|
|
1956
|
+
JSONObject().put("token", token).put("newPassword", newPassword).put("confirmPassword", confirmPassword)
|
|
1957
|
+
|
|
1958
|
+
// ===================
|
|
1959
|
+
// BUSINESS SIGN-IN CODE
|
|
1960
|
+
// ===================
|
|
1961
|
+
|
|
1962
|
+
/** Public; always the same generic answer (no account probing). Code lasts 10 min, single use. */
|
|
1963
|
+
fun requestBusinessSignInCode(email: String, callback: ApiCallback? = null) =
|
|
1964
|
+
request("POST", "/users/sign-in-code", JSONObject().put("email", email), null, callback, Base.API, Auth.NONE, retry = false)
|
|
1965
|
+
|
|
1966
|
+
/** Public; on success the accessToken becomes ownerToken. `require2fa` → call verifyBusinessTotp. */
|
|
1967
|
+
fun verifyBusinessSignInCode(email: String, code: String, callback: ApiCallback? = null) =
|
|
1968
|
+
request("POST", "/users/sign-in-code/verify", JSONObject().put("email", email).put("code", code), null, { res, err ->
|
|
1969
|
+
res?.optString("accessToken")?.takeIf { it.isNotEmpty() }?.let { ownerToken = it }
|
|
1970
|
+
callback?.invoke(res, err)
|
|
1971
|
+
}, Base.API, Auth.NONE, retry = false)
|
|
1972
|
+
|
|
1973
|
+
/** Public; finishes a login that returned `require2fa` with the authenticator-app code. */
|
|
1974
|
+
fun verifyBusinessTotp(pendingToken: String, code: String, callback: ApiCallback? = null) =
|
|
1975
|
+
request("POST", "/users/2fa/verify", JSONObject().put("pendingToken", pendingToken).put("token", code), null, { res, err ->
|
|
1976
|
+
res?.optString("accessToken")?.takeIf { it.isNotEmpty() }?.let { ownerToken = it }
|
|
1977
|
+
callback?.invoke(res, err)
|
|
1978
|
+
}, Base.API, Auth.NONE, retry = false)
|
|
1979
|
+
|
|
1980
|
+
// ===================
|
|
1981
|
+
// LINK ADDRESS, THEME, ACCESS, DOMAIN, OVERVIEW (1.4.0; chatta #489 – #496)
|
|
1982
|
+
// ===================
|
|
1983
|
+
|
|
1984
|
+
/** ownerToken; is this custom link address free? { code, available, reason?, message?, suggestions? }; reasons TOO_SHORT|TOO_LONG|INVALID|RESERVED|TAKEN */
|
|
1985
|
+
fun checkLinkCode(code: String, callback: ApiCallback? = null) =
|
|
1986
|
+
owner("GET", "/chats/links/code-available", null, mapOf("code" to code), callback)
|
|
1987
|
+
|
|
1988
|
+
/** ownerToken; mode templates as data: { linkModes: [...], conversationModes: [...] } */
|
|
1989
|
+
fun getLinkModeCatalog(callback: ApiCallback? = null) = owner("GET", "/chats/links/modes", null, null, callback)
|
|
1990
|
+
|
|
1991
|
+
/** ownerToken; replaces the theme; primaryColor + secondaryColor required, welcomeImageUrl may be a data: URI, footerText ≤ 140 */
|
|
1992
|
+
fun updateLinkTheme(linkId: String, theme: JSONObject, callback: ApiCallback? = null) =
|
|
1993
|
+
owner("PATCH", "/chats/links/${enc(linkId)}/theme", theme, null, callback)
|
|
1994
|
+
|
|
1995
|
+
/** ownerToken; who: guest | members | invite -> { who } */
|
|
1996
|
+
fun setLinkWhoCanJoin(linkId: String, who: String, callback: ApiCallback? = null) =
|
|
1997
|
+
owner("PATCH", "/chats/links/${enc(linkId)}/who-can-join", JSONObject().put("who", who), null, callback)
|
|
1998
|
+
|
|
1999
|
+
/** ownerToken; { domain, target, verified, verifiedAt, error } (white-label plans) */
|
|
2000
|
+
fun getLinkCustomDomain(linkId: String, callback: ApiCallback? = null) =
|
|
2001
|
+
owner("GET", "/chats/links/${enc(linkId)}/custom-domain", null, null, callback)
|
|
2002
|
+
|
|
2003
|
+
/** ownerToken; saves the host name and checks it; an empty string removes it */
|
|
2004
|
+
fun setLinkCustomDomain(linkId: String, domain: String, callback: ApiCallback? = null) =
|
|
2005
|
+
owner("PUT", "/chats/links/${enc(linkId)}/custom-domain", JSONObject().put("domain", domain), null, callback)
|
|
2006
|
+
|
|
2007
|
+
/** ownerToken; checks the domain's CNAME again */
|
|
2008
|
+
fun verifyLinkCustomDomain(linkId: String, callback: ApiCallback? = null) =
|
|
2009
|
+
owner("POST", "/chats/links/${enc(linkId)}/custom-domain/verify", null, null, callback)
|
|
2010
|
+
|
|
2011
|
+
/** ownerToken; deletes every message on the link, never retried: { status, deleted } */
|
|
2012
|
+
fun wipeLinkMessages(linkId: String, callback: ApiCallback? = null) =
|
|
2013
|
+
ownerNoRetry("POST", "/chats/links/${enc(linkId)}/wipe-messages", null, callback)
|
|
2014
|
+
|
|
2015
|
+
/** ownerToken; Overview cards: { visitors30d, visitorsPrev30d, conversations, messages, firstReplyMedianMs, members, maxMembers, visitorsDaily, … } */
|
|
2016
|
+
fun getLinkOverview(linkId: String, callback: ApiCallback? = null) =
|
|
2017
|
+
owner("GET", "/chats/links/${enc(linkId)}/overview", null, null, callback)
|
|
2018
|
+
|
|
2019
|
+
// ===================
|
|
2020
|
+
// API-KEY LINK MODES
|
|
2021
|
+
// ===================
|
|
2022
|
+
|
|
2023
|
+
/** API key; the mode catalog { linkModes, conversationModes } */
|
|
2024
|
+
fun getChatLinkModeCatalog(callback: ApiCallback? = null) {
|
|
2025
|
+
get("/chat-links/modes", null, callback)
|
|
2026
|
+
}
|
|
2027
|
+
|
|
2028
|
+
/** API key; body { mode, applyDefaults? }: { linkId, mode, linkType, joinPolicy, created } */
|
|
2029
|
+
fun setChatLinkMode(linkId: String, payload: JSONObject, callback: ApiCallback? = null) {
|
|
2030
|
+
request("PATCH", "/chat-links/${enc(linkId)}/mode", payload, null, callback)
|
|
2031
|
+
}
|
|
2032
|
+
|
|
2033
|
+
// ===================
|
|
2034
|
+
// MY NOTE, PIN, STARRED PEOPLE (memberToken)
|
|
2035
|
+
// ===================
|
|
2036
|
+
|
|
2037
|
+
/** memberToken; your private note: { conversationId, text, updatedAt } */
|
|
2038
|
+
fun getMyNote(conversationId: String, callback: ApiCallback? = null) =
|
|
2039
|
+
member("GET", "/chats/conversations/${enc(conversationId)}/my-note", null, null, callback)
|
|
2040
|
+
|
|
2041
|
+
/** memberToken; text ≤ 2000, empty clears it */
|
|
2042
|
+
fun setMyNote(conversationId: String, text: String, callback: ApiCallback? = null) =
|
|
2043
|
+
member("PUT", "/chats/conversations/${enc(conversationId)}/my-note", JSONObject().put("text", text), null, callback)
|
|
2044
|
+
|
|
2045
|
+
/** memberToken; pin for yourself: { conversationId, isPinned } */
|
|
2046
|
+
fun setConversationPinned(conversationId: String, pinned: Boolean, callback: ApiCallback? = null) =
|
|
2047
|
+
member("PUT", "/chats/conversations/${enc(conversationId)}/pin", JSONObject().put("pinned", pinned), null, callback)
|
|
2048
|
+
|
|
2049
|
+
/** memberToken; query: nextCursor?, limit? (1–20): { items: [{ _id, displayName, handle, photo, isOnline, starredAt? }], nextCursor, total } */
|
|
2050
|
+
fun listStarredPeople(query: Map<String, String>? = null, callback: ApiCallback? = null) =
|
|
2051
|
+
member("GET", "/chat-users/me/starred", null, query, callback)
|
|
2052
|
+
|
|
2053
|
+
/** memberToken; { ids: [...] } */
|
|
2054
|
+
fun listStarredIds(callback: ApiCallback? = null) = member("GET", "/chat-users/me/starred/ids", null, null, callback)
|
|
2055
|
+
|
|
2056
|
+
/** memberToken; { memberId, starred, total } */
|
|
2057
|
+
fun starPerson(memberId: String, callback: ApiCallback? = null) =
|
|
2058
|
+
member("PUT", "/chat-users/me/starred/${enc(memberId)}", null, null, callback)
|
|
2059
|
+
|
|
2060
|
+
/** memberToken; { memberId, starred, total } */
|
|
2061
|
+
fun unstarPerson(memberId: String, callback: ApiCallback? = null) =
|
|
2062
|
+
member("DELETE", "/chat-users/me/starred/${enc(memberId)}", null, null, callback)
|
|
2063
|
+
|
|
2064
|
+
// ===================
|
|
2065
|
+
// ACCOUNT, FLAGS
|
|
2066
|
+
// ===================
|
|
2067
|
+
|
|
2068
|
+
/** ownerToken; the business account with preferences and flags (hop_calls, voice_transcribe, automation_delays) */
|
|
2069
|
+
fun getAccountProfile(callback: ApiCallback? = null) = owner("GET", "/users/me", null, null, callback)
|
|
2070
|
+
|
|
2071
|
+
/** LiveChatta staff token in ownerToken; the flags the server reads: { results: [{ key, description, defaultOn }] } */
|
|
2072
|
+
fun getKnownFeatureFlags(callback: ApiCallback? = null) = owner("GET", "/admins/feature-flags/known", null, null, callback)
|
|
2073
|
+
|
|
2074
|
+
// ===================
|
|
2075
|
+
// BANK TRANSFERS, EXTRA SEATS, STORAGE PACKS
|
|
2076
|
+
// ===================
|
|
2077
|
+
|
|
2078
|
+
/** ownerToken; { pending: [{ reference, kind: plan_change|extra_seats, state: awaiting|processing, amountUsd, expiresAt, authorizationUrl, seats, planName, … }] } */
|
|
2079
|
+
fun listPendingTransfers(callback: ApiCallback? = null) = owner("GET", "/subscriptions/pending-transfers", null, null, callback)
|
|
2080
|
+
|
|
2081
|
+
/** Member or owner token; quantity, paymentMethod? (card default | bank_transfer); never retried: pending checkout or { status: success, newExtraSeats, … } */
|
|
2082
|
+
fun purchaseExtraSeats(quantity: Int, paymentMethod: String? = null, callback: ApiCallback? = null) =
|
|
2083
|
+
userRoute("POST", "/subscriptions/extra-seats", JSONObject().put("quantity", quantity).apply { if (paymentMethod != null) put("paymentMethod", paymentMethod) }, null, callback, retry = false)
|
|
2084
|
+
|
|
2085
|
+
/** Public; after an extra-seats checkout (SEAT- reference): { status } */
|
|
2086
|
+
fun verifyExtraSeats(reference: String, callback: ApiCallback? = null) =
|
|
2087
|
+
request("POST", "/subscriptions/extra-seats/verify", JSONObject().put("reference", reference), null, callback, Base.API, Auth.NONE, retry = false)
|
|
2088
|
+
|
|
2089
|
+
/** ownerToken; storage pack renews with the plan (card) or joins the invoice (transfer): { id, autoRenew, renewsAt, canAutoRenew, blockedReason, line, … } */
|
|
2090
|
+
fun setStorageAddonAutoRenew(purchaseId: String, autoRenew: Boolean, callback: ApiCallback? = null) =
|
|
2091
|
+
owner("POST", "/subscriptions/storage/addons/${enc(purchaseId)}/auto-renew", JSONObject().put("autoRenew", autoRenew), null, callback)
|
|
2092
|
+
|
|
2093
|
+
// ===================
|
|
2094
|
+
// API KEYS
|
|
2095
|
+
// ===================
|
|
2096
|
+
|
|
2097
|
+
/** ownerToken; body { name, description?, allowedOrigins? (≤ 20: acme.com, https://app.acme.com, *.acme.com) }; never retried */
|
|
2098
|
+
fun createApiKey(payload: JSONObject, callback: ApiCallback? = null) =
|
|
2099
|
+
ownerNoRetry("POST", "/api-keys", payload, callback)
|
|
2100
|
+
|
|
2101
|
+
/** ownerToken; query: nextCursor?, prevCursor?, limit?, apiKeySearch?, apiKeyByStatuses?, dateRange? */
|
|
2102
|
+
fun listApiKeys(query: Map<String, String>? = null, callback: ApiCallback? = null) =
|
|
2103
|
+
owner("GET", "/api-keys", null, query, callback)
|
|
2104
|
+
|
|
2105
|
+
/** ownerToken; body { name?, description?, allowedOrigins? } (an empty list allows any site) */
|
|
2106
|
+
fun updateApiKey(keyId: String, payload: JSONObject, callback: ApiCallback? = null) =
|
|
2107
|
+
owner("PATCH", "/api-keys/${enc(keyId)}", payload, null, callback)
|
|
2108
|
+
|
|
2109
|
+
/** ownerToken; new key with the same name and sites, then the old one is revoked; never retried */
|
|
2110
|
+
fun rotateApiKey(keyId: String, callback: ApiCallback? = null) =
|
|
2111
|
+
ownerNoRetry("POST", "/api-keys/${enc(keyId)}/rotate", null, callback)
|
|
2112
|
+
|
|
2113
|
+
/** ownerToken; stops the key at once */
|
|
2114
|
+
fun revokeApiKey(keyId: String, callback: ApiCallback? = null) =
|
|
2115
|
+
owner("DELETE", "/api-keys/${enc(keyId)}", null, null, callback)
|
|
2116
|
+
|
|
2117
|
+
/** ownerToken; period "7d" | "30d" | "90d" → { labels, requests, errors } per day */
|
|
2118
|
+
fun getApiKeyUsage(keyId: String, period: String = "7d", callback: ApiCallback? = null) =
|
|
2119
|
+
owner("GET", "/api-keys/${enc(keyId)}/usage", null, mapOf("period" to period), callback)
|
|
2120
|
+
|
|
2121
|
+
// ===================
|
|
2122
|
+
// LIVEFLEX (USD balance; routes say /wallet) — member token for your own, owner token for the business's
|
|
2123
|
+
// ===================
|
|
2124
|
+
|
|
2125
|
+
/** Balance, masked payout details, limits, hold and freeze: { id, balanceMinor, pendingWithdrawMinor, payoutBank, payoutCrypto, withdrawLimits, … } */
|
|
2126
|
+
fun getLiveFlex(callback: ApiCallback? = null) = userRoute("GET", "/wallet", null, null, callback)
|
|
2127
|
+
|
|
2128
|
+
/** query: cursor?, limit?, kind? (all | fund | withdraw | transfer_in | transfer_out | gift_sent | gift_received | payment | refund | migration) */
|
|
2129
|
+
fun listLiveFlexTransactions(query: Map<String, String>? = null, callback: ApiCallback? = null) =
|
|
2130
|
+
userRoute("GET", "/wallet/transactions", null, query, callback)
|
|
2131
|
+
|
|
2132
|
+
/** body { amountMinor (100–1,000,000), provider? paystack|cryptomus }; open authorizationUrl. Never retried. */
|
|
2133
|
+
fun fundLiveFlex(payload: JSONObject, callback: ApiCallback? = null) =
|
|
2134
|
+
userRoute("POST", "/wallet/fund", payload, null, callback, retry = false)
|
|
2135
|
+
|
|
2136
|
+
fun verifyLiveFlexFunding(reference: String, callback: ApiCallback? = null) =
|
|
2137
|
+
userRoute("POST", "/wallet/fund/verify", JSONObject().put("reference", reference), null, callback)
|
|
2138
|
+
|
|
2139
|
+
/** People in your workspace you can send to: [{ id, name, handle }] */
|
|
2140
|
+
fun listLiveFlexRecipients(q: String? = null, callback: ApiCallback? = null) =
|
|
2141
|
+
userRoute("GET", "/wallet/recipients", null, q?.let { mapOf("q" to it) }, callback)
|
|
2142
|
+
|
|
2143
|
+
fun listLiveFlexBanks(callback: ApiCallback? = null) = userRoute("GET", "/wallet/banks", null, null, callback)
|
|
2144
|
+
|
|
2145
|
+
/** body { bankCode, accountNumber (10 digits) }; name-checked, then a 6-digit code is emailed. Never retried. */
|
|
2146
|
+
fun setLiveFlexPayoutBank(payload: JSONObject, callback: ApiCallback? = null) =
|
|
2147
|
+
userRoute("PUT", "/wallet/payout/bank", payload, null, callback, retry = false)
|
|
2148
|
+
|
|
2149
|
+
/** body { currency USDT|USDC|BTC|ETH, network, address }; a 6-digit code is emailed. Never retried. */
|
|
2150
|
+
fun setLiveFlexPayoutCrypto(payload: JSONObject, callback: ApiCallback? = null) =
|
|
2151
|
+
userRoute("PUT", "/wallet/payout/crypto", payload, null, callback, retry = false)
|
|
2152
|
+
|
|
2153
|
+
fun confirmLiveFlexPayout(code: String, callback: ApiCallback? = null) =
|
|
2154
|
+
userRoute("POST", "/wallet/payout/confirm", JSONObject().put("code", code), null, callback, retry = false)
|
|
2155
|
+
|
|
2156
|
+
/** which: bank | crypto */
|
|
2157
|
+
fun clearLiveFlexPayout(which: String, callback: ApiCallback? = null) =
|
|
2158
|
+
userRoute("DELETE", "/wallet/payout/${enc(which)}", null, null, callback)
|
|
2159
|
+
|
|
2160
|
+
/** body { amountMinor (≥ 1000), method bank|crypto }. Never retried. */
|
|
2161
|
+
fun withdrawLiveFlex(payload: JSONObject, callback: ApiCallback? = null) =
|
|
2162
|
+
userRoute("POST", "/wallet/withdraw", payload, null, callback, retry = false)
|
|
2163
|
+
|
|
2164
|
+
/** body { recipientId? | toBusiness: "business", amountMinor, note?, idempotencyKey? }; free inside the workspace. */
|
|
2165
|
+
fun sendLiveFlex(payload: JSONObject, callback: ApiCallback? = null) =
|
|
2166
|
+
userRoute("POST", "/wallet/send", payload, null, callback, retry = false)
|
|
2167
|
+
|
|
2168
|
+
/** Emails a code to set or change the LiveFlex PIN; never retried */
|
|
2169
|
+
fun startLiveFlexPinSetup(callback: ApiCallback? = null) =
|
|
2170
|
+
userRoute("POST", "/wallet/pin/start", null, null, callback, retry = false)
|
|
2171
|
+
|
|
2172
|
+
/** body { code, pin (4–6 digits) }; then pass pin on send / withdraw over pinOverMinor */
|
|
2173
|
+
fun setLiveFlexPin(payload: JSONObject, callback: ApiCallback? = null) =
|
|
2174
|
+
userRoute("POST", "/wallet/pin", payload, null, callback, retry = false)
|
|
2175
|
+
|
|
2176
|
+
/** 1.6.0: emails a code to link this workspace's LiveFlex into the person's one LiveFlex */
|
|
2177
|
+
fun startLiveFlexLink(callback: ApiCallback? = null) =
|
|
2178
|
+
userRoute("POST", "/wallet/link/start", null, null, callback, retry = false)
|
|
2179
|
+
|
|
2180
|
+
/** body { code }; one way: the balance here moves into the person's LiveFlex → { linked, movedMinor, accounts } */
|
|
2181
|
+
fun linkLiveFlex(payload: JSONObject, callback: ApiCallback? = null) =
|
|
2182
|
+
userRoute("POST", "/wallet/link", payload, null, callback, retry = false)
|
|
2183
|
+
|
|
2184
|
+
/** opt-in global tag (linked LiveFlex only); "" turns it off → { tag } */
|
|
2185
|
+
fun setLiveFlexTag(tag: String, callback: ApiCallback? = null) =
|
|
2186
|
+
userRoute("PUT", "/wallet/tag", JSONObject().put("tag", tag), null, callback, retry = false)
|
|
2187
|
+
|
|
2188
|
+
/** exact lookup → { tag, name }; then sendLiveFlex with toTag (first time: code) */
|
|
2189
|
+
fun findLiveFlexTag(tag: String, callback: ApiCallback? = null) {
|
|
2190
|
+
val t = tag.trimStart('$')
|
|
2191
|
+
userRoute("GET", "/wallet/tags/${enc(t)}", null, null, callback)
|
|
2192
|
+
}
|
|
2193
|
+
|
|
2194
|
+
/** ownerToken; team admins' business sends waiting for the owner → { results } */
|
|
2195
|
+
fun listLiveFlexApprovals(callback: ApiCallback? = null) =
|
|
2196
|
+
owner("GET", "/wallet/approvals", null, null, callback)
|
|
2197
|
+
|
|
2198
|
+
/** ownerToken; status "approved" | "declined"; single use, never retried */
|
|
2199
|
+
fun decideLiveFlexApproval(approvalId: String, status: String, callback: ApiCallback? = null) =
|
|
2200
|
+
ownerNoRetry("PATCH", "/wallet/approvals/${enc(approvalId)}/${enc(status)}", null, callback)
|
|
2201
|
+
|
|
2202
|
+
/** owner or team admin token → { approveOverMinor, dailyCapMinor, custom } */
|
|
2203
|
+
fun getLiveFlexTeamLimits(callback: ApiCallback? = null) =
|
|
2204
|
+
owner("GET", "/wallet/team-limits", null, null, callback)
|
|
2205
|
+
|
|
2206
|
+
/** ownerToken; body { approveOverMinor, dailyCapMinor } in cents (0 off, null = default) */
|
|
2207
|
+
fun setLiveFlexTeamLimits(payload: JSONObject, callback: ApiCallback? = null) =
|
|
2208
|
+
owner("PUT", "/wallet/team-limits", payload, null, callback)
|
|
2209
|
+
|
|
2210
|
+
// ===================
|
|
2211
|
+
// LIVEFLEX REQUESTS, SPLITS, STANDING, POTS, REFUNDS, PAY LINKS, RECEIPTS (1.7.0)
|
|
2212
|
+
// money-moving calls are never retried
|
|
2213
|
+
// ===================
|
|
2214
|
+
|
|
2215
|
+
/** 1.7.0: { conversationId, amountMinor, note?, id | handle | tag } → request card; never takes money by itself */
|
|
2216
|
+
fun createLiveFlexRequest(payload: JSONObject, callback: ApiCallback? = null) =
|
|
2217
|
+
member("POST", "/wallet/requests", payload, null, callback, retry = false)
|
|
2218
|
+
|
|
2219
|
+
/** box "incoming" (default) | "outgoing" → { results } */
|
|
2220
|
+
fun listLiveFlexRequests(box: String = "incoming", callback: ApiCallback? = null) =
|
|
2221
|
+
member("GET", "/wallet/requests", null, mapOf("box" to box), callback)
|
|
2222
|
+
|
|
2223
|
+
/** one request card (the two people, or members of its chat) */
|
|
2224
|
+
fun getLiveFlexRequest(id: String, callback: ApiCallback? = null) =
|
|
2225
|
+
member("GET", "/wallet/requests/${enc(id)}", null, null, callback)
|
|
2226
|
+
|
|
2227
|
+
/** payer only; body { pin?, code? }; same checks as a send → { status, reference, balanceMinor } */
|
|
2228
|
+
fun payLiveFlexRequest(id: String, payload: JSONObject = JSONObject(), callback: ApiCallback? = null) =
|
|
2229
|
+
member("POST", "/wallet/requests/${enc(id)}/pay", payload, null, callback, retry = false)
|
|
2230
|
+
|
|
2231
|
+
/** payer only, while pending */
|
|
2232
|
+
fun declineLiveFlexRequest(id: String, callback: ApiCallback? = null) =
|
|
2233
|
+
member("POST", "/wallet/requests/${enc(id)}/decline", null, null, callback, retry = false)
|
|
2234
|
+
|
|
2235
|
+
/** payer only: declines a waiting request and refuses new ones from that person */
|
|
2236
|
+
fun blockLiveFlexRequester(id: String, callback: ApiCallback? = null) =
|
|
2237
|
+
member("POST", "/wallet/requests/${enc(id)}/block", null, null, callback, retry = false)
|
|
2238
|
+
|
|
2239
|
+
/** requester only, while pending */
|
|
2240
|
+
fun cancelLiveFlexRequest(id: String, callback: ApiCallback? = null) =
|
|
2241
|
+
member("POST", "/wallet/requests/${enc(id)}/cancel", null, null, callback, retry = false)
|
|
2242
|
+
|
|
2243
|
+
/** { conversationId, totalMinor, payers: [{ id | handle | tag, amountMinor? }], includeMe?, note? } → split card */
|
|
2244
|
+
fun createLiveFlexSplit(payload: JSONObject, callback: ApiCallback? = null) =
|
|
2245
|
+
member("POST", "/wallet/splits", payload, null, callback, retry = false)
|
|
2246
|
+
|
|
2247
|
+
/** split card: amounts and paid / unpaid */
|
|
2248
|
+
fun getLiveFlexSplit(id: String, callback: ApiCallback? = null) =
|
|
2249
|
+
member("GET", "/wallet/splits/${enc(id)}", null, null, callback)
|
|
2250
|
+
|
|
2251
|
+
/** requester only; cancels the unpaid shares */
|
|
2252
|
+
fun cancelLiveFlexSplit(id: String, callback: ApiCallback? = null) =
|
|
2253
|
+
member("POST", "/wallet/splits/${enc(id)}/cancel", null, null, callback, retry = false)
|
|
2254
|
+
|
|
2255
|
+
/** yours and ones aimed at you (read-only); owner token lists the business's → { results } */
|
|
2256
|
+
fun listLiveFlexStanding(callback: ApiCallback? = null) =
|
|
2257
|
+
userRoute("GET", "/wallet/standing", null, null, callback)
|
|
2258
|
+
|
|
2259
|
+
/** { id | handle | tag, amountMinor, interval: week | 2weeks | month, startAt?, until?, maxRuns?, note?, pin?, code? }; your confirmation covers every run */
|
|
2260
|
+
fun createLiveFlexStanding(payload: JSONObject, callback: ApiCallback? = null) =
|
|
2261
|
+
member("POST", "/wallet/standing", payload, null, callback, retry = false)
|
|
2262
|
+
|
|
2263
|
+
/** payer (or business owner) only */
|
|
2264
|
+
fun pauseLiveFlexStanding(id: String, callback: ApiCallback? = null) =
|
|
2265
|
+
userRoute("POST", "/wallet/standing/${enc(id)}/pause", null, null, callback, retry = false)
|
|
2266
|
+
|
|
2267
|
+
/** payer (or business owner) only */
|
|
2268
|
+
fun resumeLiveFlexStanding(id: String, callback: ApiCallback? = null) =
|
|
2269
|
+
userRoute("POST", "/wallet/standing/${enc(id)}/resume", null, null, callback, retry = false)
|
|
2270
|
+
|
|
2271
|
+
/** payer (or business owner) only; the recipient can see but not change it */
|
|
2272
|
+
fun cancelLiveFlexStanding(id: String, callback: ApiCallback? = null) =
|
|
2273
|
+
userRoute("POST", "/wallet/standing/${enc(id)}/cancel", null, null, callback, retry = false)
|
|
2274
|
+
|
|
2275
|
+
/** { conversationId, title, amountMinor? (fixed each), goalMinor?, closesAt? } → pot card */
|
|
2276
|
+
fun createLiveFlexPot(payload: JSONObject, callback: ApiCallback? = null) =
|
|
2277
|
+
member("POST", "/wallet/pots", payload, null, callback, retry = false)
|
|
2278
|
+
|
|
2279
|
+
/** pot card (members of its chat) */
|
|
2280
|
+
fun getLiveFlexPot(id: String, callback: ApiCallback? = null) =
|
|
2281
|
+
member("GET", "/wallet/pots/${enc(id)}", null, null, callback)
|
|
2282
|
+
|
|
2283
|
+
/** body { amountMinor? (any-amount pots), pin?, code? }; held in escrow until the pot closes */
|
|
2284
|
+
fun contributeLiveFlexPot(id: String, payload: JSONObject = JSONObject(), callback: ApiCallback? = null) =
|
|
2285
|
+
member("POST", "/wallet/pots/${enc(id)}/contribute", payload, null, callback, retry = false)
|
|
2286
|
+
|
|
2287
|
+
/** organizer only; pays out once */
|
|
2288
|
+
fun closeLiveFlexPot(id: String, callback: ApiCallback? = null) =
|
|
2289
|
+
member("POST", "/wallet/pots/${enc(id)}/close", null, null, callback, retry = false)
|
|
2290
|
+
|
|
2291
|
+
/** organizer only; refunds everyone */
|
|
2292
|
+
fun cancelLiveFlexPot(id: String, callback: ApiCallback? = null) =
|
|
2293
|
+
member("POST", "/wallet/pots/${enc(id)}/cancel", null, null, callback, retry = false)
|
|
2294
|
+
|
|
2295
|
+
/** body { amountMinor?, note?, key?, pin?, code? }; never above the original; only the receiver */
|
|
2296
|
+
fun refundLiveFlexTransaction(id: String, payload: JSONObject = JSONObject(), callback: ApiCallback? = null) =
|
|
2297
|
+
userRoute("POST", "/wallet/transactions/${enc(id)}/refund", payload, null, callback, retry = false)
|
|
2298
|
+
|
|
2299
|
+
/** staff: { conversationId, amountMinor, description, reference? } → paylink card */
|
|
2300
|
+
fun createLiveFlexPayLink(payload: JSONObject, callback: ApiCallback? = null) =
|
|
2301
|
+
member("POST", "/wallet/pay-links", payload, null, callback, retry = false)
|
|
2302
|
+
|
|
2303
|
+
/** paylink card (members of its chat) */
|
|
2304
|
+
fun getLiveFlexPayLink(id: String, callback: ApiCallback? = null) =
|
|
2305
|
+
member("GET", "/wallet/pay-links/${enc(id)}", null, null, callback)
|
|
2306
|
+
|
|
2307
|
+
/** staff only (agents, their own) */
|
|
2308
|
+
fun cancelLiveFlexPayLink(id: String, callback: ApiCallback? = null) =
|
|
2309
|
+
member("POST", "/wallet/pay-links/${enc(id)}/cancel", null, null, callback, retry = false)
|
|
2310
|
+
|
|
2311
|
+
/** body { method: wallet | card, pin?, code? }; card → { authorizationUrl, reference } */
|
|
2312
|
+
fun payLiveFlexPayLink(id: String, payload: JSONObject, callback: ApiCallback? = null) =
|
|
2313
|
+
member("POST", "/wallet/pay-links/${enc(id)}/pay", payload, null, callback, retry = false)
|
|
2314
|
+
|
|
2315
|
+
/** public, idempotent; after a card checkout → { status, reference } */
|
|
2316
|
+
fun verifyLiveFlexPayLink(reference: String, callback: ApiCallback? = null) =
|
|
2317
|
+
userRoute("POST", "/wallet/pay-links/verify", JSONObject().put("reference", reference), null, callback)
|
|
2318
|
+
|
|
2319
|
+
/** → { url } signed, 10 minutes */
|
|
2320
|
+
fun getLiveFlexPayLinkReceiptLink(id: String, callback: ApiCallback? = null) =
|
|
2321
|
+
member("GET", "/wallet/pay-links/${enc(id)}/receipt/link", null, null, callback)
|
|
2322
|
+
|
|
2323
|
+
/** latest finished payments as signed 10-minute receipt links → { results } */
|
|
2324
|
+
fun listLiveFlexReceipts(callback: ApiCallback? = null) =
|
|
2325
|
+
userRoute("GET", "/wallet/receipts", null, null, callback)
|
|
2326
|
+
|
|
2327
|
+
/** signed 10-minute PDF link for one payment */
|
|
2328
|
+
fun getLiveFlexReceiptLink(reference: String, callback: ApiCallback? = null) =
|
|
2329
|
+
userRoute("GET", "/wallet/receipts/${enc(reference)}/link", null, null, callback)
|
|
2330
|
+
|
|
2331
|
+
/** month YYYY-MM → { month, scope, pdfUrl, csvUrl } */
|
|
2332
|
+
fun getLiveFlexStatementLinks(month: String, callback: ApiCallback? = null) =
|
|
2333
|
+
userRoute("GET", "/wallet/statements/${enc(month)}/links", null, null, callback)
|
|
2334
|
+
|
|
2335
|
+
// ===================
|
|
2336
|
+
// STAFF ACCESS GRANT (owner or team admin)
|
|
2337
|
+
// ===================
|
|
2338
|
+
|
|
2339
|
+
/** ownerToken: { on, mode: view|act|null, until, grantedByName } */
|
|
2340
|
+
fun getStaffAccessGrant(callback: ApiCallback? = null) = owner("GET", "/staff-access/grant", null, null, callback)
|
|
2341
|
+
|
|
2342
|
+
/** ownerToken; body { mode: view|act, hours: 1|24|72|168 } */
|
|
2343
|
+
fun setStaffAccessGrant(payload: JSONObject, callback: ApiCallback? = null) =
|
|
2344
|
+
owner("PUT", "/staff-access/grant", payload, null, callback)
|
|
2345
|
+
|
|
2346
|
+
/** ownerToken; turns support access off and ends any open staff session. */
|
|
2347
|
+
fun revokeStaffAccessGrant(callback: ApiCallback? = null) = owner("DELETE", "/staff-access/grant", null, null, callback)
|
|
2348
|
+
|
|
2349
|
+
/** Owner or team admin: platform stickers with their content check. query: review, scope, q, nextCursor */
|
|
2350
|
+
fun listWorkspaceStickers(query: Map<String, String>? = null, callback: ApiCallback? = null) = owner("GET", "/chats/stickers", null, query, callback)
|
|
2351
|
+
|
|
2352
|
+
/** state: "blocked" (hidden in your workspace) or "allowed". */
|
|
2353
|
+
fun setWorkspaceStickerState(stickerId: String, state: String, callback: ApiCallback? = null) =
|
|
2354
|
+
owner("PATCH", "/chats/stickers/${enc(stickerId)}/workspace/${enc(state)}", null, null, callback)
|
|
2355
|
+
|
|
2356
|
+
/** Take down a sticker one of your members uploaded. */
|
|
2357
|
+
fun takeDownSticker(stickerId: String, callback: ApiCallback? = null) = owner("POST", "/chats/stickers/${enc(stickerId)}/take-down", null, null, callback)
|
|
2358
|
+
|
|
2359
|
+
// ===================
|
|
2360
|
+
// CALLS HISTORY, CONTACT, GOOGLE SIGN-IN
|
|
2361
|
+
// ===================
|
|
2362
|
+
|
|
2363
|
+
/** memberToken; every ended call, newest first; query: nextCursor? (page number), limit? (≤ 20): { results, upcoming, nextCursor, prevCursor, hasMore, hasPrev, limit } */
|
|
2364
|
+
fun listCallHistory(query: Map<String, String>? = null, callback: ApiCallback? = null) =
|
|
2365
|
+
member("GET", "/hops/calls", null, query, callback)
|
|
2366
|
+
|
|
2367
|
+
/** memberToken; 10-minute MP4 link { url (server-relative), expiresAt, filename }; 403 RECORDING_DOWNLOAD_OFF when the link's switch is off */
|
|
2368
|
+
fun getRecordingDownloadLink(messageId: String, callback: ApiCallback? = null) =
|
|
2369
|
+
member("POST", "/hops/recordings/${enc(messageId)}/download", null, null, callback, retry = false)
|
|
2370
|
+
|
|
2371
|
+
/** Public; body { name, email, message (5–4000), website? (leave empty) } at the site root; never retried: { success, message } */
|
|
2372
|
+
fun sendContactMessage(payload: JSONObject, callback: ApiCallback? = null) =
|
|
2373
|
+
request("POST", "/public/contact", payload, null, callback, Base.ROOT, Auth.NONE, retry = false)
|
|
2374
|
+
|
|
2375
|
+
/** The URL that starts "Continue with Google"; open it in the browser. No request is made. */
|
|
2376
|
+
fun googleSignInUrl(returnUrl: String? = null): String =
|
|
2377
|
+
"$apiUrl/users/google/start" + buildQueryString(if (returnUrl.isNullOrBlank()) null else mapOf("returnUrl" to returnUrl))
|
|
2378
|
+
|
|
2379
|
+
/** Public; finishes Google sign-in with the #google=<handoff> from the login URL; the token becomes ownerToken */
|
|
2380
|
+
fun redeemGoogleSignIn(handoff: String, callback: ApiCallback? = null) =
|
|
2381
|
+
request("POST", "/users/google/redeem", JSONObject().put("handoff", handoff), null, { res, err ->
|
|
2382
|
+
res?.optString("accessToken")?.takeIf { it.isNotEmpty() }?.let { ownerToken = it }
|
|
2383
|
+
callback?.invoke(res, err)
|
|
2384
|
+
}, Base.API, Auth.NONE, retry = false)
|
|
2385
|
+
|
|
2386
|
+
// ===================
|
|
2387
|
+
// INTERNAL
|
|
2388
|
+
// ===================
|
|
2389
|
+
|
|
2390
|
+
private fun member(
|
|
2391
|
+
method: String,
|
|
2392
|
+
path: String,
|
|
2393
|
+
body: JSONObject?,
|
|
2394
|
+
query: Map<String, String>?,
|
|
2395
|
+
callback: ApiCallback?,
|
|
2396
|
+
retry: Boolean = true,
|
|
2397
|
+
) {
|
|
2398
|
+
if (memberToken.isNullOrBlank()) {
|
|
2399
|
+
deliverResult(callback, null, "Member token required — set api().memberToken")
|
|
2400
|
+
return
|
|
2401
|
+
}
|
|
2402
|
+
request(method, path, body, query, callback, Base.API, Auth.MEMBER, retry)
|
|
2403
|
+
}
|
|
2404
|
+
|
|
2405
|
+
/** Routes open to members and owners: member token if set, else owner token. */
|
|
2406
|
+
private fun userRoute(
|
|
2407
|
+
method: String,
|
|
2408
|
+
path: String,
|
|
2409
|
+
body: JSONObject?,
|
|
2410
|
+
query: Map<String, String>?,
|
|
2411
|
+
callback: ApiCallback?,
|
|
2412
|
+
retry: Boolean = true,
|
|
2413
|
+
) {
|
|
2414
|
+
when {
|
|
2415
|
+
!memberToken.isNullOrBlank() -> request(method, path, body, query, callback, Base.API, Auth.MEMBER, retry)
|
|
2416
|
+
!ownerToken.isNullOrBlank() -> request(method, path, body, query, callback, Base.API, Auth.OWNER, retry)
|
|
2417
|
+
else -> deliverResult(callback, null, "Member or owner token required")
|
|
2418
|
+
}
|
|
2419
|
+
}
|
|
2420
|
+
|
|
2421
|
+
private fun owner(
|
|
2422
|
+
method: String,
|
|
2423
|
+
path: String,
|
|
2424
|
+
body: JSONObject?,
|
|
2425
|
+
query: Map<String, String>?,
|
|
2426
|
+
callback: ApiCallback?,
|
|
2427
|
+
) {
|
|
2428
|
+
if (ownerToken.isNullOrBlank()) {
|
|
2429
|
+
deliverResult(callback, null, "Owner token required — set api().ownerToken")
|
|
2430
|
+
return
|
|
2431
|
+
}
|
|
2432
|
+
request(method, path, body, query, callback, Base.API, Auth.OWNER)
|
|
2433
|
+
}
|
|
2434
|
+
|
|
2435
|
+
private fun ownerNoRetry(
|
|
2436
|
+
method: String,
|
|
2437
|
+
path: String,
|
|
2438
|
+
body: JSONObject?,
|
|
2439
|
+
callback: ApiCallback?,
|
|
2440
|
+
) {
|
|
2441
|
+
if (ownerToken.isNullOrBlank()) {
|
|
2442
|
+
deliverResult(callback, null, "Owner token required — set api().ownerToken")
|
|
2443
|
+
return
|
|
2444
|
+
}
|
|
2445
|
+
request(method, path, body, null, callback, Base.API, Auth.OWNER, retry = false)
|
|
2446
|
+
}
|
|
2447
|
+
|
|
2448
|
+
private fun enc(value: String): String = URLEncoder.encode(value, "UTF-8").replace("+", "%20")
|
|
2449
|
+
|
|
2450
|
+
fun getWebinarRegistrations(
|
|
2451
|
+
conversationId: String,
|
|
2452
|
+
callback: ApiCallback? = null,
|
|
2453
|
+
) {
|
|
2454
|
+
get("/chats/conversations/$conversationId/webinar/registrations", null, callback)
|
|
2455
|
+
}
|
|
2456
|
+
|
|
2457
|
+
private fun get(
|
|
2458
|
+
path: String,
|
|
2459
|
+
query: Map<String, String>? = null,
|
|
2460
|
+
callback: ApiCallback? = null,
|
|
2461
|
+
) {
|
|
2462
|
+
request("GET", path, null, query, callback)
|
|
2463
|
+
}
|
|
2464
|
+
|
|
2465
|
+
private fun post(
|
|
2466
|
+
path: String,
|
|
2467
|
+
body: JSONObject?,
|
|
2468
|
+
callback: ApiCallback? = null,
|
|
2469
|
+
) {
|
|
2470
|
+
request("POST", path, body, null, callback)
|
|
2471
|
+
}
|
|
2472
|
+
|
|
2473
|
+
private fun request(
|
|
2474
|
+
method: String,
|
|
2475
|
+
path: String,
|
|
2476
|
+
body: JSONObject? = null,
|
|
2477
|
+
query: Map<String, String>? = null,
|
|
2478
|
+
callback: ApiCallback? = null,
|
|
2479
|
+
base: Base = Base.EXTERNAL,
|
|
2480
|
+
auth: Auth = Auth.API_KEY,
|
|
2481
|
+
retry: Boolean = true,
|
|
2482
|
+
headers: Map<String, String> = emptyMap(),
|
|
2483
|
+
requireOwner: Boolean = false,
|
|
2484
|
+
) {
|
|
2485
|
+
if (requireOwner && ownerToken.isNullOrBlank()) {
|
|
2486
|
+
deliverResult(callback, null, "Owner token required — set api().ownerToken")
|
|
2487
|
+
return
|
|
2488
|
+
}
|
|
2489
|
+
val root =
|
|
2490
|
+
when (base) {
|
|
2491
|
+
Base.EXTERNAL -> baseUrl
|
|
2492
|
+
Base.API -> apiUrl
|
|
2493
|
+
Base.ROOT -> rootUrl
|
|
2494
|
+
}
|
|
2495
|
+
executor.execute {
|
|
2496
|
+
var lastError: String? = null
|
|
2497
|
+
|
|
2498
|
+
for (attempt in 0..(if (retry) maxRetries else 0)) {
|
|
2499
|
+
try {
|
|
2500
|
+
val queryString = buildQueryString(query)
|
|
2501
|
+
val url = URL("$root$path$queryString")
|
|
2502
|
+
|
|
2503
|
+
if (debug) Log.d(LiveChattaClient.TAG, "[HTTP] $method $path")
|
|
2504
|
+
|
|
2505
|
+
val conn =
|
|
2506
|
+
(url.openConnection() as HttpURLConnection).apply {
|
|
2507
|
+
requestMethod = if (method == "PATCH") "POST" else method
|
|
2508
|
+
if (method == "PATCH") {
|
|
2509
|
+
setRequestProperty("X-HTTP-Method-Override", "PATCH")
|
|
2510
|
+
}
|
|
2511
|
+
setRequestProperty("Content-Type", "application/json")
|
|
2512
|
+
headers.forEach { (k, v) -> setRequestProperty(k, v) }
|
|
2513
|
+
when (auth) {
|
|
2514
|
+
Auth.API_KEY -> {
|
|
2515
|
+
setRequestProperty("x-api-key", apiKey)
|
|
2516
|
+
setRequestProperty("x-embed", "true")
|
|
2517
|
+
}
|
|
2518
|
+
Auth.OWNER -> setRequestProperty("Authorization", "Bearer $ownerToken")
|
|
2519
|
+
Auth.MEMBER -> setRequestProperty("Authorization", "Bearer $memberToken")
|
|
2520
|
+
Auth.NONE -> Unit
|
|
2521
|
+
}
|
|
2522
|
+
connectTimeout = timeout
|
|
2523
|
+
readTimeout = timeout
|
|
2524
|
+
doInput = true
|
|
2525
|
+
}
|
|
2526
|
+
|
|
2527
|
+
if (body != null && method != "GET") {
|
|
2528
|
+
conn.doOutput = true
|
|
2529
|
+
val writer = OutputStreamWriter(conn.outputStream)
|
|
2530
|
+
writer.write(body.toString())
|
|
2531
|
+
writer.flush()
|
|
2532
|
+
writer.close()
|
|
2533
|
+
}
|
|
2534
|
+
|
|
2535
|
+
val responseCode = conn.responseCode
|
|
2536
|
+
|
|
2537
|
+
if (responseCode in 200..299) {
|
|
2538
|
+
val response = readResponse(conn)
|
|
2539
|
+
val json = parseResponse(response)
|
|
2540
|
+
deliverResult(callback, json, null)
|
|
2541
|
+
return@execute
|
|
2542
|
+
}
|
|
2543
|
+
|
|
2544
|
+
// Client error — don't retry
|
|
2545
|
+
if (responseCode < 500) {
|
|
2546
|
+
val errorJson =
|
|
2547
|
+
try {
|
|
2548
|
+
JSONObject(readErrorResponse(conn))
|
|
2549
|
+
} catch (e: Exception) {
|
|
2550
|
+
null
|
|
2551
|
+
}
|
|
2552
|
+
val fallback = "Request failed: $responseCode"
|
|
2553
|
+
val errorMsg = errorJson?.optString("message", fallback) ?: fallback
|
|
2554
|
+
val code = LiveChattaErrorCode.fromBody(errorJson)
|
|
2555
|
+
deliverError(callback, LiveChattaApiError(errorMsg, responseCode, code, path))
|
|
2556
|
+
return@execute
|
|
2557
|
+
}
|
|
2558
|
+
|
|
2559
|
+
// Server error — retry; keep the server's message like iOS / Flutter do.
|
|
2560
|
+
val raw = readErrorResponse(conn)
|
|
2561
|
+
lastError = (try { JSONObject(raw).optString("message", "") } catch (e: Exception) { "" })
|
|
2562
|
+
.ifEmpty { "Request failed: $responseCode" }
|
|
2563
|
+
conn.disconnect()
|
|
2564
|
+
} catch (e: Exception) {
|
|
2565
|
+
lastError = e.message ?: "Unknown error"
|
|
2566
|
+
}
|
|
2567
|
+
|
|
2568
|
+
// Exponential backoff
|
|
2569
|
+
if (retry && attempt < maxRetries) {
|
|
2570
|
+
Thread.sleep((Math.pow(2.0, attempt.toDouble()) * 1000).toLong())
|
|
2571
|
+
}
|
|
2572
|
+
}
|
|
2573
|
+
|
|
2574
|
+
deliverResult(callback, null, lastError ?: "Request failed")
|
|
2575
|
+
}
|
|
2576
|
+
}
|
|
2577
|
+
|
|
2578
|
+
private fun readResponse(conn: HttpURLConnection): String = BufferedReader(InputStreamReader(conn.inputStream)).use { it.readText() }
|
|
2579
|
+
|
|
2580
|
+
private fun readErrorResponse(conn: HttpURLConnection): String =
|
|
2581
|
+
try {
|
|
2582
|
+
BufferedReader(InputStreamReader(conn.errorStream)).use { it.readText() }
|
|
2583
|
+
} catch (e: Exception) {
|
|
2584
|
+
"Error reading response"
|
|
2585
|
+
}
|
|
2586
|
+
|
|
2587
|
+
private fun parseResponse(response: String): JSONObject =
|
|
2588
|
+
try {
|
|
2589
|
+
JSONObject(response)
|
|
2590
|
+
} catch (e: Exception) {
|
|
2591
|
+
try {
|
|
2592
|
+
// Response might be a JSON array
|
|
2593
|
+
JSONObject().put("results", JSONArray(response))
|
|
2594
|
+
} catch (e2: Exception) {
|
|
2595
|
+
JSONObject().put("data", response)
|
|
2596
|
+
}
|
|
2597
|
+
}
|
|
2598
|
+
|
|
2599
|
+
private fun buildQueryString(params: Map<String, String>?): String {
|
|
2600
|
+
if (params.isNullOrEmpty()) return ""
|
|
2601
|
+
val entries = params.filter { it.value.isNotBlank() }
|
|
2602
|
+
if (entries.isEmpty()) return ""
|
|
2603
|
+
return "?" +
|
|
2604
|
+
entries.entries.joinToString("&") {
|
|
2605
|
+
"${URLEncoder.encode(it.key, "UTF-8")}=${URLEncoder.encode(it.value, "UTF-8")}"
|
|
2606
|
+
}
|
|
2607
|
+
}
|
|
2608
|
+
|
|
2609
|
+
private companion object {
|
|
2610
|
+
val VISITOR_ID = Regex("^[A-Za-z0-9_-]{8,64}$")
|
|
2611
|
+
}
|
|
2612
|
+
|
|
2613
|
+
private fun deliverResult(
|
|
2614
|
+
callback: ApiCallback?,
|
|
2615
|
+
result: JSONObject?,
|
|
2616
|
+
error: String?,
|
|
2617
|
+
) {
|
|
2618
|
+
mainHandler.post { callback?.invoke(result, error) }
|
|
2619
|
+
}
|
|
2620
|
+
|
|
2621
|
+
private fun deliverError(
|
|
2622
|
+
callback: ApiCallback?,
|
|
2623
|
+
error: LiveChattaApiError,
|
|
2624
|
+
) {
|
|
2625
|
+
mainHandler.post {
|
|
2626
|
+
onApiError?.invoke(error)
|
|
2627
|
+
callback?.invoke(null, error.message)
|
|
2628
|
+
}
|
|
2629
|
+
}
|
|
2630
|
+
}
|