@livechatta/sdk 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +218 -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 +7258 -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 +7077 -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 +7262 -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 +278 -4
|
@@ -0,0 +1,1942 @@
|
|
|
1
|
+
/// Flutter REST client mirroring the TypeScript HttpAPI (`http` package). API-key calls hit
|
|
2
|
+
/// /api/v1/external; owner-console calls need [ownerToken]; see README "Flutter (Dart)".
|
|
3
|
+
|
|
4
|
+
import 'dart:async';
|
|
5
|
+
import 'dart:convert';
|
|
6
|
+
import 'package:http/http.dart' as http;
|
|
7
|
+
|
|
8
|
+
/// HTTP API error with status code; [code] is the server's UPPER_SNAKE code when it sent one.
|
|
9
|
+
class LiveChattaApiError implements Exception {
|
|
10
|
+
final String message;
|
|
11
|
+
final int statusCode;
|
|
12
|
+
final String? code;
|
|
13
|
+
final String? path;
|
|
14
|
+
|
|
15
|
+
LiveChattaApiError(this.message, this.statusCode, {this.code, this.path});
|
|
16
|
+
|
|
17
|
+
@override
|
|
18
|
+
String toString() =>
|
|
19
|
+
code == null ? 'LiveChattaApiError($statusCode): $message' : 'LiveChattaApiError($statusCode, $code): $message';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/// Machine-readable server error codes.
|
|
23
|
+
class LiveChattaErrorCodes {
|
|
24
|
+
/// 403 from POST /in/:code/join-exist: the member is blocked from the link and gets no token.
|
|
25
|
+
static const linkMemberBlocked = 'LINK_MEMBER_BLOCKED';
|
|
26
|
+
|
|
27
|
+
/// 400 from join / join-exist: the link reached its member cap; show the "This space is full" state.
|
|
28
|
+
static const linkFull = 'LINK_FULL';
|
|
29
|
+
|
|
30
|
+
/// 400 from join-new / join-guest: that email already has an account; sign in with join-exist instead.
|
|
31
|
+
static const accountExists = 'ACCOUNT_EXISTS';
|
|
32
|
+
|
|
33
|
+
/// 400 from join-guest: this link's mode needs a real email.
|
|
34
|
+
static const emailRequired = 'EMAIL_REQUIRED';
|
|
35
|
+
|
|
36
|
+
/// 403 from join-guest / join-new / join-exist / sign-in: invite only (not on the list), or guests not allowed.
|
|
37
|
+
static const inviteOnly = 'INVITE_ONLY';
|
|
38
|
+
|
|
39
|
+
/// 403 from join-guest: guests are off but members may sign in or join as new (e.g. school links).
|
|
40
|
+
static const signInRequired = 'SIGN_IN_REQUIRED';
|
|
41
|
+
|
|
42
|
+
/// 403 from requestToJoinLink: the link doesn't take requests to join.
|
|
43
|
+
static const approvalOff = 'APPROVAL_OFF';
|
|
44
|
+
|
|
45
|
+
/// 400 from join-new: that @handle is already used in this workspace.
|
|
46
|
+
static const handleTaken = 'HANDLE_TAKEN';
|
|
47
|
+
|
|
48
|
+
/// 403 on an /admin/* console page the admin role can't open.
|
|
49
|
+
static const adminNoAccess = 'ADMIN_NO_ACCESS';
|
|
50
|
+
|
|
51
|
+
/// Socket ack error on hop reaction / vote / raise-hand / poll-vote over the cap (10 s window).
|
|
52
|
+
static const hopRateLimited = 'RATE_LIMITED';
|
|
53
|
+
|
|
54
|
+
/// 429 chat-error when messages are sent too fast; keep the message as not sent and offer Retry.
|
|
55
|
+
static const rateLimited = 'RATE_LIMITED';
|
|
56
|
+
|
|
57
|
+
/// 403 from getRecordingDownloadLink (and the download) while the link's "Download call recordings" is off.
|
|
58
|
+
static const recordingDownloadOff = 'RECORDING_DOWNLOAD_OFF';
|
|
59
|
+
|
|
60
|
+
/// 403 when a recording download link has expired; ask for a new one.
|
|
61
|
+
static const recordingDownloadExpired = 'RECORDING_DOWNLOAD_EXPIRED';
|
|
62
|
+
|
|
63
|
+
/// Plan refusal codes (chatta #396): planNotFound is 404, the other two 400.
|
|
64
|
+
static const planNotFound = 'PLAN_NOT_FOUND';
|
|
65
|
+
static const planNotAvailable = 'PLAN_NOT_AVAILABLE';
|
|
66
|
+
static const planTeamActivated = 'PLAN_TEAM_ACTIVATED';
|
|
67
|
+
|
|
68
|
+
/// 400 on an upload past the month's storage allowance (body adds resetsAt; chatta #420).
|
|
69
|
+
static const storageLimit = 'STORAGE_LIMIT';
|
|
70
|
+
|
|
71
|
+
/// 400 on `editMessage` after the edit window (24 h from sending); the socket ack's body carries this code.
|
|
72
|
+
static const editWindowClosed = 'EDIT_WINDOW_CLOSED';
|
|
73
|
+
|
|
74
|
+
/// 400 from calendar native complete: the sign-in was started by a different member or workspace.
|
|
75
|
+
static const calendarAccountMismatch = 'CALENDAR_ACCOUNT_MISMATCH';
|
|
76
|
+
|
|
77
|
+
/// 400 from calendar native complete: the one-time code expired or was already used; connect again.
|
|
78
|
+
static const calendarSigninExpired = 'CALENDAR_SIGNIN_EXPIRED';
|
|
79
|
+
|
|
80
|
+
/// Meeting-guest email codes (verify): expired or used, wrong (400); locked, cooling down, hourly cap (429).
|
|
81
|
+
static const guestCodeExpired = 'GUEST_CODE_EXPIRED';
|
|
82
|
+
static const guestCodeInvalid = 'GUEST_CODE_INVALID';
|
|
83
|
+
static const guestCodeLocked = 'GUEST_CODE_LOCKED';
|
|
84
|
+
static const guestCodeCooldown = 'GUEST_CODE_COOLDOWN';
|
|
85
|
+
static const guestCodeRateLimited = 'GUEST_CODE_RATE_LIMITED';
|
|
86
|
+
|
|
87
|
+
/// 400 from link create with a custom `code` the server refuses (chatta #489); the message says what to change.
|
|
88
|
+
static const linkCodeTooShort = 'LINK_CODE_TOO_SHORT';
|
|
89
|
+
static const linkCodeTooLong = 'LINK_CODE_TOO_LONG';
|
|
90
|
+
static const linkCodeInvalid = 'LINK_CODE_INVALID';
|
|
91
|
+
static const linkCodeReserved = 'LINK_CODE_RESERVED';
|
|
92
|
+
static const linkCodeTaken = 'LINK_CODE_TAKEN';
|
|
93
|
+
static const linkCodeErrors = [linkCodeTooShort, linkCodeTooLong, linkCodeInvalid, linkCodeReserved, linkCodeTaken];
|
|
94
|
+
static const linkCodeMin = 3;
|
|
95
|
+
static const linkCodeMax = 40;
|
|
96
|
+
|
|
97
|
+
/// Part of the message when an API key with allowed origins is used from another site (HTTP 403, socket connect_error).
|
|
98
|
+
static const apiKeyOriginErrorMarker = "isn't allowed from";
|
|
99
|
+
|
|
100
|
+
/// Most origins one API key can list.
|
|
101
|
+
static const apiKeyMaxOrigins = 20;
|
|
102
|
+
|
|
103
|
+
/// True for a refused custom link address code.
|
|
104
|
+
static bool isLinkCodeError(String? code) => code != null && linkCodeErrors.contains(code);
|
|
105
|
+
|
|
106
|
+
/// True for the error raised when an API key is used from a site that is not on its allowed origins.
|
|
107
|
+
static bool isApiKeyOriginError(String? message) => message != null && message.contains(apiKeyOriginErrorMarker);
|
|
108
|
+
|
|
109
|
+
/// The same refusals' messages, for servers older than chatta #396 that send no code.
|
|
110
|
+
static const planNotFoundMessage = 'Plan not found.';
|
|
111
|
+
static const planNotAvailableMessage = 'This plan is not available.';
|
|
112
|
+
static const planTeamActivatedMessage = 'This plan is activated by the LiveChatta team. Contact support to switch to it.';
|
|
113
|
+
|
|
114
|
+
static final RegExp _serverCode = RegExp(r'^[A-Z][A-Z0-9_]{2,47}$');
|
|
115
|
+
|
|
116
|
+
/// The `code` of an error body, only when it is UPPER_SNAKE (same rule as the backend).
|
|
117
|
+
static String? fromBody(String body) {
|
|
118
|
+
try {
|
|
119
|
+
final json = jsonDecode(body);
|
|
120
|
+
final code = json is Map ? json['code'] : null;
|
|
121
|
+
return code is String && _serverCode.hasMatch(code) ? code : null;
|
|
122
|
+
} catch (_) {
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
class LiveChattaHttpAPI {
|
|
129
|
+
final String baseUrl;
|
|
130
|
+
final String apiKey;
|
|
131
|
+
final bool debug;
|
|
132
|
+
final http.Client _client;
|
|
133
|
+
final int _maxRetries = 2;
|
|
134
|
+
final Duration _timeout = const Duration(seconds: 30);
|
|
135
|
+
|
|
136
|
+
/// Owner account token (JWT) for owner-console methods; keep it in secure storage.
|
|
137
|
+
String? ownerToken;
|
|
138
|
+
|
|
139
|
+
/// Chat-member token (JWT, e.g. from the embed's onLoginSuccess) for member routes.
|
|
140
|
+
String? memberToken;
|
|
141
|
+
|
|
142
|
+
static final RegExp _visitorId = RegExp(r'^[A-Za-z0-9_-]{8,64}$');
|
|
143
|
+
|
|
144
|
+
String get _rootUrl =>
|
|
145
|
+
baseUrl.endsWith('/api/v1/external') ? baseUrl.substring(0, baseUrl.length - 16) : baseUrl;
|
|
146
|
+
|
|
147
|
+
LiveChattaHttpAPI({
|
|
148
|
+
required this.baseUrl,
|
|
149
|
+
required this.apiKey,
|
|
150
|
+
this.debug = false,
|
|
151
|
+
http.Client? client,
|
|
152
|
+
}) : _client = client ?? http.Client();
|
|
153
|
+
|
|
154
|
+
// ===================
|
|
155
|
+
// MEMBERS
|
|
156
|
+
// ===================
|
|
157
|
+
|
|
158
|
+
/// Register multiple members at once (up to 100). A taken `handle` gets the next free `-N`; the response shows the final one.
|
|
159
|
+
Future<Map<String, dynamic>> registerMembers(Map<String, dynamic> payload) =>
|
|
160
|
+
_post('/members', body: payload);
|
|
161
|
+
|
|
162
|
+
/// Register a single member. A taken `handle` gets the next free `-N`; the response shows the final one.
|
|
163
|
+
Future<Map<String, dynamic>> registerMember(Map<String, dynamic> payload) =>
|
|
164
|
+
_post('/members/single', body: payload);
|
|
165
|
+
|
|
166
|
+
/// List members with optional filters
|
|
167
|
+
Future<Map<String, dynamic>> listMembers({Map<String, String>? query}) =>
|
|
168
|
+
_get('/members', query: query);
|
|
169
|
+
|
|
170
|
+
/// Get a member by ID or username
|
|
171
|
+
Future<Map<String, dynamic>> getMember(String memberIdOrUsername) =>
|
|
172
|
+
_get('/members/$memberIdOrUsername');
|
|
173
|
+
|
|
174
|
+
// ===================
|
|
175
|
+
// CHAT LINKS
|
|
176
|
+
// ===================
|
|
177
|
+
|
|
178
|
+
/// Create a new chat link; mode? (standard|support|creator|school|community|tech|public|private|webinar). Then setLinkMode applies the full preset
|
|
179
|
+
Future<Map<String, dynamic>> createChatLink(Map<String, dynamic> payload) =>
|
|
180
|
+
_post('/chat-links', body: payload);
|
|
181
|
+
|
|
182
|
+
/// List chat links with optional filters
|
|
183
|
+
Future<Map<String, dynamic>> listChatLinks({Map<String, String>? query}) =>
|
|
184
|
+
_get('/chat-links', query: query);
|
|
185
|
+
|
|
186
|
+
/// Get a chat link by ID
|
|
187
|
+
Future<Map<String, dynamic>> getChatLink(String linkId) =>
|
|
188
|
+
_get('/chat-links/$linkId');
|
|
189
|
+
|
|
190
|
+
/// Update a chat link; `settings` merges key by key (maxMembers, allow*, welcomeMessage, defaultLayout, hideRunsOn), other keys are dropped
|
|
191
|
+
Future<Map<String, dynamic>> updateChatLink(String linkId, Map<String, dynamic> payload) =>
|
|
192
|
+
_request('PATCH', '/chat-links/$linkId', body: payload);
|
|
193
|
+
|
|
194
|
+
// ===================
|
|
195
|
+
// CONVERSATIONS
|
|
196
|
+
// ===================
|
|
197
|
+
|
|
198
|
+
/// Create a conversation within a chat link
|
|
199
|
+
Future<Map<String, dynamic>> createConversation(String linkId, Map<String, dynamic> payload) =>
|
|
200
|
+
_post('/chat-links/$linkId/conversations', body: payload);
|
|
201
|
+
|
|
202
|
+
/// Get a member's conversations
|
|
203
|
+
Future<Map<String, dynamic>> getMemberConversations(String memberId, {Map<String, String>? query}) =>
|
|
204
|
+
_get('/members/$memberId/conversations', query: query);
|
|
205
|
+
|
|
206
|
+
/// Get users in a conversation
|
|
207
|
+
Future<Map<String, dynamic>> getConversationUsers(String conversationId, {Map<String, String>? query}) =>
|
|
208
|
+
_get('/conversations/$conversationId/users', query: query);
|
|
209
|
+
|
|
210
|
+
/// Public channels and groups only (no DMs, private groups, support groups or meetings); 400 for an expired or off link.
|
|
211
|
+
Future<Map<String, dynamic>> listPublicConversations(String linkCode, {Map<String, String>? query}) =>
|
|
212
|
+
_get('/public/$linkCode/conversations', query: query);
|
|
213
|
+
|
|
214
|
+
// ===================
|
|
215
|
+
// MESSAGES
|
|
216
|
+
// ===================
|
|
217
|
+
|
|
218
|
+
/// Get messages in a conversation
|
|
219
|
+
Future<Map<String, dynamic>> getMessages(
|
|
220
|
+
String memberId,
|
|
221
|
+
String conversationId, {
|
|
222
|
+
Map<String, String>? query,
|
|
223
|
+
}) => _get('/members/$memberId/conversations/$conversationId/messages', query: query);
|
|
224
|
+
|
|
225
|
+
/// Send a message via HTTP. Prefer sendMessageTyped (livechatta_typed.dart).
|
|
226
|
+
@Deprecated('Use sendMessageTyped for a typed request and result.')
|
|
227
|
+
Future<Map<String, dynamic>> sendMessage(Map<String, dynamic> payload) =>
|
|
228
|
+
_post('/chats/messages/send', body: payload);
|
|
229
|
+
|
|
230
|
+
/// Messages sent by the key owner, newest first, excluding scheduled and thread children. Prefer listSentMessagesTyped.
|
|
231
|
+
@Deprecated('Use listSentMessagesTyped for typed messages.')
|
|
232
|
+
Future<Map<String, dynamic>> listSentMessages({Map<String, String>? query}) =>
|
|
233
|
+
_get('/chats/messages', query: query);
|
|
234
|
+
|
|
235
|
+
/// Cancel (soft-delete) a scheduled message; body must carry conversationId.
|
|
236
|
+
Future<Map<String, dynamic>> cancelScheduledMessage(String messageId, String conversationId) =>
|
|
237
|
+
_request('DELETE', '/chats/messages/$messageId', body: {'conversationId': conversationId});
|
|
238
|
+
|
|
239
|
+
/// Reschedule a scheduled message; body needs a future scheduledAt and conversationId.
|
|
240
|
+
Future<Map<String, dynamic>> rescheduleMessage(String messageId, String conversationId, String scheduledAt) =>
|
|
241
|
+
_request('PATCH', '/chats/messages/$messageId', body: {'scheduledAt': scheduledAt, 'conversationId': conversationId});
|
|
242
|
+
|
|
243
|
+
// ===================
|
|
244
|
+
// PUSH NOTIFICATIONS
|
|
245
|
+
// ===================
|
|
246
|
+
|
|
247
|
+
/// Send a push notification
|
|
248
|
+
Future<Map<String, dynamic>> sendPushNotification(Map<String, dynamic> payload) =>
|
|
249
|
+
_post('/chats/push-notification', body: payload);
|
|
250
|
+
|
|
251
|
+
// ===================
|
|
252
|
+
// EXPORTS
|
|
253
|
+
// ===================
|
|
254
|
+
|
|
255
|
+
/// Export chat data
|
|
256
|
+
Future<Map<String, dynamic>> exportChat(Map<String, dynamic> payload) =>
|
|
257
|
+
_post('/chats/exports', body: payload);
|
|
258
|
+
|
|
259
|
+
/// Get exports list
|
|
260
|
+
Future<Map<String, dynamic>> getExports({Map<String, String>? query}) =>
|
|
261
|
+
_get('/chats/exports', query: query);
|
|
262
|
+
|
|
263
|
+
Future<Map<String, dynamic>> getWebinarRegistrations(String conversationId) =>
|
|
264
|
+
_get('/chats/conversations/$conversationId/webinar/registrations');
|
|
265
|
+
|
|
266
|
+
// ===================
|
|
267
|
+
// CANNED RESPONSES
|
|
268
|
+
// ===================
|
|
269
|
+
|
|
270
|
+
Future<Map<String, dynamic>> getCannedResponses() => _get('/chats/canned-responses');
|
|
271
|
+
|
|
272
|
+
Future<Map<String, dynamic>> createCannedResponse(Map<String, dynamic> payload) =>
|
|
273
|
+
_post('/chats/canned-responses', body: payload);
|
|
274
|
+
|
|
275
|
+
Future<Map<String, dynamic>> updateCannedResponse(String id, Map<String, dynamic> payload) =>
|
|
276
|
+
_request('PATCH', '/chats/canned-responses/$id', body: payload);
|
|
277
|
+
|
|
278
|
+
/// Backend returns { success: true }, not a { status } envelope.
|
|
279
|
+
Future<Map<String, dynamic>> deleteCannedResponse(String id) =>
|
|
280
|
+
_request('DELETE', '/chats/canned-responses/$id');
|
|
281
|
+
|
|
282
|
+
/// Count one use when a composer inserts the reply (feeds the dashboard "Used" column).
|
|
283
|
+
Future<Map<String, dynamic>> markCannedResponseUsed(String id) =>
|
|
284
|
+
_post('/chats/canned-responses/${Uri.encodeComponent(id)}/used', body: const {});
|
|
285
|
+
|
|
286
|
+
// ===================
|
|
287
|
+
// WEBHOOKS
|
|
288
|
+
// ===================
|
|
289
|
+
|
|
290
|
+
Future<Map<String, dynamic>> getWebhooks({Map<String, String>? query}) =>
|
|
291
|
+
_get('/chats/webhooks', query: query);
|
|
292
|
+
|
|
293
|
+
Future<Map<String, dynamic>> getWebhook(String webhookId) => _get('/chats/webhooks/$webhookId');
|
|
294
|
+
|
|
295
|
+
Future<Map<String, dynamic>> createWebhook(Map<String, dynamic> payload) =>
|
|
296
|
+
_post('/chats/webhooks', body: payload);
|
|
297
|
+
|
|
298
|
+
Future<Map<String, dynamic>> updateWebhook(String webhookId, Map<String, dynamic> payload) =>
|
|
299
|
+
_request('PATCH', '/chats/webhooks/$webhookId', body: payload);
|
|
300
|
+
|
|
301
|
+
/// Backend returns { success: true }, not a { status } envelope.
|
|
302
|
+
Future<Map<String, dynamic>> deleteWebhook(String webhookId) =>
|
|
303
|
+
_request('DELETE', '/chats/webhooks/$webhookId');
|
|
304
|
+
|
|
305
|
+
// ===================
|
|
306
|
+
// INCOMING WEBHOOKS
|
|
307
|
+
// ===================
|
|
308
|
+
|
|
309
|
+
/// 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)
|
|
310
|
+
Future<Map<String, dynamic>> listIncomingWebhooks(String conversationId, {String? status, int? limit, String? nextCursor}) =>
|
|
311
|
+
_request('GET', '/chats/conversations/${Uri.encodeComponent(conversationId)}/incoming-webhooks', query: _incomingHookQuery(status, limit, nextCursor));
|
|
312
|
+
|
|
313
|
+
/// API key; make a hook from { name, botName?, botAvatar? }: the result carries the one-time url, store it now (never retried)
|
|
314
|
+
Future<Map<String, dynamic>> createIncomingWebhook(String conversationId, Map<String, dynamic> payload) =>
|
|
315
|
+
_request('POST', '/chats/conversations/${Uri.encodeComponent(conversationId)}/incoming-webhooks', body: payload, retry: false);
|
|
316
|
+
|
|
317
|
+
/// API key; rename a hook or change the name and picture of its posts; the url does not change
|
|
318
|
+
Future<Map<String, dynamic>> updateIncomingWebhook(String conversationId, String hookId, Map<String, dynamic> payload) => _request(
|
|
319
|
+
'PATCH',
|
|
320
|
+
'/chats/conversations/${Uri.encodeComponent(conversationId)}/incoming-webhooks/${Uri.encodeComponent(hookId)}',
|
|
321
|
+
body: payload,
|
|
322
|
+
retry: false,
|
|
323
|
+
);
|
|
324
|
+
|
|
325
|
+
/// API key; swap the secret: the old url answers 404 at once and the result carries the new one-time url
|
|
326
|
+
Future<Map<String, dynamic>> regenerateIncomingWebhook(String conversationId, String hookId) => _request(
|
|
327
|
+
'POST',
|
|
328
|
+
'/chats/conversations/${Uri.encodeComponent(conversationId)}/incoming-webhooks/${Uri.encodeComponent(hookId)}/regenerate',
|
|
329
|
+
body: {},
|
|
330
|
+
retry: false,
|
|
331
|
+
);
|
|
332
|
+
|
|
333
|
+
/// API key; stop a hook for good (its url answers 404); messages it posted stay
|
|
334
|
+
Future<Map<String, dynamic>> revokeIncomingWebhook(String conversationId, String hookId) => _request(
|
|
335
|
+
'DELETE',
|
|
336
|
+
'/chats/conversations/${Uri.encodeComponent(conversationId)}/incoming-webhooks/${Uri.encodeComponent(hookId)}',
|
|
337
|
+
retry: false,
|
|
338
|
+
);
|
|
339
|
+
|
|
340
|
+
Map<String, String>? _incomingHookQuery(String? status, int? limit, String? nextCursor) {
|
|
341
|
+
final q = <String, String>{if (status != null) 'status': status, if (nextCursor != null) 'nextCursor': nextCursor, if (limit != null) 'limit': '$limit'};
|
|
342
|
+
return q.isEmpty ? null : q;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// ===================
|
|
346
|
+
// TRANSLATION
|
|
347
|
+
// ===================
|
|
348
|
+
|
|
349
|
+
Future<Map<String, dynamic>> translateMessage(String messageId, String targetLanguage) => _post(
|
|
350
|
+
'/chats/translate',
|
|
351
|
+
body: {'messageId': messageId, 'targetLanguage': targetLanguage},
|
|
352
|
+
);
|
|
353
|
+
|
|
354
|
+
// ===================
|
|
355
|
+
// CHAT USER PROFILE
|
|
356
|
+
// ===================
|
|
357
|
+
|
|
358
|
+
/// The signed-in chat user, incl. hasBusinessAccount.
|
|
359
|
+
Future<Map<String, dynamic>> getChatUserProfile() => _get('/chat-users/me');
|
|
360
|
+
|
|
361
|
+
Future<Map<String, dynamic>> updateChatUserProfile(Map<String, dynamic> payload) =>
|
|
362
|
+
_request('PATCH', '/chat-users/me', body: payload);
|
|
363
|
+
|
|
364
|
+
Future<Map<String, dynamic>> getHandleEditInfo() => _get('/chat-users/me/handle-edits');
|
|
365
|
+
|
|
366
|
+
// ===================
|
|
367
|
+
// ADMIN REPLY
|
|
368
|
+
// ===================
|
|
369
|
+
|
|
370
|
+
Future<Map<String, dynamic>> sendAdminReply(Map<String, dynamic> payload) =>
|
|
371
|
+
_post('/chats/messages/admin-reply', body: payload);
|
|
372
|
+
|
|
373
|
+
// ===================
|
|
374
|
+
// SUGGESTED CANNED RESPONSES
|
|
375
|
+
// ===================
|
|
376
|
+
|
|
377
|
+
Future<Map<String, dynamic>> getCannedResponseSuggested({String? category}) =>
|
|
378
|
+
_get('/chats/canned-responses/suggested', query: category != null ? {'category': category} : null);
|
|
379
|
+
|
|
380
|
+
/// Clones the suggestion into a real canned response and returns the created CannedResponse.
|
|
381
|
+
Future<Map<String, dynamic>> useSuggestedCannedResponse(String suggestedId) =>
|
|
382
|
+
_post('/chats/canned-responses/use-suggested', body: {'suggestedId': suggestedId});
|
|
383
|
+
|
|
384
|
+
// ===================
|
|
385
|
+
// GLOBAL SEARCH
|
|
386
|
+
// ===================
|
|
387
|
+
|
|
388
|
+
Future<Map<String, dynamic>> globalSearch(String q) => _get('/chats/global-search', query: {'q': q});
|
|
389
|
+
|
|
390
|
+
// ===================
|
|
391
|
+
// BULK EXPORT
|
|
392
|
+
// ===================
|
|
393
|
+
|
|
394
|
+
Future<Map<String, dynamic>> bulkExportChat(Map<String, dynamic> payload) =>
|
|
395
|
+
_post('/chats/conversations/bulk-export', body: payload);
|
|
396
|
+
|
|
397
|
+
// ===================
|
|
398
|
+
// EXTERNAL WORKSPACE INFO (no auth required)
|
|
399
|
+
// ===================
|
|
400
|
+
|
|
401
|
+
Future<Map<String, dynamic>> getLinkWorkspaceInfo(String code) => _get('/chat-links/$code/info');
|
|
402
|
+
|
|
403
|
+
// ===================
|
|
404
|
+
// APP VERSION (no auth required)
|
|
405
|
+
// ===================
|
|
406
|
+
|
|
407
|
+
/// transport base is already .../api/v1/external; the version controller lives at .../external/version.
|
|
408
|
+
Future<Map<String, dynamic>> getAppVersion() => _get('/version');
|
|
409
|
+
|
|
410
|
+
// ===================
|
|
411
|
+
// INTERNAL
|
|
412
|
+
// ===================
|
|
413
|
+
|
|
414
|
+
// ===================
|
|
415
|
+
// CUSTOM EMOJI & STICKERS (owner console — needs ownerToken)
|
|
416
|
+
// ===================
|
|
417
|
+
|
|
418
|
+
/// payload: {'kind': 'emoji'|'sticker', 'shortcode': …, 'image': 'data:image/png;base64,…'}
|
|
419
|
+
Future<Map<String, dynamic>> createLinkEmoji(String linkId, Map<String, dynamic> payload) =>
|
|
420
|
+
_owner('POST', '/chats/links/${Uri.encodeComponent(linkId)}/emojis', body: payload);
|
|
421
|
+
|
|
422
|
+
/// query: kind, enabled ('0'|'1'), nextCursor, prevCursor, limit (≤100)
|
|
423
|
+
Future<Map<String, dynamic>> listLinkEmojis(String linkId, {Map<String, String>? query}) =>
|
|
424
|
+
_owner('GET', '/chats/links/${Uri.encodeComponent(linkId)}/emojis', query: query);
|
|
425
|
+
|
|
426
|
+
/// payload: {'shortcode'?: …, 'enabled'?: bool}
|
|
427
|
+
Future<Map<String, dynamic>> updateLinkEmoji(String linkId, String emojiId, Map<String, dynamic> payload) =>
|
|
428
|
+
_owner('PATCH', '/chats/links/${Uri.encodeComponent(linkId)}/emojis/${Uri.encodeComponent(emojiId)}', body: payload);
|
|
429
|
+
|
|
430
|
+
Future<Map<String, dynamic>> enableLinkEmoji(String linkId, String emojiId) =>
|
|
431
|
+
_owner('POST', '/chats/links/${Uri.encodeComponent(linkId)}/emojis/${Uri.encodeComponent(emojiId)}/enable');
|
|
432
|
+
|
|
433
|
+
Future<Map<String, dynamic>> disableLinkEmoji(String linkId, String emojiId) =>
|
|
434
|
+
_owner('POST', '/chats/links/${Uri.encodeComponent(linkId)}/emojis/${Uri.encodeComponent(emojiId)}/disable');
|
|
435
|
+
|
|
436
|
+
Future<Map<String, dynamic>> deleteLinkEmoji(String linkId, String emojiId) =>
|
|
437
|
+
_owner('DELETE', '/chats/links/${Uri.encodeComponent(linkId)}/emojis/${Uri.encodeComponent(emojiId)}');
|
|
438
|
+
|
|
439
|
+
/// Public member pack (GET /in/:linkCode/emoji-pack, no auth).
|
|
440
|
+
Future<Map<String, dynamic>> getLinkEmojiPack(String linkCode) =>
|
|
441
|
+
_request('GET', '/in/${Uri.encodeComponent(linkCode)}/emoji-pack', root: _rootUrl, auth: 'none');
|
|
442
|
+
|
|
443
|
+
// ===================
|
|
444
|
+
// POSTS: DRAFTS, SCHEDULE, PUBLISH (owner console — needs ownerToken)
|
|
445
|
+
// ===================
|
|
446
|
+
|
|
447
|
+
/// Owner POST /posts; payload may include 'scheduledAt' (ISO), 'asDraft', 'allowReplies', 'background' (STORY: ink|brand|lagoon|sun), 'visibility' (LINK_MEMBERS|PUBLIC|FOLLOWERS).
|
|
448
|
+
Future<Map<String, dynamic>> createPost(Map<String, dynamic> payload) => _owner('POST', '/posts', body: payload);
|
|
449
|
+
|
|
450
|
+
/// query: postByStatuses ('SCHEDULED'|'DRAFT'|…), postByTypes, nextCursor, limit
|
|
451
|
+
Future<Map<String, dynamic>> listPosts({Map<String, String>? query}) => _owner('GET', '/posts', query: query);
|
|
452
|
+
|
|
453
|
+
/// payload: {'scheduledAt': ISO, 'expiresAt'?: ISO}
|
|
454
|
+
Future<Map<String, dynamic>> schedulePost(String postId, Map<String, dynamic> payload) =>
|
|
455
|
+
_owner('POST', '/posts/${Uri.encodeComponent(postId)}/schedule', body: payload);
|
|
456
|
+
|
|
457
|
+
Future<Map<String, dynamic>> publishPost(String postId) =>
|
|
458
|
+
_owner('POST', '/posts/${Uri.encodeComponent(postId)}/publish');
|
|
459
|
+
|
|
460
|
+
Future<Map<String, dynamic>> cancelPostSchedule(String postId) =>
|
|
461
|
+
_owner('POST', '/posts/${Uri.encodeComponent(postId)}/cancel-schedule');
|
|
462
|
+
|
|
463
|
+
// ===================
|
|
464
|
+
// PROMO ANALYTICS
|
|
465
|
+
// ===================
|
|
466
|
+
|
|
467
|
+
/// 30-day + lifetime stats for a PROMOTION post (owner console — needs ownerToken).
|
|
468
|
+
Future<Map<String, dynamic>> getPromoAnalytics(String postId) =>
|
|
469
|
+
_owner('GET', '/posts/${Uri.encodeComponent(postId)}/analytics');
|
|
470
|
+
|
|
471
|
+
/// Public CTA click; call before opening the returned 'url'. visitorId: [A-Za-z0-9_-]{8,64}.
|
|
472
|
+
Future<Map<String, dynamic>> trackPromoClick(String postId, {String? visitorId}) => _request(
|
|
473
|
+
'POST',
|
|
474
|
+
'/promos/${Uri.encodeComponent(postId)}/click',
|
|
475
|
+
body: visitorId != null && _visitorId.hasMatch(visitorId) ? {'visitorId': visitorId} : <String, dynamic>{},
|
|
476
|
+
root: '$_rootUrl/api/v1',
|
|
477
|
+
auth: 'none',
|
|
478
|
+
retry: false,
|
|
479
|
+
);
|
|
480
|
+
|
|
481
|
+
// ===================
|
|
482
|
+
// CHAT FEATURES — member = memberToken; user = memberToken, else ownerToken; owner = ownerToken
|
|
483
|
+
// ===================
|
|
484
|
+
|
|
485
|
+
/// Seen-by / delivered list (sender or conversation admin; owner org-scoped).
|
|
486
|
+
Future<Map<String, dynamic>> getMessageInfo(String conversationId, String messageId, {Map<String, String>? query}) =>
|
|
487
|
+
_userRoute('GET', '/chats/conversations/${Uri.encodeComponent(conversationId)}/messages/${Uri.encodeComponent(messageId)}/info', query: query);
|
|
488
|
+
|
|
489
|
+
/// A message's edit history (prior versions + current), gated by editHistoryAdminsOnly
|
|
490
|
+
Future<Map<String, dynamic>> getMessageEditHistory(String conversationId, String messageId) =>
|
|
491
|
+
_userRoute('GET', '/chats/conversations/${Uri.encodeComponent(conversationId)}/messages/${Uri.encodeComponent(messageId)}/history');
|
|
492
|
+
|
|
493
|
+
/// Conversation admins: export to your own account email. format: 'CSV' | 'PDF' | 'JSON' | 'ZIP'.
|
|
494
|
+
Future<Map<String, dynamic>> exportConversationAsAdmin(String conversationId, {String? format}) =>
|
|
495
|
+
_member('POST', '/chats/conversations/${Uri.encodeComponent(conversationId)}/member-export',
|
|
496
|
+
body: {if (format != null) 'format': format});
|
|
497
|
+
|
|
498
|
+
/// body: { format?, scope? ('mine'|'all'), includeMedia?, from?, to? (ISO or YYYY-MM-DD), emailMe? }; returns { exportId, email, scope }
|
|
499
|
+
Future<Map<String, dynamic>> exportConversationAsMember(String conversationId, Map<String, dynamic> payload) =>
|
|
500
|
+
_member('POST', '/chats/conversations/${Uri.encodeComponent(conversationId)}/member-export', body: payload);
|
|
501
|
+
|
|
502
|
+
/// Your own member export: { exportId, status, format, totalMessages, downloadUrl, error }
|
|
503
|
+
Future<Map<String, dynamic>> getMemberExportStatus(String conversationId, String exportId) => _member('GET',
|
|
504
|
+
'/chats/conversations/${Uri.encodeComponent(conversationId)}/member-export/${Uri.encodeComponent(exportId)}');
|
|
505
|
+
|
|
506
|
+
/// ownerToken; body: { email, format?, includeMedia?, from?, to? }: { success, exportId, message }
|
|
507
|
+
Future<Map<String, dynamic>> exportConversationAsOwner(String conversationId, Map<String, dynamic> payload) =>
|
|
508
|
+
_owner('POST', '/chats/conversations/${Uri.encodeComponent(conversationId)}/export', body: payload);
|
|
509
|
+
|
|
510
|
+
/// body: { duration: 1h|8h|1w|forever|off }
|
|
511
|
+
Future<Map<String, dynamic>> muteConversation(String conversationId, Map<String, dynamic> payload) =>
|
|
512
|
+
_member('POST', '/chats/conversations/${Uri.encodeComponent(conversationId)}/mute', body: payload);
|
|
513
|
+
|
|
514
|
+
/// Your quiet hours plus `account` (linked business window, or null).
|
|
515
|
+
/// Every unsent draft this member has, for cross-device sync on load → { drafts }
|
|
516
|
+
Future<Map<String, dynamic>> getDrafts() => _member('GET', '/chats/drafts');
|
|
517
|
+
|
|
518
|
+
Future<Map<String, dynamic>> getQuietHours() =>
|
|
519
|
+
_member('GET', '/chats/settings/quiet-hours');
|
|
520
|
+
|
|
521
|
+
/// body: { enabled, start: HH:mm, end: HH:mm, timezone }
|
|
522
|
+
Future<Map<String, dynamic>> setQuietHours(Map<String, dynamic> payload) =>
|
|
523
|
+
_member('POST', '/chats/settings/quiet-hours', body: payload);
|
|
524
|
+
|
|
525
|
+
/// body: { conversationId, messageId, kind, preset?, remindAt?, note? }
|
|
526
|
+
Future<Map<String, dynamic>> createReminder(Map<String, dynamic> payload) =>
|
|
527
|
+
_member('POST', '/chats/reminders', body: payload);
|
|
528
|
+
|
|
529
|
+
/// query: kind, nextCursor, limit (≤50) — pending only.
|
|
530
|
+
Future<Map<String, dynamic>> listReminders({Map<String, String>? query}) =>
|
|
531
|
+
_member('GET', '/chats/reminders', query: query);
|
|
532
|
+
|
|
533
|
+
/// Cancel a reminder.
|
|
534
|
+
Future<Map<String, dynamic>> cancelReminder(String reminderId) =>
|
|
535
|
+
_member('DELETE', '/chats/reminders/${Uri.encodeComponent(reminderId)}');
|
|
536
|
+
|
|
537
|
+
/// Mark a reminder / read-later item done.
|
|
538
|
+
Future<Map<String, dynamic>> completeReminder(String reminderId) =>
|
|
539
|
+
_member('POST', '/chats/reminders/${Uri.encodeComponent(reminderId)}/done');
|
|
540
|
+
|
|
541
|
+
/// Conversation permissions + slow mode.
|
|
542
|
+
Future<Map<String, dynamic>> getConversationPermissions(String conversationId) =>
|
|
543
|
+
_userRoute('GET', '/chats/conversations/${Uri.encodeComponent(conversationId)}/permissions');
|
|
544
|
+
|
|
545
|
+
/// Conversation admin or owner; body: membersCan*?, slowModeSeconds?, allowScreenshots?, isPrivate?
|
|
546
|
+
Future<Map<String, dynamic>> updateConversationPermissions(String conversationId, Map<String, dynamic> payload) =>
|
|
547
|
+
_userRoute('PATCH', '/chats/conversations/${Uri.encodeComponent(conversationId)}/permissions', body: payload);
|
|
548
|
+
|
|
549
|
+
/// { enabled, audio, video } — hide Transcribe when disabled.
|
|
550
|
+
Future<Map<String, dynamic>> getTranscribeAvailability() =>
|
|
551
|
+
_userRoute('GET', '/chats/transcription/availability');
|
|
552
|
+
|
|
553
|
+
/// Failures come back as transcript.errorCode.
|
|
554
|
+
Future<Map<String, dynamic>> transcribeMessage(String conversationId, String messageId) =>
|
|
555
|
+
_userRoute('POST', '/chats/conversations/${Uri.encodeComponent(conversationId)}/messages/${Uri.encodeComponent(messageId)}/transcribe');
|
|
556
|
+
|
|
557
|
+
/// Current transcript.
|
|
558
|
+
Future<Map<String, dynamic>> getTranscript(String conversationId, String messageId) =>
|
|
559
|
+
_userRoute('GET', '/chats/conversations/${Uri.encodeComponent(conversationId)}/messages/${Uri.encodeComponent(messageId)}/transcript');
|
|
560
|
+
|
|
561
|
+
/// Summary (or errorCode).
|
|
562
|
+
Future<Map<String, dynamic>> summarizeTranscript(String conversationId, String messageId) =>
|
|
563
|
+
_userRoute('POST', '/chats/conversations/${Uri.encodeComponent(conversationId)}/messages/${Uri.encodeComponent(messageId)}/transcript/summary');
|
|
564
|
+
|
|
565
|
+
/// body: { targetLanguage: "fr" }
|
|
566
|
+
Future<Map<String, dynamic>> translateTranscript(String conversationId, String messageId, Map<String, dynamic> payload) =>
|
|
567
|
+
_userRoute('POST', '/chats/conversations/${Uri.encodeComponent(conversationId)}/messages/${Uri.encodeComponent(messageId)}/transcript/translate', body: payload);
|
|
568
|
+
|
|
569
|
+
/// body: { initialMediaKind?: audio|video } — then sock().joinHop
|
|
570
|
+
Future<Map<String, dynamic>> startHuddle(String conversationId, Map<String, dynamic> payload) =>
|
|
571
|
+
_member('POST', '/hops/huddles/${Uri.encodeComponent(conversationId)}/start', body: payload);
|
|
572
|
+
|
|
573
|
+
/// Huddle status.
|
|
574
|
+
Future<Map<String, dynamic>> getHuddle(String conversationId) =>
|
|
575
|
+
_member('GET', '/hops/huddles/${Uri.encodeComponent(conversationId)}');
|
|
576
|
+
|
|
577
|
+
/// Host/co-host or conversation admin.
|
|
578
|
+
Future<Map<String, dynamic>> endHuddle(String conversationId) =>
|
|
579
|
+
_member('POST', '/hops/huddles/${Uri.encodeComponent(conversationId)}/end');
|
|
580
|
+
|
|
581
|
+
/// Owner; body: { enabled }
|
|
582
|
+
Future<Map<String, dynamic>> setLinkAutoTranscribe(String linkId, Map<String, dynamic> payload) =>
|
|
583
|
+
_owner('POST', '/chats/links/${Uri.encodeComponent(linkId)}/auto-transcribe', body: payload);
|
|
584
|
+
|
|
585
|
+
/// Owner; body: { enabled }
|
|
586
|
+
Future<Map<String, dynamic>> setLinkAgentInbox(String linkId, Map<String, dynamic> payload) =>
|
|
587
|
+
_owner('POST', '/chats/links/${Uri.encodeComponent(linkId)}/agent-inbox', body: payload);
|
|
588
|
+
|
|
589
|
+
/// Owner; query: lane (waiting|mine|unassigned|resolved), chatLinkId?, nextCursor, limit (≤20)
|
|
590
|
+
Future<Map<String, dynamic>> listInbox({Map<String, String>? query}) =>
|
|
591
|
+
_owner('GET', '/chats/inbox', query: query);
|
|
592
|
+
|
|
593
|
+
/// Owner; body: { assigneeId } (JSONObject.NULL / NSNull / null unassigns)
|
|
594
|
+
Future<Map<String, dynamic>> assignInbox(String conversationId, Map<String, dynamic> payload) =>
|
|
595
|
+
_owner('POST', '/chats/inbox/${Uri.encodeComponent(conversationId)}/assign', body: payload);
|
|
596
|
+
|
|
597
|
+
/// Owner; body: { status: open|waiting|resolved }
|
|
598
|
+
Future<Map<String, dynamic>> setInboxStatus(String conversationId, Map<String, dynamic> payload) =>
|
|
599
|
+
_owner('POST', '/chats/inbox/${Uri.encodeComponent(conversationId)}/status', body: payload);
|
|
600
|
+
|
|
601
|
+
/// Owner; body: { slaTargetMinutes?: int|null, topics?: [{ id?, label, tag?, assigneeId? }] (≤8) }
|
|
602
|
+
Future<Map<String, dynamic>> setLinkInboxSettings(String linkId, Map<String, dynamic> payload) =>
|
|
603
|
+
_owner('POST', '/chats/links/${Uri.encodeComponent(linkId)}/inbox-settings', body: payload);
|
|
604
|
+
|
|
605
|
+
/// Owner; body: { enabled } — offer the link in "Did you mean" suggestions
|
|
606
|
+
Future<Map<String, dynamic>> setLinkDiscoverable(String linkId, Map<String, dynamic> payload) =>
|
|
607
|
+
_owner('POST', '/chats/links/${Uri.encodeComponent(linkId)}/discoverable', body: payload);
|
|
608
|
+
|
|
609
|
+
// ===================
|
|
610
|
+
// SUPPORT CSAT
|
|
611
|
+
// ===================
|
|
612
|
+
|
|
613
|
+
/// memberToken (the conversation's customer); body { score: 1-5, comment? (≤500), ratingId? }: the rating; never retried
|
|
614
|
+
Future<Map<String, dynamic>> submitCsat(String conversationId, Map<String, dynamic> payload) =>
|
|
615
|
+
_member('POST', '/chats/conversations/${Uri.encodeComponent(conversationId)}/csat', body: payload, retry: false);
|
|
616
|
+
|
|
617
|
+
/// API key; rated requests newest first. query: from?, to? (ISO), chatLinkId?, nextCursor?, limit? (≤20): { results, nextCursor, hasMore }
|
|
618
|
+
Future<Map<String, dynamic>> listCsatRatings({Map<String, String>? query}) => _get('/chats/csat', query: query);
|
|
619
|
+
|
|
620
|
+
/// API key; query: from?, to?, chatLinkId?: { requests, responses, average, satisfiedPct, responseRatePct, agents, teams }
|
|
621
|
+
Future<Map<String, dynamic>> getCsatSummary({Map<String, String>? query}) => _get('/chats/csat/summary', query: query);
|
|
622
|
+
|
|
623
|
+
/// Owner; listCsatRatings with the owner token
|
|
624
|
+
Future<Map<String, dynamic>> listCsatRatingsAsOwner({Map<String, String>? query}) => _owner('GET', '/chats/csat', query: query);
|
|
625
|
+
|
|
626
|
+
/// Owner; getCsatSummary with the owner token
|
|
627
|
+
Future<Map<String, dynamic>> getCsatSummaryAsOwner({Map<String, String>? query}) => _owner('GET', '/chats/csat/summary', query: query);
|
|
628
|
+
|
|
629
|
+
// ===================
|
|
630
|
+
// LINK MEMBERS (owner)
|
|
631
|
+
// ===================
|
|
632
|
+
|
|
633
|
+
/// Owner; query: q?, status? (all|active|blocked|invited), limit? (≤100), nextCursor?: { results, nextCursor, hasMore, total }
|
|
634
|
+
Future<Map<String, dynamic>> getLinkMemberList(String linkId, {Map<String, String>? query}) =>
|
|
635
|
+
_owner('GET', '/chats/links/${Uri.encodeComponent(linkId)}/member-list', query: query);
|
|
636
|
+
|
|
637
|
+
/// Owner; off the invite list, and blocked if they already joined: { status: true, blocked }
|
|
638
|
+
Future<Map<String, dynamic>> revokeLinkInvite(String linkId, String memberId) =>
|
|
639
|
+
_owner('DELETE', '/chats/links/${Uri.encodeComponent(linkId)}/members/${Uri.encodeComponent(memberId)}/invite', retry: false);
|
|
640
|
+
|
|
641
|
+
/// Owner; body: { preChat: { enabled, intro, fields }, businessHours: { enabled, timezone, awayMessage, week } }
|
|
642
|
+
Future<Map<String, dynamic>> setWidgetConfig(String linkId, Map<String, dynamic> payload) =>
|
|
643
|
+
_owner('PUT', '/chats/links/${Uri.encodeComponent(linkId)}/widget', body: payload);
|
|
644
|
+
|
|
645
|
+
// ===================
|
|
646
|
+
// SUPPORT INBOX — chat-UI agents (memberToken; the server re-checks team + membership)
|
|
647
|
+
// ===================
|
|
648
|
+
|
|
649
|
+
/// { agent, userId?, teamRole?, team } — agent: false for non-team chat users
|
|
650
|
+
Future<Map<String, dynamic>> getInboxAgentProfile() => _member('GET', '/chats/agent-inbox/me');
|
|
651
|
+
|
|
652
|
+
/// query: nextCursor, limit (≤20)
|
|
653
|
+
Future<Map<String, dynamic>> listInternalNotes(String conversationId, {Map<String, String>? query}) =>
|
|
654
|
+
_member('GET', '/chats/agent-inbox/${Uri.encodeComponent(conversationId)}/internal-notes', query: query);
|
|
655
|
+
|
|
656
|
+
/// body: { message (≤3000), referenceId? } — agents only, never sent to the customer
|
|
657
|
+
Future<Map<String, dynamic>> createInternalNote(String conversationId, Map<String, dynamic> payload) =>
|
|
658
|
+
_member('POST', '/chats/agent-inbox/${Uri.encodeComponent(conversationId)}/internal-notes', body: payload);
|
|
659
|
+
|
|
660
|
+
/// Delete an internal note (own; owner/admin agents any).
|
|
661
|
+
Future<Map<String, dynamic>> deleteInternalNote(String conversationId, String noteId) =>
|
|
662
|
+
_member('DELETE', '/chats/agent-inbox/${Uri.encodeComponent(conversationId)}/internal-notes/${Uri.encodeComponent(noteId)}');
|
|
663
|
+
|
|
664
|
+
/// { inbox, slaTargetMinutes, sla, topic, tag }
|
|
665
|
+
Future<Map<String, dynamic>> getAgentInboxState(String conversationId) =>
|
|
666
|
+
_member('GET', '/chats/agent-inbox/${Uri.encodeComponent(conversationId)}/state');
|
|
667
|
+
|
|
668
|
+
/// body: { assigneeId } ({'assigneeId': null} unassigns)
|
|
669
|
+
Future<Map<String, dynamic>> agentAssignConversation(String conversationId, Map<String, dynamic> payload) =>
|
|
670
|
+
_member('POST', '/chats/agent-inbox/${Uri.encodeComponent(conversationId)}/assign', body: payload);
|
|
671
|
+
|
|
672
|
+
/// body: { status: open|waiting|resolved }
|
|
673
|
+
Future<Map<String, dynamic>> agentSetInboxStatus(String conversationId, Map<String, dynamic> payload) =>
|
|
674
|
+
_member('POST', '/chats/agent-inbox/${Uri.encodeComponent(conversationId)}/status', body: payload);
|
|
675
|
+
|
|
676
|
+
/// Customer notes; query: nextCursor, limit (≤20)
|
|
677
|
+
Future<Map<String, dynamic>> listConversationNotes(String conversationId, {Map<String, String>? query}) =>
|
|
678
|
+
_member('GET', '/chats/agent-inbox/${Uri.encodeComponent(conversationId)}/notes', query: query);
|
|
679
|
+
|
|
680
|
+
/// body: { text (≤2000) }
|
|
681
|
+
Future<Map<String, dynamic>> createConversationNote(String conversationId, Map<String, dynamic> payload) =>
|
|
682
|
+
_member('POST', '/chats/agent-inbox/${Uri.encodeComponent(conversationId)}/notes', body: payload);
|
|
683
|
+
|
|
684
|
+
/// body: { text }
|
|
685
|
+
Future<Map<String, dynamic>> updateConversationNote(String conversationId, String noteId, Map<String, dynamic> payload) =>
|
|
686
|
+
_member('PATCH', '/chats/agent-inbox/${Uri.encodeComponent(conversationId)}/notes/${Uri.encodeComponent(noteId)}', body: payload);
|
|
687
|
+
|
|
688
|
+
/// Delete a customer note.
|
|
689
|
+
Future<Map<String, dynamic>> deleteConversationNote(String conversationId, String noteId) =>
|
|
690
|
+
_member('DELETE', '/chats/agent-inbox/${Uri.encodeComponent(conversationId)}/notes/${Uri.encodeComponent(noteId)}');
|
|
691
|
+
|
|
692
|
+
/// AI summary; failures come back as errorCode (OUT_OF_AI_CREDITS|NOT_ENOUGH_MESSAGES|PROVIDER_FAILED).
|
|
693
|
+
Future<Map<String, dynamic>> getConversationSummary(String conversationId) =>
|
|
694
|
+
_member('GET', '/chats/agent-inbox/${Uri.encodeComponent(conversationId)}/summary');
|
|
695
|
+
|
|
696
|
+
/// Any member: private AI draft { draft, errorCode? } for your next message; nothing is posted.
|
|
697
|
+
Future<Map<String, dynamic>> draftConversationReply(String conversationId, {String? note}) =>
|
|
698
|
+
_member('POST', '/chats/conversations/${Uri.encodeComponent(conversationId)}/draft-reply',
|
|
699
|
+
body: note != null ? {'note': note} : <String, dynamic>{}, retry: false);
|
|
700
|
+
|
|
701
|
+
/// Agents: AI reply draft { draft, errorCode? }; spends the owner's AI credits.
|
|
702
|
+
Future<Map<String, dynamic>> getDraftReply(String conversationId) =>
|
|
703
|
+
_member('POST', '/chats/agent-inbox/${Uri.encodeComponent(conversationId)}/draft-reply');
|
|
704
|
+
|
|
705
|
+
/// body: { unreadCount (≥8 for a summary) }
|
|
706
|
+
Future<Map<String, dynamic>> getConversationCatchUp(String conversationId, Map<String, dynamic> payload) =>
|
|
707
|
+
_member('POST', '/chats/conversations/${Uri.encodeComponent(conversationId)}/catch-up', body: payload);
|
|
708
|
+
|
|
709
|
+
/// body: { topicId } — first pick wins for customers; may auto-assign
|
|
710
|
+
Future<Map<String, dynamic>> setConversationTopic(String conversationId, Map<String, dynamic> payload) =>
|
|
711
|
+
_member('POST', '/chats/conversations/${Uri.encodeComponent(conversationId)}/topic', body: payload);
|
|
712
|
+
|
|
713
|
+
/// Public (no auth): { enabled, agentsOnline, typicalReplyMinutes }
|
|
714
|
+
Future<Map<String, dynamic>> getPresenceStats(String linkCode) =>
|
|
715
|
+
_request('GET', '/in/${Uri.encodeComponent(linkCode)}/presence-stats', root: _rootUrl, auth: 'none');
|
|
716
|
+
|
|
717
|
+
// ===================
|
|
718
|
+
// CHAT CORE — my links, availability, gifts (chat-features-api.md §14)
|
|
719
|
+
// ===================
|
|
720
|
+
|
|
721
|
+
/// query: search?, status? (ACTIVE|DISABLED|EXPIRED|ARCHIVED), nextCursor?, limit? (≤20); rows carry memberCount and role (owner|admin|agent|member)
|
|
722
|
+
Future<Map<String, dynamic>> listMyChatLinks({Map<String, String>? query}) =>
|
|
723
|
+
_member('GET', '/chat-users/me/links', query: query);
|
|
724
|
+
|
|
725
|
+
/// Leave every conversation in the link (history kept) and drop it from your links: { left }
|
|
726
|
+
Future<Map<String, dynamic>> leaveMyLink(String linkId) =>
|
|
727
|
+
_member('POST', '/chat-users/me/links/${Uri.encodeComponent(linkId)}/leave');
|
|
728
|
+
|
|
729
|
+
/// 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? }
|
|
730
|
+
Future<Map<String, dynamic>> claimGuest(String guestToken) =>
|
|
731
|
+
_member('POST', '/chat-users/me/claim-guest', body: {'guestToken': guestToken}, retry: false);
|
|
732
|
+
|
|
733
|
+
/// Your push level for one link: 'all' | 'mentions' | 'off' → { chatLinkId, level }
|
|
734
|
+
Future<Map<String, dynamic>> setMyLinkNotify(String linkId, String level) =>
|
|
735
|
+
_member('PUT', '/chat-users/me/links/${Uri.encodeComponent(linkId)}/notify', body: {'level': level});
|
|
736
|
+
|
|
737
|
+
/// Teammates on one of your links, online first (limit 1–5): { results }
|
|
738
|
+
Future<Map<String, dynamic>> listLinkMembers(String chatLinkId, {int? limit}) =>
|
|
739
|
+
_member('GET', '/chat-users/me/link-members',
|
|
740
|
+
query: {'chatLinkId': chatLinkId, if (limit != null) 'limit': '$limit'});
|
|
741
|
+
|
|
742
|
+
/// ownerToken; keywords (≤10) tried on the link's last 7 days: { matched, scanned, total, capped, keywords }
|
|
743
|
+
Future<Map<String, dynamic>> testAutomationKeywords(String chatLinkId, List<String> keywords) =>
|
|
744
|
+
_owner('POST', '/chats/automations/test', body: {'chatLinkId': chatLinkId, 'keywords': keywords});
|
|
745
|
+
|
|
746
|
+
/// Public (no auth): { enabled, open, timezone, nextOpenLabel, awayMessage }
|
|
747
|
+
Future<Map<String, dynamic>> getLinkAvailability(String linkCode) =>
|
|
748
|
+
_request('GET', '/in/${Uri.encodeComponent(linkCode)}/availability', root: _rootUrl, auth: 'none');
|
|
749
|
+
|
|
750
|
+
/// body: { reference, note? (≤140) } — share a verified gift you paid for
|
|
751
|
+
Future<Map<String, dynamic>> announceGift(String conversationId, Map<String, dynamic> payload) =>
|
|
752
|
+
_member('POST', '/chats/conversations/${Uri.encodeComponent(conversationId)}/gift-announce', body: payload);
|
|
753
|
+
|
|
754
|
+
// ===================
|
|
755
|
+
// SIGNED-IN SESSIONS + ACCOUNT QUIET HOURS
|
|
756
|
+
// ===================
|
|
757
|
+
|
|
758
|
+
/// Business devices (ownerToken): { results: [{ id, browser, os, deviceType, client, country, city, createdAt, lastActiveAt, current }], currentId }
|
|
759
|
+
Future<Map<String, dynamic>> listAccountSessions() => _owner('GET', '/users/sessions');
|
|
760
|
+
|
|
761
|
+
/// { revoked: 1 }; 400 for the calling session, 404 if not yours.
|
|
762
|
+
Future<Map<String, dynamic>> revokeAccountSession(String sessionId) =>
|
|
763
|
+
_owner('DELETE', '/users/sessions/${Uri.encodeComponent(sessionId)}');
|
|
764
|
+
|
|
765
|
+
/// Sign out every other business device: { revoked }
|
|
766
|
+
Future<Map<String, dynamic>> revokeOtherAccountSessions() => _owner('POST', '/users/sessions/revoke-others');
|
|
767
|
+
|
|
768
|
+
/// Chat-user devices (memberToken); same shape as listAccountSessions.
|
|
769
|
+
Future<Map<String, dynamic>> listMySessions() => _member('GET', '/chat-users/me/sessions');
|
|
770
|
+
|
|
771
|
+
/// { revoked: 1 }; 400 for the calling session, 404 if not yours.
|
|
772
|
+
Future<Map<String, dynamic>> revokeMySession(String sessionId) =>
|
|
773
|
+
_member('DELETE', '/chat-users/me/sessions/${Uri.encodeComponent(sessionId)}');
|
|
774
|
+
|
|
775
|
+
/// Sign out every other chat-user device: { revoked }
|
|
776
|
+
Future<Map<String, dynamic>> revokeMyOtherSessions() => _member('POST', '/chat-users/me/sessions/revoke-others');
|
|
777
|
+
|
|
778
|
+
/// Business quiet hours (ownerToken): { enabled, start, end, timezone }
|
|
779
|
+
Future<Map<String, dynamic>> getAccountQuietHours() => _owner('GET', '/users/me/quiet-hours');
|
|
780
|
+
|
|
781
|
+
/// body: { enabled, start: HH:mm, end: HH:mm, timezone } — also quiets the same-e-mail chat identity
|
|
782
|
+
Future<Map<String, dynamic>> setAccountQuietHours(Map<String, dynamic> payload) =>
|
|
783
|
+
_owner('PUT', '/users/me/quiet-hours', body: payload);
|
|
784
|
+
|
|
785
|
+
// ===================
|
|
786
|
+
// SCHEDULED SEND NOW, CALL DECLINE, LINK REOPEN, STATUS, WEBHOOK TEST, PUBLIC WEBINAR
|
|
787
|
+
// ===================
|
|
788
|
+
|
|
789
|
+
/// Send one of your scheduled messages now (≤ 1 min): { _id, scheduledAt, queued: true }; 400 if already sent.
|
|
790
|
+
Future<Map<String, dynamic>> sendScheduledMessageNow(String messageId) =>
|
|
791
|
+
_member('POST', '/chats/messages/${Uri.encodeComponent(messageId)}/send-now');
|
|
792
|
+
|
|
793
|
+
/// Decline a ringing call from the lock screen (no socket): { ok: true, sessionId }
|
|
794
|
+
Future<Map<String, dynamic>> declineHopInvite(String sessionId) =>
|
|
795
|
+
_member('POST', '/hops/${Uri.encodeComponent(sessionId)}/decline');
|
|
796
|
+
|
|
797
|
+
/// Public; the call push's declineToken from the native call screen: { ok, sessionId }; 401 used / expired, 403 call ended
|
|
798
|
+
Future<Map<String, dynamic>> pushDeclineCall(String token) => _request(
|
|
799
|
+
'POST', '/hops/push-decline', body: {'token': token}, root: '$_rootUrl/api/v1', auth: 'none', retry: false);
|
|
800
|
+
|
|
801
|
+
/// Member or owner token; payload: { deviceToken?, webToken?, voipToken? (iOS hex), platform?, inlineReply? }: { success }
|
|
802
|
+
Future<Map<String, dynamic>> registerDevice(Map<String, dynamic> payload) =>
|
|
803
|
+
_userRoute('POST', '/notifications/register-device', body: payload);
|
|
804
|
+
|
|
805
|
+
/// memberToken; ring up to 50 chat users into a call you are in (socket + push): { ok, invited }
|
|
806
|
+
Future<Map<String, dynamic>> inviteToHop(String sessionId, List<String> chatUserIds) {
|
|
807
|
+
final token = memberToken;
|
|
808
|
+
if (token == null || token.isEmpty) {
|
|
809
|
+
return Future.error(LiveChattaApiError('Member token required — set api().memberToken', 401));
|
|
810
|
+
}
|
|
811
|
+
return _request('POST', '/hops/${Uri.encodeComponent(sessionId)}/invite',
|
|
812
|
+
body: {'chatUserIds': chatUserIds}, root: '$_rootUrl/api/v1', auth: 'member', retry: false);
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
/// Public "Live now · N online": { online }
|
|
816
|
+
Future<Map<String, dynamic>> getLinkOnlineCount(String linkCode) =>
|
|
817
|
+
_request('GET', '/in/${Uri.encodeComponent(linkCode)}/online-count', root: _rootUrl, auth: 'none');
|
|
818
|
+
|
|
819
|
+
/// Public one-step guest join (displayName 2–30, email optional): { chatUser, accessToken, refreshToken, expireInSeconds, chatLink }; 400 LINK_FULL / ACCOUNT_EXISTS
|
|
820
|
+
Future<Map<String, dynamic>> joinLinkAsGuest(String linkCode, String displayName, {String? email, String? meetingCode}) => _request(
|
|
821
|
+
'POST', '/in/${Uri.encodeComponent(linkCode)}/join-guest',
|
|
822
|
+
body: {
|
|
823
|
+
'displayName': displayName,
|
|
824
|
+
if (email != null && email.isNotEmpty) 'email': email,
|
|
825
|
+
if (meetingCode != null && meetingCode.isNotEmpty) 'meetingCode': meetingCode,
|
|
826
|
+
},
|
|
827
|
+
root: _rootUrl, auth: 'none', retry: false);
|
|
828
|
+
|
|
829
|
+
/// Public: a returning meeting guest's emailed 6-digit code → the same session shape as joinLinkAsGuest
|
|
830
|
+
Future<Map<String, dynamic>> verifyMeetingGuest(String linkCode, String email, String code, String meetingCode) => _request(
|
|
831
|
+
'POST', '/in/${Uri.encodeComponent(linkCode)}/join-guest/verify',
|
|
832
|
+
body: {'email': email, 'code': code, 'meetingCode': meetingCode},
|
|
833
|
+
root: _rootUrl, auth: 'none', retry: false);
|
|
834
|
+
|
|
835
|
+
/// Public: email me once when this paused link reopens: { ok: true }; 400 if the link is not paused.
|
|
836
|
+
Future<Map<String, dynamic>> notifyWhenLinkReopens(String linkCode, String email) => _request(
|
|
837
|
+
'POST', '/in/${Uri.encodeComponent(linkCode)}/notify-reopen',
|
|
838
|
+
body: {'email': email}, root: _rootUrl, auth: 'none');
|
|
839
|
+
|
|
840
|
+
/// Public status updates by email: { subscribed: true }
|
|
841
|
+
Future<Map<String, dynamic>> subscribeToStatusUpdates(String email) =>
|
|
842
|
+
_request('POST', '/health/subscribe', body: {'email': email}, root: '$_rootUrl/api/v1', auth: 'none');
|
|
843
|
+
|
|
844
|
+
/// token = the signed one from the email's unsubscribe link: { unsubscribed }
|
|
845
|
+
Future<Map<String, dynamic>> unsubscribeFromStatusUpdates(String email, String token) => _request(
|
|
846
|
+
'GET', '/health/unsubscribe',
|
|
847
|
+
query: {'email': email, 'token': token}, root: '$_rootUrl/api/v1', auth: 'none');
|
|
848
|
+
|
|
849
|
+
/// API key: one immediate webhook.test delivery: { ok, status, durationMs, error }
|
|
850
|
+
Future<Map<String, dynamic>> testWebhook(String webhookId) =>
|
|
851
|
+
_post('/chats/webhooks/${Uri.encodeComponent(webhookId)}/test');
|
|
852
|
+
|
|
853
|
+
/// Owner-console twin of testWebhook (ownerToken).
|
|
854
|
+
Future<Map<String, dynamic>> testWebhookAsOwner(String webhookId) =>
|
|
855
|
+
_owner('POST', '/chats/webhooks/${Uri.encodeComponent(webhookId)}/test');
|
|
856
|
+
|
|
857
|
+
/// ownerToken; limit 1–20 (default 10): { results: [{ id, event, code, at, attempt, ok, canRetry }] }
|
|
858
|
+
Future<Map<String, dynamic>> getWebhookDeliveries(String webhookId, {int? limit}) =>
|
|
859
|
+
_owner('GET', '/chats/webhooks/${Uri.encodeComponent(webhookId)}/deliveries',
|
|
860
|
+
query: limit == null ? null : {'limit': '$limit'});
|
|
861
|
+
|
|
862
|
+
/// ownerToken; a row with canRetry: { queued: true } (next run, ≤ 30 s)
|
|
863
|
+
Future<Map<String, dynamic>> retryWebhookDelivery(String webhookId, String deliveryId) => _owner('POST',
|
|
864
|
+
'/chats/webhooks/${Uri.encodeComponent(webhookId)}/deliveries/${Uri.encodeComponent(deliveryId)}/retry', retry: false);
|
|
865
|
+
|
|
866
|
+
/// ownerToken; new signing secret, shown once: { secret, hint }
|
|
867
|
+
Future<Map<String, dynamic>> rotateWebhookSecret(String webhookId) =>
|
|
868
|
+
_owner('POST', '/chats/webhooks/${Uri.encodeComponent(webhookId)}/rotate-secret', retry: false);
|
|
869
|
+
|
|
870
|
+
/// ownerToken; start (or extend) listening: the next deliveries are kept 30 min, last 50: { active, expiresAt, results, lastSeq }
|
|
871
|
+
Future<Map<String, dynamic>> startWebhookCapture(String webhookId) =>
|
|
872
|
+
_owner('POST', '/chats/webhooks/${Uri.encodeComponent(webhookId)}/capture', retry: false);
|
|
873
|
+
|
|
874
|
+
/// ownerToken; deliveries after sequence [after], oldest first: { active, expiresAt, lastSeq, results: [{ seq, at, event, attempt, signature, body, truncated }] }
|
|
875
|
+
Future<Map<String, dynamic>> readWebhookCapture(String webhookId, {int after = 0}) =>
|
|
876
|
+
_owner('GET', '/chats/webhooks/${Uri.encodeComponent(webhookId)}/capture', query: {'after': '$after'});
|
|
877
|
+
|
|
878
|
+
/// ownerToken; stop listening and delete what was kept: { stopped: true }
|
|
879
|
+
Future<Map<String, dynamic>> stopWebhookCapture(String webhookId) =>
|
|
880
|
+
_owner('DELETE', '/chats/webhooks/${Uri.encodeComponent(webhookId)}/capture', retry: false);
|
|
881
|
+
|
|
882
|
+
/// 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 }
|
|
883
|
+
Future<Map<String, dynamic>> listMeetings(String linkId, {String? status, int? limit, String? nextCursor}) =>
|
|
884
|
+
_owner('GET', '/hops/owner/meetings', query: _meetingQuery(linkId, status, limit, nextCursor));
|
|
885
|
+
|
|
886
|
+
/// 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
|
|
887
|
+
Future<Map<String, dynamic>> scheduleMeeting(Map<String, dynamic> payload, {String? idempotencyKey}) =>
|
|
888
|
+
_owner('POST', '/hops/owner/meetings', body: payload, retry: idempotencyKey != null, headers: _idempotencyHeader(idempotencyKey));
|
|
889
|
+
|
|
890
|
+
/// ownerToken; cancel a meeting (reason up to 300 characters), invitees are told; safe to repeat: { ok, id, status, alreadyCancelled }
|
|
891
|
+
Future<Map<String, dynamic>> cancelMeeting(String meetingId, {String? reason}) => _owner(
|
|
892
|
+
'DELETE',
|
|
893
|
+
'/hops/owner/meetings/${Uri.encodeComponent(meetingId)}',
|
|
894
|
+
query: reason == null ? null : {'reason': reason},
|
|
895
|
+
retry: false,
|
|
896
|
+
);
|
|
897
|
+
|
|
898
|
+
/// API key; same as listMeetings through /external/meetings
|
|
899
|
+
Future<Map<String, dynamic>> listMeetingsWithKey(String linkId, {String? status, int? limit, String? nextCursor}) =>
|
|
900
|
+
_request('GET', '/meetings', query: _meetingQuery(linkId, status, limit, nextCursor));
|
|
901
|
+
|
|
902
|
+
/// API key; same as scheduleMeeting through /external/meetings
|
|
903
|
+
Future<Map<String, dynamic>> scheduleMeetingWithKey(Map<String, dynamic> payload, {String? idempotencyKey}) =>
|
|
904
|
+
_request('POST', '/meetings', body: payload, retry: idempotencyKey != null, headers: _idempotencyHeader(idempotencyKey));
|
|
905
|
+
|
|
906
|
+
/// API key; same as cancelMeeting through /external/meetings
|
|
907
|
+
Future<Map<String, dynamic>> cancelMeetingWithKey(String meetingId, {String? reason}) => _request(
|
|
908
|
+
'DELETE',
|
|
909
|
+
'/meetings/${Uri.encodeComponent(meetingId)}',
|
|
910
|
+
query: reason == null ? null : {'reason': reason},
|
|
911
|
+
retry: false,
|
|
912
|
+
);
|
|
913
|
+
|
|
914
|
+
Map<String, String> _meetingQuery(String linkId, String? status, int? limit, String? nextCursor) => {
|
|
915
|
+
'linkId': linkId,
|
|
916
|
+
if (status != null) 'status': status,
|
|
917
|
+
if (nextCursor != null) 'nextCursor': nextCursor,
|
|
918
|
+
if (limit != null) 'limit': '$limit',
|
|
919
|
+
};
|
|
920
|
+
|
|
921
|
+
Map<String, String> _idempotencyHeader(String? key) =>
|
|
922
|
+
key == null || key.isEmpty ? const {} : {'Idempotency-Key': key};
|
|
923
|
+
|
|
924
|
+
/// Your links (ownerToken); query: chatLinkExpiringDays (1–365) = ACTIVE links expiring within N days, chatLinkSearch, limit, …
|
|
925
|
+
Future<Map<String, dynamic>> listAccountChatLinks({Map<String, String>? query}) =>
|
|
926
|
+
_owner('GET', '/chats/links', query: query);
|
|
927
|
+
|
|
928
|
+
/// ownerToken; body: { firstName?, …, preferences?: { notifyTopics, language, translateIncomingTo ('off' disables), soundPreferences } }, merged by key
|
|
929
|
+
Future<Map<String, dynamic>> updateAccountProfile(Map<String, dynamic> payload) =>
|
|
930
|
+
_owner('PATCH', '/users/me', body: payload);
|
|
931
|
+
|
|
932
|
+
// ===================
|
|
933
|
+
// TEAMS, INVITES, FOLLOWERS, PUSH REPLY, MEETINGS, WEBINAR RECORDINGS, GIFTS
|
|
934
|
+
// ===================
|
|
935
|
+
|
|
936
|
+
/// Named teams (ownerToken): { results: [{ _id, name, description, chatLink, members, memberCount }], max }
|
|
937
|
+
Future<Map<String, dynamic>> listWorkspaceTeams() =>
|
|
938
|
+
_owner('GET', '/users/teams');
|
|
939
|
+
|
|
940
|
+
/// ownerToken; body: { name (≤40), description?, chatLinkId?, memberIds? (≤50) }
|
|
941
|
+
Future<Map<String, dynamic>> createWorkspaceTeam(Map<String, dynamic> payload) =>
|
|
942
|
+
_owner('POST', '/users/teams', body: payload);
|
|
943
|
+
|
|
944
|
+
/// ownerToken; memberIds replaces the list, chatLinkId null clears the scope
|
|
945
|
+
Future<Map<String, dynamic>> updateWorkspaceTeam(String teamId, Map<String, dynamic> payload) =>
|
|
946
|
+
_owner('PATCH', '/users/teams/${Uri.encodeComponent(teamId)}', body: payload);
|
|
947
|
+
|
|
948
|
+
/// ownerToken: { status }
|
|
949
|
+
Future<Map<String, dynamic>> deleteWorkspaceTeam(String teamId) =>
|
|
950
|
+
_owner('DELETE', '/users/teams/${Uri.encodeComponent(teamId)}');
|
|
951
|
+
|
|
952
|
+
/// ownerToken; body: { firstName, lastName?, username (email), teamRole? ADMIN|AGENT, answerLinks? }: the TeamMemberView allowlist
|
|
953
|
+
Future<Map<String, dynamic>> inviteTeamMember(Map<String, dynamic> payload) =>
|
|
954
|
+
_owner('POST', '/users/team/invite', body: payload, retry: false);
|
|
955
|
+
|
|
956
|
+
/// ownerToken; body: { firstName, lastName?, email, chatLinkId, sendWelcome? }: { _id, existed, emailed }
|
|
957
|
+
Future<Map<String, dynamic>> inviteChatUser(Map<String, dynamic> payload) =>
|
|
958
|
+
_owner('POST', '/chats/chat-users/invite', body: payload, retry: false);
|
|
959
|
+
|
|
960
|
+
/// ownerToken: { title, results: [{ id, manifestUrl, durationSec, startedAt }] }
|
|
961
|
+
Future<Map<String, dynamic>> getWebinarRecordingsAsOwner(String conversationId) =>
|
|
962
|
+
_owner('GET', '/chats/conversations/${Uri.encodeComponent(conversationId)}/webinar/recordings');
|
|
963
|
+
|
|
964
|
+
/// memberToken: { chatLinkId, memberId, followers, following, isFollowing, followsYou, canFollow }
|
|
965
|
+
Future<Map<String, dynamic>> getMemberFollowStatus(String linkId, String memberId) =>
|
|
966
|
+
_member('GET', '/chat-users/links/${Uri.encodeComponent(linkId)}/members/${Uri.encodeComponent(memberId)}/follow');
|
|
967
|
+
|
|
968
|
+
/// memberToken; same shape as getMemberFollowStatus
|
|
969
|
+
Future<Map<String, dynamic>> followMember(String linkId, String memberId) =>
|
|
970
|
+
_member('POST', '/chat-users/links/${Uri.encodeComponent(linkId)}/members/${Uri.encodeComponent(memberId)}/follow');
|
|
971
|
+
|
|
972
|
+
/// memberToken; same shape as getMemberFollowStatus
|
|
973
|
+
Future<Map<String, dynamic>> unfollowMember(String linkId, String memberId) =>
|
|
974
|
+
_member('DELETE', '/chat-users/links/${Uri.encodeComponent(linkId)}/members/${Uri.encodeComponent(memberId)}/follow');
|
|
975
|
+
|
|
976
|
+
/// memberToken; the ?guest= pass from a meeting invite: { conversationId, conversationCode }
|
|
977
|
+
Future<Map<String, dynamic>> redeemMeetingGuestPass(String code, String token) =>
|
|
978
|
+
_member('POST', '/hops/meetings/guest-pass', body: {'code': code, 'token': token});
|
|
979
|
+
|
|
980
|
+
/// memberToken; plain /hop/{code} meeting link, host admits from the lobby: { conversationId, conversationCode }
|
|
981
|
+
Future<Map<String, dynamic>> joinMeetingByLink(String code) =>
|
|
982
|
+
_member('POST', '/hops/meetings/join-by-link', body: {'code': code});
|
|
983
|
+
|
|
984
|
+
/// memberToken; Join on a HOP_MEETING card: { conversationId, conversationCode }
|
|
985
|
+
Future<Map<String, dynamic>> joinMeetingFromChannel(String meetingConversationId) =>
|
|
986
|
+
_member('POST', '/hops/meetings/${Uri.encodeComponent(meetingConversationId)}/join-from-channel');
|
|
987
|
+
|
|
988
|
+
/// memberToken; calendars the workspace offers and yours: { enabled, providers: [{ id, label }], connections: [{ provider, label, status: active|needs_reauth, accountHint, connectedAt, lastSyncAt, lastError, shareBusy, realtime }] }
|
|
989
|
+
Future<Map<String, dynamic>> getCalendarSyncStatus() => _member('GET', '/calendar-sync/status');
|
|
990
|
+
|
|
991
|
+
/// memberToken; provider google | microsoft; open the returned { authUrl }; native: true from an app (system browser, one-time code back)
|
|
992
|
+
Future<Map<String, dynamic>> connectCalendar(String provider, {String? returnTo, bool? native}) =>
|
|
993
|
+
_member('POST', '/calendar-sync/${Uri.encodeComponent(provider)}/connect',
|
|
994
|
+
body: {if (returnTo != null) 'returnTo': returnTo, if (native != null) 'native': native}, retry: false);
|
|
995
|
+
|
|
996
|
+
/// memberToken; apps redeem the one-time code from livechatta://calendar-sync/done?code=: { ok }; 400 CALENDAR_ACCOUNT_MISMATCH | CALENDAR_SIGNIN_EXPIRED
|
|
997
|
+
Future<Map<String, dynamic>> completeNativeCalendarConnect(String code) =>
|
|
998
|
+
_member('POST', '/calendar-sync/native/complete', body: {'code': code}, retry: false);
|
|
999
|
+
|
|
1000
|
+
/// memberToken; disconnect and take upcoming synced events off that calendar: { ok }
|
|
1001
|
+
Future<Map<String, dynamic>> disconnectCalendar(String provider) =>
|
|
1002
|
+
_member('DELETE', '/calendar-sync/${Uri.encodeComponent(provider)}');
|
|
1003
|
+
|
|
1004
|
+
/// memberToken; show your busy times (never titles) to members who share a conversation with you: { ok }
|
|
1005
|
+
Future<Map<String, dynamic>> setCalendarShareBusy(String provider, bool shareBusy) =>
|
|
1006
|
+
_member('PATCH', '/calendar-sync/${Uri.encodeComponent(provider)}/settings', body: {'shareBusy': shareBusy});
|
|
1007
|
+
|
|
1008
|
+
/// memberToken; sync your active calendars now (429 after 4 a minute): { queued }
|
|
1009
|
+
Future<Map<String, dynamic>> syncCalendarNow() => _member('POST', '/calendar-sync/sync', retry: false);
|
|
1010
|
+
|
|
1011
|
+
/// 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 }] }] }
|
|
1012
|
+
Future<Map<String, dynamic>> getCalendarBusy(List<String> userIds, String from, String to) =>
|
|
1013
|
+
_member('GET', '/calendar-sync/busy', query: {'userIds': userIds.join(','), 'from': from, 'to': to});
|
|
1014
|
+
|
|
1015
|
+
/// Member or owner token; mentions and reactions, newest first; query: prevCursor?, nextCursor?, limit?
|
|
1016
|
+
Future<Map<String, dynamic>> listActivity({Map<String, String>? query}) =>
|
|
1017
|
+
_userRoute('GET', '/notifications/activity', query: query);
|
|
1018
|
+
|
|
1019
|
+
/// Member or owner token: { count }
|
|
1020
|
+
Future<Map<String, dynamic>> getActivityUnreadCount() => _userRoute('GET', '/notifications/activity/unread-count');
|
|
1021
|
+
|
|
1022
|
+
/// Member or owner token: { success }
|
|
1023
|
+
Future<Map<String, dynamic>> markAllActivityRead() => _userRoute('PATCH', '/notifications/activity/read-all');
|
|
1024
|
+
|
|
1025
|
+
/// Member or owner token; GIF settings: { enabled, providers, rating, providerLabel } (enabled=false when GIF search is off; the other GIF routes answer 404)
|
|
1026
|
+
Future<Map<String, dynamic>> getGifConfig() => _userRoute('GET', '/chats/gifs/config');
|
|
1027
|
+
|
|
1028
|
+
/// 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.
|
|
1029
|
+
Future<Map<String, dynamic>> searchGifs({String? q, String? nextCursor, String? source}) {
|
|
1030
|
+
final query = <String, String>{
|
|
1031
|
+
if (q != null && q.isNotEmpty) 'q': q,
|
|
1032
|
+
if (nextCursor != null && nextCursor.isNotEmpty) 'nextCursor': nextCursor,
|
|
1033
|
+
if (source != null && source.isNotEmpty) 'source': source,
|
|
1034
|
+
};
|
|
1035
|
+
return _userRoute('GET', '/chats/gifs/search', query: query.isEmpty ? null : query);
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
/// Member or owner token; trending GIFs (the default pack when no provider is set), same page shape as searchGifs
|
|
1039
|
+
Future<Map<String, dynamic>> trendingGifs({String? nextCursor, String? source}) {
|
|
1040
|
+
final query = <String, String>{
|
|
1041
|
+
if (nextCursor != null && nextCursor.isNotEmpty) 'nextCursor': nextCursor,
|
|
1042
|
+
if (source != null && source.isNotEmpty) 'source': source,
|
|
1043
|
+
};
|
|
1044
|
+
return _userRoute('GET', '/chats/gifs/trending', query: query.isEmpty ? null : query);
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
/// Member or owner token; tell the provider a GIF was sent (once a day per member and GIF): { ok, counted }
|
|
1048
|
+
Future<Map<String, dynamic>> registerGifShare(String provider, String id, {String? q}) =>
|
|
1049
|
+
_userRoute('POST', '/chats/gifs/share', body: {'provider': provider, 'id': id, if (q != null) 'q': q}, retry: false);
|
|
1050
|
+
|
|
1051
|
+
/// Member or owner token; report a GIF (reason: sexual|violent|hateful|spam|other; note up to 300 characters): { ok }
|
|
1052
|
+
Future<Map<String, dynamic>> reportGif(String provider, String id, String reason, {String? note, String? messageId}) =>
|
|
1053
|
+
_userRoute('POST', '/chats/gifs/report', body: {'provider': provider, 'id': id, 'reason': reason, if (note != null) 'note': note, if (messageId != null) 'messageId': messageId}, retry: false);
|
|
1054
|
+
|
|
1055
|
+
// Shared channels between workspaces (member token; changes are never retried).
|
|
1056
|
+
|
|
1057
|
+
/// 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? }
|
|
1058
|
+
Future<Map<String, dynamic>> inviteSharedChannel(String chatLinkId, String conversationId, {String? partnerLinkCode, int? expiresInHours}) =>
|
|
1059
|
+
_member('POST', '/shared-channels', body: {'chatLinkId': chatLinkId, 'conversationId': conversationId, if (partnerLinkCode != null) 'partnerLinkCode': partnerLinkCode, if (expiresInHours != null) 'expiresInHours': expiresInHours}, retry: false);
|
|
1060
|
+
|
|
1061
|
+
/// Member token; shares of your workspace, live and ended in the last 30 days: { results: [SharedChannelView], nextCursor }
|
|
1062
|
+
Future<Map<String, dynamic>> listSharedChannels(String chatLinkId, {String? nextCursor}) =>
|
|
1063
|
+
_member('GET', '/shared-channels', query: {'chatLinkId': chatLinkId, if (nextCursor != null && nextCursor.isNotEmpty) 'nextCursor': nextCursor});
|
|
1064
|
+
|
|
1065
|
+
/// Member token; look at an invite link before accepting (owner or team admin; does not use it up): { hostName, channelName, invitedByName, expiresAt }
|
|
1066
|
+
Future<Map<String, dynamic>> previewSharedChannelInvite(String token) =>
|
|
1067
|
+
_member('POST', '/shared-channels/preview', body: {'token': token}, retry: false);
|
|
1068
|
+
|
|
1069
|
+
/// Member token; people of your workspace to pick for a PICKED audience (name and handle only): { results, nextCursor }
|
|
1070
|
+
Future<Map<String, dynamic>> listSharedChannelMembers(String chatLinkId, {String? q, String? sharedChannelId, String? nextCursor}) =>
|
|
1071
|
+
_member('GET', '/shared-channels/members', query: {
|
|
1072
|
+
'chatLinkId': chatLinkId,
|
|
1073
|
+
if (q != null && q.isNotEmpty) 'q': q,
|
|
1074
|
+
if (sharedChannelId != null && sharedChannelId.isNotEmpty) 'sharedChannelId': sharedChannelId,
|
|
1075
|
+
if (nextCursor != null && nextCursor.isNotEmpty) 'nextCursor': nextCursor,
|
|
1076
|
+
});
|
|
1077
|
+
|
|
1078
|
+
/// 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] }
|
|
1079
|
+
Future<Map<String, dynamic>> getConversationSharedChannels(String conversationId, String chatLinkId) =>
|
|
1080
|
+
_member('GET', '/shared-channels/conversations/${Uri.encodeComponent(conversationId)}', query: {'chatLinkId': chatLinkId});
|
|
1081
|
+
|
|
1082
|
+
/// Member token; what your workspace may do here: { side (null when not shared with you), canRemoveMessages, canRemoveMembers, externalIds }
|
|
1083
|
+
Future<Map<String, dynamic>> getSharedChannelPermissions(String conversationId, String chatLinkId) =>
|
|
1084
|
+
_member('GET', '/shared-channels/conversations/${Uri.encodeComponent(conversationId)}/permissions', query: {'chatLinkId': chatLinkId});
|
|
1085
|
+
|
|
1086
|
+
/// Member token; accept an invite sent to your link code (partner owner or team admin; audience ALL or PICKED with memberIds): SharedChannelView
|
|
1087
|
+
Future<Map<String, dynamic>> acceptSharedChannel(String sharedChannelId, String chatLinkId, String audience, {List<String>? memberIds}) =>
|
|
1088
|
+
_member('POST', '/shared-channels/${Uri.encodeComponent(sharedChannelId)}/accept', body: {'chatLinkId': chatLinkId, 'audience': audience, if (memberIds != null) 'memberIds': memberIds}, retry: false);
|
|
1089
|
+
|
|
1090
|
+
/// Member token; accept a single-use invite link with its token (works once): SharedChannelView
|
|
1091
|
+
Future<Map<String, dynamic>> acceptSharedChannelByToken(String token, String chatLinkId, String audience, {List<String>? memberIds}) =>
|
|
1092
|
+
_member('POST', '/shared-channels/accept-token', body: {'chatLinkId': chatLinkId, 'audience': audience, 'token': token, if (memberIds != null) 'memberIds': memberIds}, retry: false);
|
|
1093
|
+
|
|
1094
|
+
/// Member token; host removes the partner, partner leaves, or either side cancels or declines a pending invite: SharedChannelView
|
|
1095
|
+
Future<Map<String, dynamic>> endSharedChannel(String sharedChannelId, String chatLinkId) =>
|
|
1096
|
+
_member('POST', '/shared-channels/${Uri.encodeComponent(sharedChannelId)}/end', body: {'chatLinkId': chatLinkId}, retry: false);
|
|
1097
|
+
|
|
1098
|
+
/// Member token; partner owner or team admin changes who has the channel (same body as accepting): SharedChannelView
|
|
1099
|
+
Future<Map<String, dynamic>> updateSharedChannelMembers(String sharedChannelId, String chatLinkId, String audience, {List<String>? memberIds}) =>
|
|
1100
|
+
_member('PUT', '/shared-channels/${Uri.encodeComponent(sharedChannelId)}/members', body: {'chatLinkId': chatLinkId, 'audience': audience, if (memberIds != null) 'memberIds': memberIds}, retry: false);
|
|
1101
|
+
|
|
1102
|
+
/// Member token; your workspace's activity log for one share: { results: [{ _id, action, actorName, detail, createdAt }], nextCursor }
|
|
1103
|
+
Future<Map<String, dynamic>> getSharedChannelAudit(String sharedChannelId, String chatLinkId, {String? nextCursor}) =>
|
|
1104
|
+
_member('GET', '/shared-channels/${Uri.encodeComponent(sharedChannelId)}/audit', query: {'chatLinkId': chatLinkId, if (nextCursor != null && nextCursor.isNotEmpty) 'nextCursor': nextCursor});
|
|
1105
|
+
|
|
1106
|
+
/// 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 }
|
|
1107
|
+
Future<Map<String, dynamic>> openSharedDirect(String chatLinkId, String conversationId, String memberId) =>
|
|
1108
|
+
_member('POST', '/shared-channels/direct', body: {'chatLinkId': chatLinkId, 'conversationId': conversationId, 'memberId': memberId}, retry: false);
|
|
1109
|
+
|
|
1110
|
+
/// Member token; host only: remove one partner member (they stay out if the channel is shared again): SharedChannelView
|
|
1111
|
+
Future<Map<String, dynamic>> removeSharedChannelMember(String chatLinkId, String conversationId, String memberId) =>
|
|
1112
|
+
_member('POST', '/shared-channels/remove-member', body: {'chatLinkId': chatLinkId, 'conversationId': conversationId, 'memberId': memberId}, retry: false);
|
|
1113
|
+
|
|
1114
|
+
/// Member token; wipe a message for everyone (workspace owners and admins; partner staff only for their own people): { messageId }
|
|
1115
|
+
Future<Map<String, dynamic>> removeSharedChannelMessage(String chatLinkId, String conversationId, String messageId) =>
|
|
1116
|
+
_member('POST', '/shared-channels/remove-message', body: {'chatLinkId': chatLinkId, 'conversationId': conversationId, 'messageId': messageId}, retry: false);
|
|
1117
|
+
|
|
1118
|
+
/// Owner token; bind a verified teammate to the chat user that is theirs (they then count as staff for shared channels): { linked: true }
|
|
1119
|
+
Future<Map<String, dynamic>> linkChatUserToAccount(String accountId, String chatUserId) =>
|
|
1120
|
+
_owner('POST', '/chats/chat-users/link-account', body: {'accountId': accountId, 'chatUserId': chatUserId}, retry: false);
|
|
1121
|
+
|
|
1122
|
+
/// Member or owner token; your own sidebar category names (one link when chatLinkId is set): { categories }
|
|
1123
|
+
Future<Map<String, dynamic>> getSidebarCategories({String? chatLinkId}) =>
|
|
1124
|
+
_userRoute('GET', '/chats/categories', query: chatLinkId == null ? null : {'chatLinkId': chatLinkId});
|
|
1125
|
+
|
|
1126
|
+
/// Member or owner token; category ≤ 40 characters, empty removes it: { conversationId, category, categories }
|
|
1127
|
+
Future<Map<String, dynamic>> setConversationCategory(String conversationId, String category) =>
|
|
1128
|
+
_userRoute('PUT', '/chats/conversations/${Uri.encodeComponent(conversationId)}/category', body: {'category': category});
|
|
1129
|
+
|
|
1130
|
+
/// Member or owner token; rename one of your categories (400 when missing or the new name is used): { categories }
|
|
1131
|
+
Future<Map<String, dynamic>> renameSidebarCategory(String from, String to, {String? chatLinkId}) =>
|
|
1132
|
+
_userRoute('PATCH', '/chats/categories', body: {'from': from, 'to': to, if (chatLinkId != null) 'chatLinkId': chatLinkId});
|
|
1133
|
+
|
|
1134
|
+
/// Member or owner token; delete a category, its conversations return to Channels, Groups and People: { categories }
|
|
1135
|
+
Future<Map<String, dynamic>> deleteSidebarCategory(String name, {String? chatLinkId}) =>
|
|
1136
|
+
_userRoute('DELETE', '/chats/categories', query: {'name': name, if (chatLinkId != null) 'chatLinkId': chatLinkId});
|
|
1137
|
+
|
|
1138
|
+
/// Member or owner token: [{ id, key, name, emoji, description, priceMinor, currency }] (no fee fields since chatta #416)
|
|
1139
|
+
Future<Map<String, dynamic>> getGiftCatalog() =>
|
|
1140
|
+
_userRoute('GET', '/gifts/catalog');
|
|
1141
|
+
|
|
1142
|
+
/// memberToken; body: { conversationId, recipientId, giftKey, note? }: { authorizationUrl, reference, … }
|
|
1143
|
+
Future<Map<String, dynamic>> sendPeerGift(Map<String, dynamic> payload) =>
|
|
1144
|
+
_member('POST', '/gifts/peer', body: payload, retry: false);
|
|
1145
|
+
|
|
1146
|
+
/// memberToken; query: nextCursor?, prevCursor?, limit?: { balance, openPayout, results (amountMinor, netMinor; no feeMinor), nextCursor, … }
|
|
1147
|
+
Future<Map<String, dynamic>> listReceivedGifts({Map<String, String>? query}) =>
|
|
1148
|
+
_member('GET', '/gifts/received', query: query);
|
|
1149
|
+
|
|
1150
|
+
/// memberToken: { currency, availableMinor, pendingPayoutMinor, lifetimeMinor }
|
|
1151
|
+
Future<Map<String, dynamic>> getGiftBalance() =>
|
|
1152
|
+
_member('GET', '/gifts/balance');
|
|
1153
|
+
|
|
1154
|
+
/// memberToken; pay out the available balance (min 1000): { payout, balance }
|
|
1155
|
+
Future<Map<String, dynamic>> requestGiftPayout() =>
|
|
1156
|
+
_member('POST', '/gifts/payouts', retry: false);
|
|
1157
|
+
|
|
1158
|
+
/// ownerToken; body: { mode, applyDefaults? }: { linkId, mode, linkType, joinPolicy, created }
|
|
1159
|
+
Future<Map<String, dynamic>> setLinkMode(String linkId, Map<String, dynamic> payload) =>
|
|
1160
|
+
_owner('PATCH', '/chats/links/${Uri.encodeComponent(linkId)}/mode', body: payload);
|
|
1161
|
+
|
|
1162
|
+
/// Conversation admin or owner; mode: standard|broadcast|announcement|qa|voice|support. Returns permissions + mode
|
|
1163
|
+
Future<Map<String, dynamic>> setConversationMode(String conversationId, String mode) =>
|
|
1164
|
+
_userRoute('PATCH', '/chats/conversations/${Uri.encodeComponent(conversationId)}/mode', body: {'mode': mode});
|
|
1165
|
+
|
|
1166
|
+
/// Public link card: { _id, code, name, mode?, joinPolicy: { guests, emailRequired, signInRequired, inviteOnly, approval }, settings (display only) }
|
|
1167
|
+
Future<Map<String, dynamic>> getPublicLinkInfo(String linkCode) =>
|
|
1168
|
+
_request('GET', '/in/${Uri.encodeComponent(linkCode)}', root: _rootUrl, auth: 'none');
|
|
1169
|
+
|
|
1170
|
+
/// API key; query: nextCursor?, prevCursor?, limit?, handles? (comma-separated lanes, default admin), q? (search, ≤ 80 chars)
|
|
1171
|
+
Future<Map<String, dynamic>> getAdminMentions({Map<String, String>? query}) =>
|
|
1172
|
+
_get('/chats/messages/admin-mentions', query: query);
|
|
1173
|
+
|
|
1174
|
+
/// ownerToken; query adds handles (comma-separated lanes, unknown = 400) and q (search, ≤ 80 chars)
|
|
1175
|
+
Future<Map<String, dynamic>> getAdminMentionsAsOwner({Map<String, String>? query}) =>
|
|
1176
|
+
_owner('GET', '/chats/messages/admin-mentions', query: query);
|
|
1177
|
+
|
|
1178
|
+
/// ownerToken; console link create (POST chats/links) honouring modeOptions: link + modeResult { applied, warning? }
|
|
1179
|
+
Future<Map<String, dynamic>> createAccountChatLink(Map<String, dynamic> payload) =>
|
|
1180
|
+
_owner('POST', '/chats/links', body: payload, retry: false);
|
|
1181
|
+
|
|
1182
|
+
/// Public join-card preview: { members, online, channels: [{ name, type, mode, category, members, live }] }
|
|
1183
|
+
Future<Map<String, dynamic>> getLinkChannels(String linkCode) =>
|
|
1184
|
+
_request('GET', '/in/${Uri.encodeComponent(linkCode)}/channels', root: _rootUrl, auth: 'none');
|
|
1185
|
+
|
|
1186
|
+
/// Public gift store: { giftPlans, features, currentPlanId } (public plans only)
|
|
1187
|
+
Future<Map<String, dynamic>> getGiftStoreData(String linkCode) =>
|
|
1188
|
+
_request('GET', '/in/${Uri.encodeComponent(linkCode)}/gift-store-data', root: _rootUrl, auth: 'none');
|
|
1189
|
+
|
|
1190
|
+
/// ownerToken (business console); body: any of { guests, emailRequired, signInRequired, approval }: the resolved JoinPolicy
|
|
1191
|
+
Future<Map<String, dynamic>> setLinkJoinPolicy(String linkId, Map<String, dynamic> payload) =>
|
|
1192
|
+
_owner('PATCH', '/chats/links/${Uri.encodeComponent(linkId)}/join-policy', body: payload);
|
|
1193
|
+
|
|
1194
|
+
/// Public Ask to join (5/min): { status: pending|approved|member }; 403 approvalOff when off
|
|
1195
|
+
Future<Map<String, dynamic>> requestToJoinLink(String linkCode, String name, String email, {String? message}) => _request(
|
|
1196
|
+
'POST', '/in/${Uri.encodeComponent(linkCode)}/join-request',
|
|
1197
|
+
body: {'name': name, 'email': email, if (message != null) 'message': message},
|
|
1198
|
+
root: _rootUrl, auth: 'none', retry: false);
|
|
1199
|
+
|
|
1200
|
+
/// ownerToken; query: status? (pending|approved|denied), nextCursor?, limit? (1–20): { results, nextCursor, hasMore, pending }
|
|
1201
|
+
Future<Map<String, dynamic>> listJoinRequests(String linkId, {Map<String, String>? query}) =>
|
|
1202
|
+
_owner('GET', '/chats/links/${Uri.encodeComponent(linkId)}/join-requests', query: query);
|
|
1203
|
+
|
|
1204
|
+
/// ownerToken; the updated request (the requester is emailed)
|
|
1205
|
+
Future<Map<String, dynamic>> approveJoinRequest(String linkId, String requestId) => _owner('POST',
|
|
1206
|
+
'/chats/links/${Uri.encodeComponent(linkId)}/join-requests/${Uri.encodeComponent(requestId)}/approve', retry: false);
|
|
1207
|
+
|
|
1208
|
+
/// ownerToken; the updated request (the requester is emailed)
|
|
1209
|
+
Future<Map<String, dynamic>> denyJoinRequest(String linkId, String requestId) => _owner('POST',
|
|
1210
|
+
'/chats/links/${Uri.encodeComponent(linkId)}/join-requests/${Uri.encodeComponent(requestId)}/deny', retry: false);
|
|
1211
|
+
|
|
1212
|
+
/// memberToken of a support-group admin: { conversationId, topicId, teamId, name, teams: [{ _id, name, memberCount }] }
|
|
1213
|
+
Future<Map<String, dynamic>> getSupportGroupTeam(String conversationId) =>
|
|
1214
|
+
_member('GET', '/chats/conversations/${Uri.encodeComponent(conversationId)}/support-team');
|
|
1215
|
+
|
|
1216
|
+
/// memberToken; teamId null stops routing; same shape as getSupportGroupTeam
|
|
1217
|
+
Future<Map<String, dynamic>> setSupportGroupTeam(String conversationId, String? teamId) =>
|
|
1218
|
+
_member('PATCH', '/chats/conversations/${Uri.encodeComponent(conversationId)}/support-team', body: {'teamId': teamId});
|
|
1219
|
+
|
|
1220
|
+
/// ownerToken; websites allowed to frame the embed chat (≤ 20; empty = any site): { domains }
|
|
1221
|
+
Future<Map<String, dynamic>> setLinkEmbedDomains(String linkId, List<String> domains) =>
|
|
1222
|
+
_owner('PUT', '/chats/links/${Uri.encodeComponent(linkId)}/embed-domains', body: {'domains': domains});
|
|
1223
|
+
|
|
1224
|
+
/// ownerToken; native app origins that may frame the app embed (≤ 10: capacitor://localhost, ionic://localhost, app://name, https://localhost; empty = none): { origins }
|
|
1225
|
+
Future<Map<String, dynamic>> setLinkAppOrigins(String linkId, List<String> origins) =>
|
|
1226
|
+
_owner('PUT', '/chats/links/${Uri.encodeComponent(linkId)}/app-origins', body: {'origins': origins});
|
|
1227
|
+
|
|
1228
|
+
// ===================
|
|
1229
|
+
// PLANS + FEATURE STORE
|
|
1230
|
+
// ===================
|
|
1231
|
+
|
|
1232
|
+
String get _ownerOrNone => (ownerToken ?? '').isEmpty ? 'none' : 'owner';
|
|
1233
|
+
|
|
1234
|
+
/// Public (owner token sent when set): plans as { results: [...] }. CUSTOM plans only for their client
|
|
1235
|
+
Future<Map<String, dynamic>> listPlans() =>
|
|
1236
|
+
_request('GET', '/subscriptions/plans', root: '$_rootUrl/api/v1', auth: _ownerOrNone);
|
|
1237
|
+
|
|
1238
|
+
/// Public (owner token sent when set); 404 [LiveChattaErrorCodes.planNotFoundMessage] for plans you may not see
|
|
1239
|
+
Future<Map<String, dynamic>> getPlan(String planId) =>
|
|
1240
|
+
_request('GET', '/subscriptions/plans/${Uri.encodeComponent(planId)}', root: '$_rootUrl/api/v1', auth: _ownerOrNone);
|
|
1241
|
+
|
|
1242
|
+
/// ownerToken; billingCycle: MONTHLY|QUARTERLY|SEMI_YEARLY|YEARLY; paymentMethod: card (default) | bank_transfer
|
|
1243
|
+
Future<Map<String, dynamic>> subscribeToPlan(String planId, String billingCycle, {String? paymentMethod}) => _owner(
|
|
1244
|
+
'POST', '/subscriptions/subscribe',
|
|
1245
|
+
body: {'planId': planId, 'billingCycle': billingCycle, if (paymentMethod != null) 'paymentMethod': paymentMethod}, retry: false);
|
|
1246
|
+
|
|
1247
|
+
/// ownerToken: { eligible, trial: null | { subscriptionId, planName, status, endsAt, daysLeft, hasCard, amountUsd } }
|
|
1248
|
+
Future<Map<String, dynamic>> getTrialStatus() => _owner('GET', '/subscriptions/trial');
|
|
1249
|
+
|
|
1250
|
+
/// ownerToken; plan with trialDays > 0, one per account: { subscriptionId, planName, trialEndsAt, days }
|
|
1251
|
+
Future<Map<String, dynamic>> startTrial(String planId, {String? billingCycle}) => _owner(
|
|
1252
|
+
'POST', '/subscriptions/trial', body: {'planId': planId, if (billingCycle != null) 'billingCycle': billingCycle}, retry: false);
|
|
1253
|
+
|
|
1254
|
+
/// ownerToken: { renewal: null | { state: current|due-soon|due|grace|lapsed, subscriptionId, periodEnd, graceEndsAt, daysLeft, amountUsd } }
|
|
1255
|
+
Future<Map<String, dynamic>> getRenewalStatus() => _owner('GET', '/subscriptions/renewal');
|
|
1256
|
+
|
|
1257
|
+
/// ownerToken; paymentMethod bank_transfer (default) | card: { authorizationUrl, reference, paymentMethod }; verify with verifySubscription
|
|
1258
|
+
Future<Map<String, dynamic>> renewSubscription(String subscriptionId, {String? paymentMethod}) => _owner(
|
|
1259
|
+
'POST', '/subscriptions/${Uri.encodeComponent(subscriptionId)}/renew',
|
|
1260
|
+
body: {if (paymentMethod != null) 'paymentMethod': paymentMethod}, retry: false);
|
|
1261
|
+
|
|
1262
|
+
/// ownerToken; stop auto-charging the card, every active plan renews by transfer: { paymentChannel }
|
|
1263
|
+
Future<Map<String, dynamic>> useBankTransferRenewals() =>
|
|
1264
|
+
_owner('POST', '/subscriptions/payment-method/bank-transfer', retry: false);
|
|
1265
|
+
|
|
1266
|
+
/// Member or owner token: { monthBytes, totalBytes, capGB (0 unlimited, -1 none), planGB, addonGB, pct, remainingBytes, state, periodStart, resetsAt }
|
|
1267
|
+
Future<Map<String, dynamic>> getStorageUsage() => _userRoute('GET', '/subscriptions/storage');
|
|
1268
|
+
|
|
1269
|
+
/// ownerToken (owner or team admin); query: nextCursor?, prevCursor?, limit? (≤ 20): { results: [{ staffName, mode: view|act, reason, … }], … }
|
|
1270
|
+
Future<Map<String, dynamic>> listStaffAccess({Map<String, String>? query}) => _owner('GET', '/staff-access', query: query);
|
|
1271
|
+
|
|
1272
|
+
/// ownerToken; paid gifts in your links: { totals: { count, grossMinor, feeMinor, netMinor }, results: [{ platformFeeBps, feeMinor, netMinor, … }], … }
|
|
1273
|
+
Future<Map<String, dynamic>> getOwnerGifts({Map<String, String>? query}) => _owner('GET', '/gifts/owner', query: query);
|
|
1274
|
+
|
|
1275
|
+
/// Public, after checkout: the subscription, or { status: pending } for bank transfers
|
|
1276
|
+
Future<Map<String, dynamic>> verifySubscription(String reference) =>
|
|
1277
|
+
_request('POST', '/subscriptions/verify', body: {'reference': reference}, root: '$_rootUrl/api/v1', auth: 'none', retry: false);
|
|
1278
|
+
|
|
1279
|
+
/// ownerToken: active subscriptions as { results: [...] }
|
|
1280
|
+
Future<Map<String, dynamic>> listMySubscriptions() => _owner('GET', '/subscriptions/my-subscriptions');
|
|
1281
|
+
|
|
1282
|
+
/// ownerToken; body: { planId, billingCycle, scheduleForPeriodEnd? }: checkout + credit/netAmount, or { scheduled, effectiveAt }
|
|
1283
|
+
Future<Map<String, dynamic>> changePlan(String subscriptionId, Map<String, dynamic> payload) =>
|
|
1284
|
+
_owner('POST', '/subscriptions/${Uri.encodeComponent(subscriptionId)}/change-plan', body: payload, retry: false);
|
|
1285
|
+
|
|
1286
|
+
/// ownerToken
|
|
1287
|
+
Future<Map<String, dynamic>> cancelSubscription(String subscriptionId) =>
|
|
1288
|
+
_owner('DELETE', '/subscriptions/${Uri.encodeComponent(subscriptionId)}');
|
|
1289
|
+
|
|
1290
|
+
/// ownerToken; drops a scheduled downgrade
|
|
1291
|
+
Future<Map<String, dynamic>> cancelScheduledPlanChange(String subscriptionId) =>
|
|
1292
|
+
_owner('DELETE', '/subscriptions/${Uri.encodeComponent(subscriptionId)}/scheduled-change');
|
|
1293
|
+
|
|
1294
|
+
/// Member or owner token; pay for a plan for the workspace: { authorizationUrl, reference, accessCode }
|
|
1295
|
+
Future<Map<String, dynamic>> giftPlan(String planId, String billingCycle) =>
|
|
1296
|
+
_userRoute('POST', '/subscriptions/plan/gift', body: {'planId': planId, 'billingCycle': billingCycle}, retry: false);
|
|
1297
|
+
|
|
1298
|
+
/// Public, after a plan-gift checkout
|
|
1299
|
+
Future<Map<String, dynamic>> verifyPlanGift(String reference) =>
|
|
1300
|
+
_request('POST', '/subscriptions/plan/gift/verify', body: {'reference': reference}, root: '$_rootUrl/api/v1', auth: 'none', retry: false);
|
|
1301
|
+
|
|
1302
|
+
/// Public; body: { contactName, contactEmail, company?, expectedChatLinks?, membersPerLink?, aiCredits?, features?, message?, source? }
|
|
1303
|
+
Future<Map<String, dynamic>> requestCustomPlan(Map<String, dynamic> payload) =>
|
|
1304
|
+
_request('POST', '/plan-requests', body: payload, root: '$_rootUrl/api/v1', auth: 'none', retry: false);
|
|
1305
|
+
|
|
1306
|
+
/// ownerToken; same body, linked to your business: { id, status, createdAt, statusUpdatedAt }
|
|
1307
|
+
Future<Map<String, dynamic>> requestCustomPlanAsOwner(Map<String, dynamic> payload) =>
|
|
1308
|
+
_owner('POST', '/plan-requests/me', body: payload, retry: false);
|
|
1309
|
+
|
|
1310
|
+
/// ownerToken: { request: { id, status: NEW|CONTACTED|QUOTED|ASSIGNED|CLOSED, … } | null }
|
|
1311
|
+
Future<Map<String, dynamic>> getMyLatestPlanRequest() => _owner('GET', '/plan-requests/me/latest');
|
|
1312
|
+
|
|
1313
|
+
/// Public: add-ons and AI credit packs as { results: [{ _id, featureKey, name, pricePerDay, usageLimit, category }] }
|
|
1314
|
+
Future<Map<String, dynamic>> listStoreFeatures() =>
|
|
1315
|
+
_request('GET', '/subscriptions/features', root: '$_rootUrl/api/v1', auth: 'none');
|
|
1316
|
+
|
|
1317
|
+
/// ownerToken; durationDays 1–365, needs an active plan: { authorizationUrl, reference, accessCode }
|
|
1318
|
+
Future<Map<String, dynamic>> purchaseFeature(String featurePricingId, int durationDays) => _owner(
|
|
1319
|
+
'POST', '/subscriptions/features/purchase',
|
|
1320
|
+
body: {'featurePricingId': featurePricingId, 'durationDays': durationDays}, retry: false);
|
|
1321
|
+
|
|
1322
|
+
/// Public, after a feature checkout
|
|
1323
|
+
Future<Map<String, dynamic>> verifyFeaturePurchase(String reference) =>
|
|
1324
|
+
_request('POST', '/subscriptions/features/verify', body: {'reference': reference}, root: '$_rootUrl/api/v1', auth: 'none', retry: false);
|
|
1325
|
+
|
|
1326
|
+
/// Member or owner token: the workspace's purchases as { results: [...] }
|
|
1327
|
+
Future<Map<String, dynamic>> listMyFeaturePurchases() => _userRoute('GET', '/subscriptions/features/my-purchases');
|
|
1328
|
+
|
|
1329
|
+
/// Member or owner token; gift an add-on to the workspace: { authorizationUrl, reference, accessCode }
|
|
1330
|
+
Future<Map<String, dynamic>> giftWorkspaceFeature(String featurePricingId, int durationDays) => _userRoute(
|
|
1331
|
+
'POST', '/subscriptions/features/gift', body: {'featurePricingId': featurePricingId, 'durationDays': durationDays}, retry: false);
|
|
1332
|
+
|
|
1333
|
+
/// Public, after a feature-gift checkout
|
|
1334
|
+
Future<Map<String, dynamic>> verifyWorkspaceFeatureGift(String reference) => _request(
|
|
1335
|
+
'POST', '/subscriptions/features/gift/verify', body: {'reference': reference}, root: '$_rootUrl/api/v1', auth: 'none', retry: false);
|
|
1336
|
+
|
|
1337
|
+
/// Public; the replyToken from an inline-Reply chat push + the text: { sent, messageId, replyToken? }. [deviceHint] ('ios-app' or 'android-app') sets `sentFrom`; the server checks it against the user agent.
|
|
1338
|
+
Future<Map<String, dynamic>> sendPushReply(String token, String message, [String? deviceHint]) =>
|
|
1339
|
+
_request('POST', '/chats/push-reply', body: {'token': token, 'message': message, if (deviceHint != null && deviceHint.isNotEmpty) 'deviceHint': deviceHint}, root: '$_rootUrl/api/v1', auth: 'none', retry: false);
|
|
1340
|
+
|
|
1341
|
+
/// Public; email a registrant their Watch recording link: always { sent: true }
|
|
1342
|
+
Future<Map<String, dynamic>> requestWebinarRecordingLink(String conversationId, String email) =>
|
|
1343
|
+
_request('POST', '/chats/conversations/${Uri.encodeComponent(conversationId)}/webinar/recording-link', body: {'email': email}, root: '$_rootUrl/api/v1', auth: 'none', retry: false);
|
|
1344
|
+
|
|
1345
|
+
/// Public; playback for the signed token from that email: { title, results }. Token goes in X-Recording-Token
|
|
1346
|
+
Future<Map<String, dynamic>> getWebinarRecording(String conversationId, String token) =>
|
|
1347
|
+
_request('GET', '/chats/conversations/${Uri.encodeComponent(conversationId)}/webinar/recording',
|
|
1348
|
+
root: '$_rootUrl/api/v1', auth: 'none', headers: {'X-Recording-Token': token});
|
|
1349
|
+
|
|
1350
|
+
/// Public, idempotent after checkout: { status: success|pending, reference, messageId? }
|
|
1351
|
+
Future<Map<String, dynamic>> verifyPeerGift(String reference) =>
|
|
1352
|
+
_request('POST', '/gifts/peer/verify', body: {'reference': reference}, root: '$_rootUrl/api/v1', auth: 'none');
|
|
1353
|
+
|
|
1354
|
+
/// Public webinar landing: { title, startAt, state, registeredCount, maxAttendees, isFull, hostName, joinPath, … }
|
|
1355
|
+
Future<Map<String, dynamic>> getWebinarInfo(String conversationId) => _request(
|
|
1356
|
+
'GET', '/chats/conversations/${Uri.encodeComponent(conversationId)}/webinar/info',
|
|
1357
|
+
root: '$_rootUrl/api/v1', auth: 'none');
|
|
1358
|
+
|
|
1359
|
+
/// Public; body: { name, email, notes?, company?, wantsRecording?, waitlist? }
|
|
1360
|
+
Future<Map<String, dynamic>> registerForWebinar(String conversationId, Map<String, dynamic> payload) => _request(
|
|
1361
|
+
'POST', '/chats/conversations/${Uri.encodeComponent(conversationId)}/webinar/register',
|
|
1362
|
+
body: payload, root: '$_rootUrl/api/v1', auth: 'none', retry: false);
|
|
1363
|
+
|
|
1364
|
+
// Forgot / reset password (public; reset replies { status, message, audience, loginUrl, signedOut }).
|
|
1365
|
+
|
|
1366
|
+
/// Business or admin account: same generic { status, message } whether or not it exists
|
|
1367
|
+
Future<Map<String, dynamic>> requestBusinessPasswordReset(String identifier) => _request(
|
|
1368
|
+
'POST', '/users/forgot-password', body: {'identifier': identifier}, root: '$_rootUrl/api/v1', auth: 'none', retry: false);
|
|
1369
|
+
|
|
1370
|
+
/// Business / admin codes; newPassword 8–200 and equal to confirmPassword
|
|
1371
|
+
Future<Map<String, dynamic>> resetBusinessPassword(String token, String newPassword, String confirmPassword) => _request(
|
|
1372
|
+
'POST', '/users/reset-password', body: _resetBody(token, newPassword, confirmPassword), root: '$_rootUrl/api/v1', auth: 'none', retry: false);
|
|
1373
|
+
|
|
1374
|
+
/// { state: valid|used|expired|invalid, audience?, purpose?: reset|set, linkCode?, email? (masked) }
|
|
1375
|
+
Future<Map<String, dynamic>> getPasswordResetStatus(String token) => _request(
|
|
1376
|
+
'GET', '/users/reset-password/status', query: {'token': token}, root: '$_rootUrl/api/v1', auth: 'none');
|
|
1377
|
+
|
|
1378
|
+
/// Chat user of one chat space; chatLinkCode is required (nothing is sent without it)
|
|
1379
|
+
Future<Map<String, dynamic>> requestChatPasswordReset(String identifier, String chatLinkCode) => _request(
|
|
1380
|
+
'POST', '/chat-users/forgot-password', body: {'identifier': identifier, 'chatLinkCode': chatLinkCode},
|
|
1381
|
+
root: '$_rootUrl/api/v1', auth: 'none', retry: false);
|
|
1382
|
+
|
|
1383
|
+
/// Chat codes only; signs out that chat user's sessions
|
|
1384
|
+
Future<Map<String, dynamic>> resetChatPassword(String token, String newPassword, String confirmPassword) => _request(
|
|
1385
|
+
'POST', '/chat-users/reset-password', body: _resetBody(token, newPassword, confirmPassword), root: '$_rootUrl/api/v1', auth: 'none', retry: false);
|
|
1386
|
+
|
|
1387
|
+
/// The chat page's door (link from the path, 5/min)
|
|
1388
|
+
Future<Map<String, dynamic>> requestLinkPasswordReset(String linkCode, String identifier) => _request(
|
|
1389
|
+
'POST', '/in/${Uri.encodeComponent(linkCode)}/forgot-password', body: {'identifier': identifier}, root: _rootUrl, auth: 'none', retry: false);
|
|
1390
|
+
|
|
1391
|
+
/// Code must belong to a member of this link's owner
|
|
1392
|
+
Future<Map<String, dynamic>> resetLinkPassword(String linkCode, String token, String newPassword, String confirmPassword) => _request(
|
|
1393
|
+
'POST', '/in/${Uri.encodeComponent(linkCode)}/reset-password', body: _resetBody(token, newPassword, confirmPassword),
|
|
1394
|
+
root: _rootUrl, auth: 'none', retry: false);
|
|
1395
|
+
|
|
1396
|
+
Map<String, dynamic> _resetBody(String token, String newPassword, String confirmPassword) =>
|
|
1397
|
+
{'token': token, 'newPassword': newPassword, 'confirmPassword': confirmPassword};
|
|
1398
|
+
|
|
1399
|
+
/// Public; always the same generic answer (no account probing). Code lasts 10 min, single use.
|
|
1400
|
+
Future<Map<String, dynamic>> requestBusinessSignInCode(String email) => _request(
|
|
1401
|
+
'POST', '/users/sign-in-code',
|
|
1402
|
+
body: {'email': email}, root: '$_rootUrl/api/v1', auth: 'none', retry: false);
|
|
1403
|
+
|
|
1404
|
+
/// Public; on success the accessToken becomes [ownerToken]. `require2fa` → [verifyBusinessTotp].
|
|
1405
|
+
Future<Map<String, dynamic>> verifyBusinessSignInCode(String email, String code) async {
|
|
1406
|
+
final res = await _request('POST', '/users/sign-in-code/verify',
|
|
1407
|
+
body: {'email': email, 'code': code}, root: '$_rootUrl/api/v1', auth: 'none', retry: false);
|
|
1408
|
+
final token = res['accessToken'];
|
|
1409
|
+
if (token is String && token.isNotEmpty) ownerToken = token;
|
|
1410
|
+
return res;
|
|
1411
|
+
}
|
|
1412
|
+
|
|
1413
|
+
/// Public; finishes a login that returned `require2fa` with the authenticator-app code.
|
|
1414
|
+
Future<Map<String, dynamic>> verifyBusinessTotp(String pendingToken, String code) async {
|
|
1415
|
+
final res = await _request('POST', '/users/2fa/verify',
|
|
1416
|
+
body: {'pendingToken': pendingToken, 'token': code}, root: '$_rootUrl/api/v1', auth: 'none', retry: false);
|
|
1417
|
+
final token = res['accessToken'];
|
|
1418
|
+
if (token is String && token.isNotEmpty) ownerToken = token;
|
|
1419
|
+
return res;
|
|
1420
|
+
}
|
|
1421
|
+
|
|
1422
|
+
// ===================
|
|
1423
|
+
// LINK ADDRESS, THEME, ACCESS, DOMAIN, OVERVIEW (1.4.0; chatta #489 – #496)
|
|
1424
|
+
// ===================
|
|
1425
|
+
|
|
1426
|
+
/// ownerToken; is this custom link address free? { code, available, reason?, message?, suggestions? }; reasons TOO_SHORT|TOO_LONG|INVALID|RESERVED|TAKEN
|
|
1427
|
+
Future<Map<String, dynamic>> checkLinkCode(String code) =>
|
|
1428
|
+
_owner('GET', '/chats/links/code-available', query: {'code': code});
|
|
1429
|
+
|
|
1430
|
+
/// ownerToken; mode templates as data: { linkModes: [...], conversationModes: [...] }
|
|
1431
|
+
Future<Map<String, dynamic>> getLinkModeCatalog() => _owner('GET', '/chats/links/modes');
|
|
1432
|
+
|
|
1433
|
+
/// ownerToken; replaces the theme; primaryColor + secondaryColor required, welcomeImageUrl may be a data: URI, footerText ≤ 140
|
|
1434
|
+
Future<Map<String, dynamic>> updateLinkTheme(String linkId, Map<String, dynamic> theme) =>
|
|
1435
|
+
_owner('PATCH', '/chats/links/${Uri.encodeComponent(linkId)}/theme', body: theme);
|
|
1436
|
+
|
|
1437
|
+
/// ownerToken; who: guest | members | invite → { who }
|
|
1438
|
+
Future<Map<String, dynamic>> setLinkWhoCanJoin(String linkId, String who) =>
|
|
1439
|
+
_owner('PATCH', '/chats/links/${Uri.encodeComponent(linkId)}/who-can-join', body: {'who': who});
|
|
1440
|
+
|
|
1441
|
+
/// ownerToken; { domain, target, verified, verifiedAt, error } (white-label plans)
|
|
1442
|
+
Future<Map<String, dynamic>> getLinkCustomDomain(String linkId) =>
|
|
1443
|
+
_owner('GET', '/chats/links/${Uri.encodeComponent(linkId)}/custom-domain');
|
|
1444
|
+
|
|
1445
|
+
/// ownerToken; saves the host name and checks it; an empty string removes it
|
|
1446
|
+
Future<Map<String, dynamic>> setLinkCustomDomain(String linkId, String domain) =>
|
|
1447
|
+
_owner('PUT', '/chats/links/${Uri.encodeComponent(linkId)}/custom-domain', body: {'domain': domain});
|
|
1448
|
+
|
|
1449
|
+
/// ownerToken; checks the domain's CNAME again
|
|
1450
|
+
Future<Map<String, dynamic>> verifyLinkCustomDomain(String linkId) =>
|
|
1451
|
+
_owner('POST', '/chats/links/${Uri.encodeComponent(linkId)}/custom-domain/verify');
|
|
1452
|
+
|
|
1453
|
+
/// ownerToken; deletes every message on the link, never retried: { status, deleted }
|
|
1454
|
+
Future<Map<String, dynamic>> wipeLinkMessages(String linkId) =>
|
|
1455
|
+
_owner('POST', '/chats/links/${Uri.encodeComponent(linkId)}/wipe-messages', retry: false);
|
|
1456
|
+
|
|
1457
|
+
/// ownerToken; Overview cards: { visitors30d, visitorsPrev30d, conversations, messages, firstReplyMedianMs, members, maxMembers, visitorsDaily, … }
|
|
1458
|
+
Future<Map<String, dynamic>> getLinkOverview(String linkId) =>
|
|
1459
|
+
_owner('GET', '/chats/links/${Uri.encodeComponent(linkId)}/overview');
|
|
1460
|
+
|
|
1461
|
+
// ===================
|
|
1462
|
+
// API-KEY LINK MODES
|
|
1463
|
+
// ===================
|
|
1464
|
+
|
|
1465
|
+
/// API key; the mode catalog { linkModes, conversationModes }
|
|
1466
|
+
Future<Map<String, dynamic>> getChatLinkModeCatalog() => _get('/chat-links/modes');
|
|
1467
|
+
|
|
1468
|
+
/// API key; body { mode, applyDefaults? }: { linkId, mode, linkType, joinPolicy, created }
|
|
1469
|
+
Future<Map<String, dynamic>> setChatLinkMode(String linkId, Map<String, dynamic> payload) =>
|
|
1470
|
+
_request('PATCH', '/chat-links/${Uri.encodeComponent(linkId)}/mode', body: payload);
|
|
1471
|
+
|
|
1472
|
+
// ===================
|
|
1473
|
+
// MY NOTE, PIN, STARRED PEOPLE (memberToken)
|
|
1474
|
+
// ===================
|
|
1475
|
+
|
|
1476
|
+
/// memberToken; your private note: { conversationId, text, updatedAt }
|
|
1477
|
+
Future<Map<String, dynamic>> getMyNote(String conversationId) =>
|
|
1478
|
+
_member('GET', '/chats/conversations/${Uri.encodeComponent(conversationId)}/my-note');
|
|
1479
|
+
|
|
1480
|
+
/// memberToken; text ≤ 2000, empty clears it
|
|
1481
|
+
Future<Map<String, dynamic>> setMyNote(String conversationId, String text) =>
|
|
1482
|
+
_member('PUT', '/chats/conversations/${Uri.encodeComponent(conversationId)}/my-note', body: {'text': text});
|
|
1483
|
+
|
|
1484
|
+
/// memberToken; pin for yourself: { conversationId, isPinned }
|
|
1485
|
+
Future<Map<String, dynamic>> setConversationPinned(String conversationId, bool pinned) =>
|
|
1486
|
+
_member('PUT', '/chats/conversations/${Uri.encodeComponent(conversationId)}/pin', body: {'pinned': pinned});
|
|
1487
|
+
|
|
1488
|
+
/// memberToken; query: nextCursor?, limit? (1–20): { items: [{ _id, displayName, handle, photo, isOnline, starredAt? }], nextCursor, total }
|
|
1489
|
+
Future<Map<String, dynamic>> listStarredPeople({Map<String, String>? query}) =>
|
|
1490
|
+
_member('GET', '/chat-users/me/starred', query: query);
|
|
1491
|
+
|
|
1492
|
+
/// memberToken; { ids: [...] }
|
|
1493
|
+
Future<Map<String, dynamic>> listStarredIds() => _member('GET', '/chat-users/me/starred/ids');
|
|
1494
|
+
|
|
1495
|
+
/// memberToken; { memberId, starred, total }
|
|
1496
|
+
Future<Map<String, dynamic>> starPerson(String memberId) =>
|
|
1497
|
+
_member('PUT', '/chat-users/me/starred/${Uri.encodeComponent(memberId)}');
|
|
1498
|
+
|
|
1499
|
+
/// memberToken; { memberId, starred, total }
|
|
1500
|
+
Future<Map<String, dynamic>> unstarPerson(String memberId) =>
|
|
1501
|
+
_member('DELETE', '/chat-users/me/starred/${Uri.encodeComponent(memberId)}');
|
|
1502
|
+
|
|
1503
|
+
// ===================
|
|
1504
|
+
// ACCOUNT, FLAGS
|
|
1505
|
+
// ===================
|
|
1506
|
+
|
|
1507
|
+
/// ownerToken; the business account with preferences and flags (hop_calls, voice_transcribe, automation_delays)
|
|
1508
|
+
Future<Map<String, dynamic>> getAccountProfile() => _owner('GET', '/users/me');
|
|
1509
|
+
|
|
1510
|
+
/// LiveChatta staff token in ownerToken; the flags the server reads: { results: [{ key, description, defaultOn }] }
|
|
1511
|
+
Future<Map<String, dynamic>> getKnownFeatureFlags() => _owner('GET', '/admins/feature-flags/known');
|
|
1512
|
+
|
|
1513
|
+
// ===================
|
|
1514
|
+
// BANK TRANSFERS, EXTRA SEATS, STORAGE PACKS
|
|
1515
|
+
// ===================
|
|
1516
|
+
|
|
1517
|
+
/// ownerToken; { pending: [{ reference, kind: plan_change|extra_seats, state: awaiting|processing, amountUsd, expiresAt, authorizationUrl, seats, planName, … }] }
|
|
1518
|
+
Future<Map<String, dynamic>> listPendingTransfers() => _owner('GET', '/subscriptions/pending-transfers');
|
|
1519
|
+
|
|
1520
|
+
/// Member or owner token; quantity, paymentMethod? (card default | bank_transfer); never retried: pending checkout or { status: success, newExtraSeats, … }
|
|
1521
|
+
Future<Map<String, dynamic>> purchaseExtraSeats(int quantity, {String? paymentMethod}) => _userRoute(
|
|
1522
|
+
'POST', '/subscriptions/extra-seats',
|
|
1523
|
+
body: {'quantity': quantity, if (paymentMethod != null) 'paymentMethod': paymentMethod}, retry: false);
|
|
1524
|
+
|
|
1525
|
+
/// Public; after an extra-seats checkout (SEAT- reference): { status }
|
|
1526
|
+
Future<Map<String, dynamic>> verifyExtraSeats(String reference) => _request(
|
|
1527
|
+
'POST', '/subscriptions/extra-seats/verify',
|
|
1528
|
+
body: {'reference': reference}, root: '$_rootUrl/api/v1', auth: 'none', retry: false);
|
|
1529
|
+
|
|
1530
|
+
/// ownerToken; storage pack renews with the plan (card) or joins the invoice (transfer): { id, autoRenew, renewsAt, canAutoRenew, blockedReason, line, … }
|
|
1531
|
+
Future<Map<String, dynamic>> setStorageAddonAutoRenew(String purchaseId, bool autoRenew) => _owner(
|
|
1532
|
+
'POST', '/subscriptions/storage/addons/${Uri.encodeComponent(purchaseId)}/auto-renew', body: {'autoRenew': autoRenew});
|
|
1533
|
+
|
|
1534
|
+
// ===================
|
|
1535
|
+
// API KEYS
|
|
1536
|
+
// ===================
|
|
1537
|
+
|
|
1538
|
+
/// ownerToken; body { name, description?, allowedOrigins? (≤ 20: acme.com, https://app.acme.com, *.acme.com) }; never retried
|
|
1539
|
+
Future<Map<String, dynamic>> createApiKey(Map<String, dynamic> payload) =>
|
|
1540
|
+
_owner('POST', '/api-keys', body: payload, retry: false);
|
|
1541
|
+
|
|
1542
|
+
/// ownerToken; query: nextCursor?, prevCursor?, limit?, apiKeySearch?, apiKeyByStatuses?, dateRange?
|
|
1543
|
+
Future<Map<String, dynamic>> listApiKeys({Map<String, String>? query}) => _owner('GET', '/api-keys', query: query);
|
|
1544
|
+
|
|
1545
|
+
/// ownerToken; body { name?, description?, allowedOrigins? } (an empty list allows any site)
|
|
1546
|
+
Future<Map<String, dynamic>> updateApiKey(String keyId, Map<String, dynamic> payload) =>
|
|
1547
|
+
_owner('PATCH', '/api-keys/${Uri.encodeComponent(keyId)}', body: payload);
|
|
1548
|
+
|
|
1549
|
+
/// ownerToken; new key with the same name and sites, then the old one is revoked; never retried
|
|
1550
|
+
Future<Map<String, dynamic>> rotateApiKey(String keyId) =>
|
|
1551
|
+
_owner('POST', '/api-keys/${Uri.encodeComponent(keyId)}/rotate', retry: false);
|
|
1552
|
+
|
|
1553
|
+
/// ownerToken; stops the key at once
|
|
1554
|
+
Future<Map<String, dynamic>> revokeApiKey(String keyId) => _owner('DELETE', '/api-keys/${Uri.encodeComponent(keyId)}');
|
|
1555
|
+
|
|
1556
|
+
/// ownerToken; period '7d' | '30d' | '90d' → { labels, requests, errors } per day
|
|
1557
|
+
Future<Map<String, dynamic>> getApiKeyUsage(String keyId, {String period = '7d'}) =>
|
|
1558
|
+
_owner('GET', '/api-keys/${Uri.encodeComponent(keyId)}/usage', query: {'period': period});
|
|
1559
|
+
|
|
1560
|
+
// ===================
|
|
1561
|
+
// CALLS HISTORY, CONTACT, GOOGLE SIGN-IN
|
|
1562
|
+
// ===================
|
|
1563
|
+
|
|
1564
|
+
/// memberToken; every ended call, newest first; query: nextCursor? (page number), limit? (≤ 20): { results, upcoming, nextCursor, prevCursor, hasMore, hasPrev, limit }
|
|
1565
|
+
// LiveFlex (USD balance; routes say /wallet). Member token for your own, owner token for the business's.
|
|
1566
|
+
Future<Map<String, dynamic>> getLiveFlex() => _userRoute('GET', '/wallet');
|
|
1567
|
+
Future<Map<String, dynamic>> listLiveFlexTransactions({Map<String, String>? query}) => _userRoute('GET', '/wallet/transactions', query: query);
|
|
1568
|
+
/// { amountMinor (100–1,000,000), provider? paystack|cryptomus }; never retried.
|
|
1569
|
+
Future<Map<String, dynamic>> fundLiveFlex(Map<String, dynamic> payload) => _userRoute('POST', '/wallet/fund', body: payload, retry: false);
|
|
1570
|
+
Future<Map<String, dynamic>> verifyLiveFlexFunding(String reference) => _userRoute('POST', '/wallet/fund/verify', body: {'reference': reference});
|
|
1571
|
+
/// { data: [{ id, name, handle }] }
|
|
1572
|
+
Future<Map<String, dynamic>> listLiveFlexRecipients({String? q}) => _userRoute('GET', '/wallet/recipients', query: q == null ? null : {'q': q});
|
|
1573
|
+
Future<Map<String, dynamic>> listLiveFlexBanks() => _userRoute('GET', '/wallet/banks');
|
|
1574
|
+
/// { bankCode, accountNumber }; a 6-digit code is emailed. Never retried.
|
|
1575
|
+
Future<Map<String, dynamic>> setLiveFlexPayoutBank(Map<String, dynamic> payload) => _userRoute('PUT', '/wallet/payout/bank', body: payload, retry: false);
|
|
1576
|
+
/// { currency USDT|USDC|BTC|ETH, network, address }; a 6-digit code is emailed. Never retried.
|
|
1577
|
+
Future<Map<String, dynamic>> setLiveFlexPayoutCrypto(Map<String, dynamic> payload) => _userRoute('PUT', '/wallet/payout/crypto', body: payload, retry: false);
|
|
1578
|
+
Future<Map<String, dynamic>> confirmLiveFlexPayout(String code) => _userRoute('POST', '/wallet/payout/confirm', body: {'code': code}, retry: false);
|
|
1579
|
+
Future<Map<String, dynamic>> clearLiveFlexPayout(String which) => _userRoute('DELETE', '/wallet/payout/${Uri.encodeComponent(which)}');
|
|
1580
|
+
/// { amountMinor (≥ 1000), method bank|crypto }. Never retried.
|
|
1581
|
+
Future<Map<String, dynamic>> withdrawLiveFlex(Map<String, dynamic> payload) => _userRoute('POST', '/wallet/withdraw', body: payload, retry: false);
|
|
1582
|
+
/// { recipientId? | toBusiness: 'business', amountMinor, note?, idempotencyKey? }
|
|
1583
|
+
Future<Map<String, dynamic>> sendLiveFlex(Map<String, dynamic> payload) => _userRoute('POST', '/wallet/send', body: payload, retry: false);
|
|
1584
|
+
|
|
1585
|
+
/// Emails a code to set or change the LiveFlex PIN; never retried
|
|
1586
|
+
Future<Map<String, dynamic>> startLiveFlexPinSetup() => _userRoute('POST', '/wallet/pin/start', retry: false);
|
|
1587
|
+
|
|
1588
|
+
/// body { code, pin (4–6 digits) }; then pass pin on send / withdraw over pinOverMinor
|
|
1589
|
+
Future<Map<String, dynamic>> setLiveFlexPin(Map<String, dynamic> payload) => _userRoute('POST', '/wallet/pin', body: payload, retry: false);
|
|
1590
|
+
|
|
1591
|
+
/// 1.6.0: emails a code to link this workspace's LiveFlex into the person's one LiveFlex
|
|
1592
|
+
Future<Map<String, dynamic>> startLiveFlexLink() => _userRoute('POST', '/wallet/link/start', retry: false);
|
|
1593
|
+
|
|
1594
|
+
/// body { code }; one way: the balance here moves into the person's LiveFlex → { linked, movedMinor, accounts }
|
|
1595
|
+
Future<Map<String, dynamic>> linkLiveFlex(Map<String, dynamic> payload) => _userRoute('POST', '/wallet/link', body: payload, retry: false);
|
|
1596
|
+
|
|
1597
|
+
/// opt-in global tag (linked LiveFlex only); '' turns it off → { tag }
|
|
1598
|
+
Future<Map<String, dynamic>> setLiveFlexTag(String tag) => _userRoute('PUT', '/wallet/tag', body: {'tag': tag}, retry: false);
|
|
1599
|
+
|
|
1600
|
+
/// exact lookup → { tag, name }; then sendLiveFlex with toTag (first time: code)
|
|
1601
|
+
Future<Map<String, dynamic>> findLiveFlexTag(String tag) {
|
|
1602
|
+
final t = tag.replaceFirst(RegExp(r'^\$'), '');
|
|
1603
|
+
return _userRoute('GET', '/wallet/tags/${Uri.encodeComponent(t)}');
|
|
1604
|
+
}
|
|
1605
|
+
|
|
1606
|
+
/// ownerToken; team admins' business sends waiting for the owner → { results }
|
|
1607
|
+
Future<Map<String, dynamic>> listLiveFlexApprovals() => _owner('GET', '/wallet/approvals');
|
|
1608
|
+
|
|
1609
|
+
/// ownerToken; status 'approved' | 'declined'; single use, never retried
|
|
1610
|
+
Future<Map<String, dynamic>> decideLiveFlexApproval(String approvalId, String status) =>
|
|
1611
|
+
_owner('PATCH', '/wallet/approvals/${Uri.encodeComponent(approvalId)}/${Uri.encodeComponent(status)}', retry: false);
|
|
1612
|
+
|
|
1613
|
+
/// owner or team admin token → { approveOverMinor, dailyCapMinor, custom }
|
|
1614
|
+
Future<Map<String, dynamic>> getLiveFlexTeamLimits() => _owner('GET', '/wallet/team-limits');
|
|
1615
|
+
|
|
1616
|
+
/// ownerToken; body { approveOverMinor, dailyCapMinor } in cents (0 off, null = default)
|
|
1617
|
+
Future<Map<String, dynamic>> setLiveFlexTeamLimits(Map<String, dynamic> payload) => _owner('PUT', '/wallet/team-limits', body: payload);
|
|
1618
|
+
|
|
1619
|
+
// LiveFlex requests, splits, standing, pots, refunds, pay links, receipts (1.7.0; money-moving calls are never retried).
|
|
1620
|
+
|
|
1621
|
+
/// 1.7.0: { conversationId, amountMinor, note?, id | handle | tag } → request card; never takes money by itself
|
|
1622
|
+
Future<Map<String, dynamic>> createLiveFlexRequest(Map<String, dynamic> payload) =>
|
|
1623
|
+
_member('POST', '/wallet/requests', body: payload, retry: false);
|
|
1624
|
+
|
|
1625
|
+
/// box "incoming" (default) | "outgoing" → { results }
|
|
1626
|
+
Future<Map<String, dynamic>> listLiveFlexRequests([String box = 'incoming']) =>
|
|
1627
|
+
_member('GET', '/wallet/requests', query: {'box': box});
|
|
1628
|
+
|
|
1629
|
+
/// one request card (the two people, or members of its chat)
|
|
1630
|
+
Future<Map<String, dynamic>> getLiveFlexRequest(String id) =>
|
|
1631
|
+
_member('GET', '/wallet/requests/${Uri.encodeComponent(id)}');
|
|
1632
|
+
|
|
1633
|
+
/// payer only; body { pin?, code? }; same checks as a send → { status, reference, balanceMinor }
|
|
1634
|
+
Future<Map<String, dynamic>> payLiveFlexRequest(String id, [Map<String, dynamic> payload = const {}]) =>
|
|
1635
|
+
_member('POST', '/wallet/requests/${Uri.encodeComponent(id)}/pay', body: payload, retry: false);
|
|
1636
|
+
|
|
1637
|
+
/// payer only, while pending
|
|
1638
|
+
Future<Map<String, dynamic>> declineLiveFlexRequest(String id) =>
|
|
1639
|
+
_member('POST', '/wallet/requests/${Uri.encodeComponent(id)}/decline', retry: false);
|
|
1640
|
+
|
|
1641
|
+
/// payer only: declines a waiting request and refuses new ones from that person
|
|
1642
|
+
Future<Map<String, dynamic>> blockLiveFlexRequester(String id) =>
|
|
1643
|
+
_member('POST', '/wallet/requests/${Uri.encodeComponent(id)}/block', retry: false);
|
|
1644
|
+
|
|
1645
|
+
/// requester only, while pending
|
|
1646
|
+
Future<Map<String, dynamic>> cancelLiveFlexRequest(String id) =>
|
|
1647
|
+
_member('POST', '/wallet/requests/${Uri.encodeComponent(id)}/cancel', retry: false);
|
|
1648
|
+
|
|
1649
|
+
/// { conversationId, totalMinor, payers: [{ id | handle | tag, amountMinor? }], includeMe?, note? } → split card
|
|
1650
|
+
Future<Map<String, dynamic>> createLiveFlexSplit(Map<String, dynamic> payload) =>
|
|
1651
|
+
_member('POST', '/wallet/splits', body: payload, retry: false);
|
|
1652
|
+
|
|
1653
|
+
/// split card: amounts and paid / unpaid
|
|
1654
|
+
Future<Map<String, dynamic>> getLiveFlexSplit(String id) =>
|
|
1655
|
+
_member('GET', '/wallet/splits/${Uri.encodeComponent(id)}');
|
|
1656
|
+
|
|
1657
|
+
/// requester only; cancels the unpaid shares
|
|
1658
|
+
Future<Map<String, dynamic>> cancelLiveFlexSplit(String id) =>
|
|
1659
|
+
_member('POST', '/wallet/splits/${Uri.encodeComponent(id)}/cancel', retry: false);
|
|
1660
|
+
|
|
1661
|
+
/// yours and ones aimed at you (read-only); owner token lists the business's → { results }
|
|
1662
|
+
Future<Map<String, dynamic>> listLiveFlexStanding() =>
|
|
1663
|
+
_userRoute('GET', '/wallet/standing');
|
|
1664
|
+
|
|
1665
|
+
/// { id | handle | tag, amountMinor, interval: week | 2weeks | month, startAt?, until?, maxRuns?, note?, pin?, code? }; your confirmation covers every run
|
|
1666
|
+
Future<Map<String, dynamic>> createLiveFlexStanding(Map<String, dynamic> payload) =>
|
|
1667
|
+
_member('POST', '/wallet/standing', body: payload, retry: false);
|
|
1668
|
+
|
|
1669
|
+
/// payer (or business owner) only
|
|
1670
|
+
Future<Map<String, dynamic>> pauseLiveFlexStanding(String id) =>
|
|
1671
|
+
_userRoute('POST', '/wallet/standing/${Uri.encodeComponent(id)}/pause', retry: false);
|
|
1672
|
+
|
|
1673
|
+
/// payer (or business owner) only
|
|
1674
|
+
Future<Map<String, dynamic>> resumeLiveFlexStanding(String id) =>
|
|
1675
|
+
_userRoute('POST', '/wallet/standing/${Uri.encodeComponent(id)}/resume', retry: false);
|
|
1676
|
+
|
|
1677
|
+
/// payer (or business owner) only; the recipient can see but not change it
|
|
1678
|
+
Future<Map<String, dynamic>> cancelLiveFlexStanding(String id) =>
|
|
1679
|
+
_userRoute('POST', '/wallet/standing/${Uri.encodeComponent(id)}/cancel', retry: false);
|
|
1680
|
+
|
|
1681
|
+
/// { conversationId, title, amountMinor? (fixed each), goalMinor?, closesAt? } → pot card
|
|
1682
|
+
Future<Map<String, dynamic>> createLiveFlexPot(Map<String, dynamic> payload) =>
|
|
1683
|
+
_member('POST', '/wallet/pots', body: payload, retry: false);
|
|
1684
|
+
|
|
1685
|
+
/// pot card (members of its chat)
|
|
1686
|
+
Future<Map<String, dynamic>> getLiveFlexPot(String id) =>
|
|
1687
|
+
_member('GET', '/wallet/pots/${Uri.encodeComponent(id)}');
|
|
1688
|
+
|
|
1689
|
+
/// body { amountMinor? (any-amount pots), pin?, code? }; held in escrow until the pot closes
|
|
1690
|
+
Future<Map<String, dynamic>> contributeLiveFlexPot(String id, [Map<String, dynamic> payload = const {}]) =>
|
|
1691
|
+
_member('POST', '/wallet/pots/${Uri.encodeComponent(id)}/contribute', body: payload, retry: false);
|
|
1692
|
+
|
|
1693
|
+
/// organizer only; pays out once
|
|
1694
|
+
Future<Map<String, dynamic>> closeLiveFlexPot(String id) =>
|
|
1695
|
+
_member('POST', '/wallet/pots/${Uri.encodeComponent(id)}/close', retry: false);
|
|
1696
|
+
|
|
1697
|
+
/// organizer only; refunds everyone
|
|
1698
|
+
Future<Map<String, dynamic>> cancelLiveFlexPot(String id) =>
|
|
1699
|
+
_member('POST', '/wallet/pots/${Uri.encodeComponent(id)}/cancel', retry: false);
|
|
1700
|
+
|
|
1701
|
+
/// body { amountMinor?, note?, key?, pin?, code? }; never above the original; only the receiver
|
|
1702
|
+
Future<Map<String, dynamic>> refundLiveFlexTransaction(String id, [Map<String, dynamic> payload = const {}]) =>
|
|
1703
|
+
_userRoute('POST', '/wallet/transactions/${Uri.encodeComponent(id)}/refund', body: payload, retry: false);
|
|
1704
|
+
|
|
1705
|
+
/// staff: { conversationId, amountMinor, description, reference? } → paylink card
|
|
1706
|
+
Future<Map<String, dynamic>> createLiveFlexPayLink(Map<String, dynamic> payload) =>
|
|
1707
|
+
_member('POST', '/wallet/pay-links', body: payload, retry: false);
|
|
1708
|
+
|
|
1709
|
+
/// paylink card (members of its chat)
|
|
1710
|
+
Future<Map<String, dynamic>> getLiveFlexPayLink(String id) =>
|
|
1711
|
+
_member('GET', '/wallet/pay-links/${Uri.encodeComponent(id)}');
|
|
1712
|
+
|
|
1713
|
+
/// staff only (agents, their own)
|
|
1714
|
+
Future<Map<String, dynamic>> cancelLiveFlexPayLink(String id) =>
|
|
1715
|
+
_member('POST', '/wallet/pay-links/${Uri.encodeComponent(id)}/cancel', retry: false);
|
|
1716
|
+
|
|
1717
|
+
/// body { method: wallet | card, pin?, code? }; card → { authorizationUrl, reference }
|
|
1718
|
+
Future<Map<String, dynamic>> payLiveFlexPayLink(String id, Map<String, dynamic> payload) =>
|
|
1719
|
+
_member('POST', '/wallet/pay-links/${Uri.encodeComponent(id)}/pay', body: payload, retry: false);
|
|
1720
|
+
|
|
1721
|
+
/// public, idempotent; after a card checkout → { status, reference }
|
|
1722
|
+
Future<Map<String, dynamic>> verifyLiveFlexPayLink(String reference) => _userRoute('POST', '/wallet/pay-links/verify', body: {'reference': reference});
|
|
1723
|
+
|
|
1724
|
+
/// → { url } signed, 10 minutes
|
|
1725
|
+
Future<Map<String, dynamic>> getLiveFlexPayLinkReceiptLink(String id) =>
|
|
1726
|
+
_member('GET', '/wallet/pay-links/${Uri.encodeComponent(id)}/receipt/link');
|
|
1727
|
+
|
|
1728
|
+
/// latest finished payments as signed 10-minute receipt links → { results }
|
|
1729
|
+
Future<Map<String, dynamic>> listLiveFlexReceipts() =>
|
|
1730
|
+
_userRoute('GET', '/wallet/receipts');
|
|
1731
|
+
|
|
1732
|
+
/// signed 10-minute PDF link for one payment
|
|
1733
|
+
Future<Map<String, dynamic>> getLiveFlexReceiptLink(String reference) =>
|
|
1734
|
+
_userRoute('GET', '/wallet/receipts/${Uri.encodeComponent(reference)}/link');
|
|
1735
|
+
|
|
1736
|
+
/// month YYYY-MM → { month, scope, pdfUrl, csvUrl }
|
|
1737
|
+
Future<Map<String, dynamic>> getLiveFlexStatementLinks(String month) =>
|
|
1738
|
+
_userRoute('GET', '/wallet/statements/${Uri.encodeComponent(month)}/links');
|
|
1739
|
+
|
|
1740
|
+
// Staff access grant (owner or team admin): { on, mode, until, grantedByName }.
|
|
1741
|
+
Future<Map<String, dynamic>> getStaffAccessGrant() => _owner('GET', '/staff-access/grant');
|
|
1742
|
+
/// { mode: view|act, hours: 1|24|72|168 }
|
|
1743
|
+
Future<Map<String, dynamic>> setStaffAccessGrant(Map<String, dynamic> payload) => _owner('PUT', '/staff-access/grant', body: payload);
|
|
1744
|
+
Future<Map<String, dynamic>> revokeStaffAccessGrant() => _owner('DELETE', '/staff-access/grant');
|
|
1745
|
+
|
|
1746
|
+
/// Owner or team admin: platform stickers with their content check. query: review, scope, q, nextCursor
|
|
1747
|
+
Future<Map<String, dynamic>> listWorkspaceStickers({Map<String, String>? query}) => _owner('GET', '/chats/stickers', query: query);
|
|
1748
|
+
|
|
1749
|
+
/// state: 'blocked' (hidden in your workspace) or 'allowed'.
|
|
1750
|
+
Future<Map<String, dynamic>> setWorkspaceStickerState(String stickerId, String state) =>
|
|
1751
|
+
_owner('PATCH', '/chats/stickers/${Uri.encodeComponent(stickerId)}/workspace/${Uri.encodeComponent(state)}');
|
|
1752
|
+
|
|
1753
|
+
/// Take down a sticker one of your members uploaded.
|
|
1754
|
+
Future<Map<String, dynamic>> takeDownSticker(String stickerId) => _owner('POST', '/chats/stickers/${Uri.encodeComponent(stickerId)}/take-down');
|
|
1755
|
+
|
|
1756
|
+
Future<Map<String, dynamic>> listCallHistory({Map<String, String>? query}) => _member('GET', '/hops/calls', query: query);
|
|
1757
|
+
|
|
1758
|
+
/// memberToken; 10-minute MP4 link { url (server-relative), expiresAt, filename }; 403 RECORDING_DOWNLOAD_OFF when the link's switch is off
|
|
1759
|
+
Future<Map<String, dynamic>> getRecordingDownloadLink(String messageId) =>
|
|
1760
|
+
_member('POST', '/hops/recordings/${Uri.encodeComponent(messageId)}/download', retry: false);
|
|
1761
|
+
|
|
1762
|
+
/// Public; body { name, email, message (5–4000), website? (leave empty) } at the site root; never retried: { success, message }
|
|
1763
|
+
Future<Map<String, dynamic>> sendContactMessage(Map<String, dynamic> payload) =>
|
|
1764
|
+
_request('POST', '/public/contact', body: payload, root: _rootUrl, auth: 'none', retry: false);
|
|
1765
|
+
|
|
1766
|
+
/// The URL that starts "Continue with Google"; open it in the browser. No request is made.
|
|
1767
|
+
String googleSignInUrl({String? returnUrl}) =>
|
|
1768
|
+
'$_rootUrl/api/v1/users/google/start${_buildQueryString(returnUrl == null || returnUrl.isEmpty ? null : {'returnUrl': returnUrl})}';
|
|
1769
|
+
|
|
1770
|
+
/// Public; finishes Google sign-in with the #google=<handoff> from the login URL; the token becomes ownerToken.
|
|
1771
|
+
Future<Map<String, dynamic>> redeemGoogleSignIn(String handoff) async {
|
|
1772
|
+
final res = await _request('POST', '/users/google/redeem',
|
|
1773
|
+
body: {'handoff': handoff}, root: '$_rootUrl/api/v1', auth: 'none', retry: false);
|
|
1774
|
+
final token = res['accessToken'];
|
|
1775
|
+
if (token is String && token.isNotEmpty) ownerToken = token;
|
|
1776
|
+
return res;
|
|
1777
|
+
}
|
|
1778
|
+
|
|
1779
|
+
Future<Map<String, dynamic>> _member(String method, String path,
|
|
1780
|
+
{Map<String, dynamic>? body, Map<String, String>? query, bool retry = true}) {
|
|
1781
|
+
final token = memberToken;
|
|
1782
|
+
if (token == null || token.isEmpty) {
|
|
1783
|
+
return Future.error(LiveChattaApiError('Member token required — set api().memberToken', 401));
|
|
1784
|
+
}
|
|
1785
|
+
return _request(method, path, body: body, query: query, root: '$_rootUrl/api/v1', auth: 'member', retry: retry);
|
|
1786
|
+
}
|
|
1787
|
+
|
|
1788
|
+
/// Routes open to members and owners: member token if set, else owner token.
|
|
1789
|
+
Future<Map<String, dynamic>> _userRoute(String method, String path,
|
|
1790
|
+
{Map<String, dynamic>? body, Map<String, String>? query, bool retry = true}) {
|
|
1791
|
+
final m = memberToken, o = ownerToken;
|
|
1792
|
+
final auth = (m != null && m.isNotEmpty) ? 'member' : (o != null && o.isNotEmpty) ? 'owner' : null;
|
|
1793
|
+
if (auth == null) {
|
|
1794
|
+
return Future.error(LiveChattaApiError('Member or owner token required', 401));
|
|
1795
|
+
}
|
|
1796
|
+
return _request(method, path, body: body, query: query, root: '$_rootUrl/api/v1', auth: auth, retry: retry);
|
|
1797
|
+
}
|
|
1798
|
+
|
|
1799
|
+
Future<Map<String, dynamic>> _owner(String method, String path,
|
|
1800
|
+
{Map<String, dynamic>? body, Map<String, String>? query, bool retry = true, Map<String, String> headers = const {}}) {
|
|
1801
|
+
final token = ownerToken;
|
|
1802
|
+
if (token == null || token.isEmpty) {
|
|
1803
|
+
return Future.error(LiveChattaApiError('Owner token required — set api().ownerToken', 401));
|
|
1804
|
+
}
|
|
1805
|
+
return _request(method, path, body: body, query: query, root: '$_rootUrl/api/v1', auth: 'owner', retry: retry, headers: headers);
|
|
1806
|
+
}
|
|
1807
|
+
|
|
1808
|
+
Future<Map<String, dynamic>> _get(String path, {Map<String, String>? query}) =>
|
|
1809
|
+
_request('GET', path, query: query);
|
|
1810
|
+
|
|
1811
|
+
Future<Map<String, dynamic>> _post(String path, {Map<String, dynamic>? body}) =>
|
|
1812
|
+
_request('POST', path, body: body);
|
|
1813
|
+
|
|
1814
|
+
Future<Map<String, dynamic>> _request(
|
|
1815
|
+
String method,
|
|
1816
|
+
String path, {
|
|
1817
|
+
Map<String, dynamic>? body,
|
|
1818
|
+
Map<String, String>? query,
|
|
1819
|
+
String? root,
|
|
1820
|
+
String auth = 'apiKey',
|
|
1821
|
+
bool retry = true,
|
|
1822
|
+
Map<String, String> headers = const {},
|
|
1823
|
+
}) async {
|
|
1824
|
+
final queryString = _buildQueryString(query);
|
|
1825
|
+
final url = Uri.parse('${root ?? baseUrl}$path$queryString');
|
|
1826
|
+
final maxRetries = retry ? _maxRetries : 0;
|
|
1827
|
+
|
|
1828
|
+
if (debug) print('[LiveChatta HTTP] $method $path');
|
|
1829
|
+
|
|
1830
|
+
Exception? lastError;
|
|
1831
|
+
|
|
1832
|
+
for (var attempt = 0; attempt <= maxRetries; attempt++) {
|
|
1833
|
+
try {
|
|
1834
|
+
final sendHeaders = <String, String>{...headers, 'Content-Type': 'application/json'};
|
|
1835
|
+
if (auth == 'apiKey') {
|
|
1836
|
+
sendHeaders['x-api-key'] = apiKey;
|
|
1837
|
+
sendHeaders['x-embed'] = 'true';
|
|
1838
|
+
} else if (auth == 'owner') {
|
|
1839
|
+
sendHeaders['Authorization'] = 'Bearer $ownerToken';
|
|
1840
|
+
} else if (auth == 'member') {
|
|
1841
|
+
sendHeaders['Authorization'] = 'Bearer $memberToken';
|
|
1842
|
+
}
|
|
1843
|
+
|
|
1844
|
+
http.Response response;
|
|
1845
|
+
|
|
1846
|
+
switch (method) {
|
|
1847
|
+
case 'GET':
|
|
1848
|
+
response = await _client.get(url, headers: sendHeaders).timeout(_timeout);
|
|
1849
|
+
break;
|
|
1850
|
+
case 'POST':
|
|
1851
|
+
response = await _client
|
|
1852
|
+
.post(url, headers: sendHeaders, body: body != null ? jsonEncode(body) : null)
|
|
1853
|
+
.timeout(_timeout);
|
|
1854
|
+
break;
|
|
1855
|
+
case 'PATCH':
|
|
1856
|
+
response = await _client
|
|
1857
|
+
.patch(url, headers: sendHeaders, body: body != null ? jsonEncode(body) : null)
|
|
1858
|
+
.timeout(_timeout);
|
|
1859
|
+
break;
|
|
1860
|
+
case 'PUT':
|
|
1861
|
+
response = await _client
|
|
1862
|
+
.put(url, headers: sendHeaders, body: body != null ? jsonEncode(body) : null)
|
|
1863
|
+
.timeout(_timeout);
|
|
1864
|
+
break;
|
|
1865
|
+
case 'DELETE':
|
|
1866
|
+
response = await _client.delete(url, headers: sendHeaders).timeout(_timeout);
|
|
1867
|
+
break;
|
|
1868
|
+
default:
|
|
1869
|
+
throw LiveChattaApiError('Unsupported method: $method', 0);
|
|
1870
|
+
}
|
|
1871
|
+
|
|
1872
|
+
if (response.statusCode >= 200 && response.statusCode < 300) {
|
|
1873
|
+
return _parseResponse(response.body);
|
|
1874
|
+
}
|
|
1875
|
+
|
|
1876
|
+
// Client error — don't retry
|
|
1877
|
+
if (response.statusCode < 500) {
|
|
1878
|
+
final errorMsg = _parseErrorMessage(response.body, response.statusCode);
|
|
1879
|
+
throw LiveChattaApiError(
|
|
1880
|
+
errorMsg,
|
|
1881
|
+
response.statusCode,
|
|
1882
|
+
code: LiveChattaErrorCodes.fromBody(response.body),
|
|
1883
|
+
path: path,
|
|
1884
|
+
);
|
|
1885
|
+
}
|
|
1886
|
+
|
|
1887
|
+
// Server error — retry
|
|
1888
|
+
lastError = LiveChattaApiError(
|
|
1889
|
+
_parseErrorMessage(response.body, response.statusCode),
|
|
1890
|
+
response.statusCode,
|
|
1891
|
+
);
|
|
1892
|
+
} on LiveChattaApiError catch (e) {
|
|
1893
|
+
if (e.statusCode < 500) rethrow;
|
|
1894
|
+
lastError = e;
|
|
1895
|
+
} on TimeoutException {
|
|
1896
|
+
lastError = LiveChattaApiError('Request timeout', 408);
|
|
1897
|
+
} catch (e) {
|
|
1898
|
+
lastError = e is Exception ? e : Exception(e.toString());
|
|
1899
|
+
}
|
|
1900
|
+
|
|
1901
|
+
// Exponential backoff
|
|
1902
|
+
if (attempt < maxRetries) {
|
|
1903
|
+
await Future.delayed(Duration(milliseconds: (1 << attempt) * 1000));
|
|
1904
|
+
}
|
|
1905
|
+
}
|
|
1906
|
+
|
|
1907
|
+
throw lastError ?? LiveChattaApiError('Request failed', 0);
|
|
1908
|
+
}
|
|
1909
|
+
|
|
1910
|
+
Map<String, dynamic> _parseResponse(String body) {
|
|
1911
|
+
try {
|
|
1912
|
+
final decoded = jsonDecode(body);
|
|
1913
|
+
if (decoded is Map<String, dynamic>) return decoded;
|
|
1914
|
+
if (decoded is List) return {'results': decoded};
|
|
1915
|
+
return {'data': decoded};
|
|
1916
|
+
} catch (_) {
|
|
1917
|
+
return {'data': body};
|
|
1918
|
+
}
|
|
1919
|
+
}
|
|
1920
|
+
|
|
1921
|
+
String _parseErrorMessage(String body, int statusCode) {
|
|
1922
|
+
try {
|
|
1923
|
+
final json = jsonDecode(body);
|
|
1924
|
+
if (json is Map && json.containsKey('message')) {
|
|
1925
|
+
return json['message'].toString();
|
|
1926
|
+
}
|
|
1927
|
+
} catch (_) {}
|
|
1928
|
+
return 'Request failed: $statusCode';
|
|
1929
|
+
}
|
|
1930
|
+
|
|
1931
|
+
String _buildQueryString(Map<String, String>? params) {
|
|
1932
|
+
if (params == null || params.isEmpty) return '';
|
|
1933
|
+
final filtered = params.entries.where((e) => e.value.isNotEmpty);
|
|
1934
|
+
if (filtered.isEmpty) return '';
|
|
1935
|
+
return '?${filtered.map((e) => '${Uri.encodeComponent(e.key)}=${Uri.encodeComponent(e.value)}').join('&')}';
|
|
1936
|
+
}
|
|
1937
|
+
|
|
1938
|
+
/// Dispose the HTTP client
|
|
1939
|
+
void dispose() {
|
|
1940
|
+
_client.close();
|
|
1941
|
+
}
|
|
1942
|
+
}
|