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