@livechatta/sdk 0.0.0-stage → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +228 -0
- package/LICENSE +21 -0
- package/README.md +2558 -2
- package/bin/chatta.mjs +7 -0
- package/bin/lib/cli.d.mts +46 -0
- package/bin/lib/cli.mjs +2088 -0
- package/dist/cjs/livechatta.cjs.js +7259 -0
- package/dist/cjs/livechatta.cjs.js.map +1 -0
- package/dist/cjs/livechatta.cjs.min.js +2 -0
- package/dist/cjs/livechatta.cjs.min.js.map +1 -0
- package/dist/esm/livechatta.esm.js +7078 -0
- package/dist/esm/livechatta.esm.js.map +1 -0
- package/dist/esm/livechatta.esm.min.js +2 -0
- package/dist/esm/livechatta.esm.min.js.map +1 -0
- package/dist/platforms/android/LiveChattaClient.kt +367 -0
- package/dist/platforms/android/LiveChattaHttpAPI.kt +2630 -0
- package/dist/platforms/android/LiveChattaJson.kt +83 -0
- package/dist/platforms/android/LiveChattaModels.kt +22805 -0
- package/dist/platforms/android/LiveChattaSentFrom.kt +30 -0
- package/dist/platforms/android/LiveChattaSocketAPI.kt +2113 -0
- package/dist/platforms/android/LiveChattaTyped.kt +239 -0
- package/dist/platforms/android/LiveChattaWebView.kt +158 -0
- package/dist/platforms/angular/livechatta-bridge.service.d.ts +35 -0
- package/dist/platforms/angular/livechatta-bridge.service.js +1 -0
- package/dist/platforms/angular/livechatta-bridge.service.js.map +1 -0
- package/dist/platforms/angular/livechatta-embed.component.d.ts +46 -0
- package/dist/platforms/angular/livechatta-embed.component.js +1 -0
- package/dist/platforms/angular/livechatta-embed.component.js.map +1 -0
- package/dist/platforms/angular/livechatta.service.d.ts +66 -0
- package/dist/platforms/angular/livechatta.service.js +1 -0
- package/dist/platforms/angular/livechatta.service.js.map +1 -0
- package/dist/platforms/capacitor/CapacitorBridge.d.ts +27 -0
- package/dist/platforms/capacitor/CapacitorBridge.js +1 -0
- package/dist/platforms/capacitor/CapacitorBridge.js.map +1 -0
- package/dist/platforms/capacitor/CapacitorDeepLinks.d.ts +23 -0
- package/dist/platforms/capacitor/CapacitorDeepLinks.js +1 -0
- package/dist/platforms/capacitor/CapacitorDeepLinks.js.map +1 -0
- package/dist/platforms/capacitor/CapacitorPermissions.d.ts +29 -0
- package/dist/platforms/capacitor/CapacitorPermissions.js +1 -0
- package/dist/platforms/capacitor/CapacitorPermissions.js.map +1 -0
- package/dist/platforms/capacitor/CapacitorPush.d.ts +33 -0
- package/dist/platforms/capacitor/CapacitorPush.js +1 -0
- package/dist/platforms/capacitor/CapacitorPush.js.map +1 -0
- package/dist/platforms/capacitor/index.d.ts +24 -0
- package/dist/platforms/capacitor/index.js +1 -0
- package/dist/platforms/capacitor/index.js.map +1 -0
- package/dist/platforms/flutter/livechatta_client.dart +359 -0
- package/dist/platforms/flutter/livechatta_http_api.dart +1942 -0
- package/dist/platforms/flutter/livechatta_json.dart +57 -0
- package/dist/platforms/flutter/livechatta_models.dart +23531 -0
- package/dist/platforms/flutter/livechatta_sent_from.dart +35 -0
- package/dist/platforms/flutter/livechatta_socket_api.dart +1504 -0
- package/dist/platforms/flutter/livechatta_typed.dart +234 -0
- package/dist/platforms/flutter/livechatta_webview.dart +190 -0
- package/dist/platforms/ios/LiveChattaClient.swift +374 -0
- package/dist/platforms/ios/LiveChattaHttpAPI.swift +2431 -0
- package/dist/platforms/ios/LiveChattaJSON.swift +84 -0
- package/dist/platforms/ios/LiveChattaModels.swift +27050 -0
- package/dist/platforms/ios/LiveChattaSentFrom.swift +32 -0
- package/dist/platforms/ios/LiveChattaSocketAPI.swift +1446 -0
- package/dist/platforms/ios/LiveChattaTyped.swift +268 -0
- package/dist/platforms/ios/LiveChattaWebView.swift +191 -0
- package/dist/platforms/nuxt/LiveChattaView.d.ts +1 -0
- package/dist/platforms/nuxt/LiveChattaView.js +1 -0
- package/dist/platforms/nuxt/LiveChattaView.js.map +1 -0
- package/dist/platforms/nuxt/useChattaBridge.d.ts +9 -0
- package/dist/platforms/nuxt/useChattaBridge.js +1 -0
- package/dist/platforms/nuxt/useChattaBridge.js.map +1 -0
- package/dist/platforms/nuxt/useLiveChatta.d.ts +63 -0
- package/dist/platforms/nuxt/useLiveChatta.js +1 -0
- package/dist/platforms/nuxt/useLiveChatta.js.map +1 -0
- package/dist/platforms/react/LiveChattaView.d.ts +58 -0
- package/dist/platforms/react/LiveChattaView.js +1 -0
- package/dist/platforms/react/LiveChattaView.js.map +1 -0
- package/dist/platforms/react/useChattaBridge.d.ts +1 -0
- package/dist/platforms/react/useChattaBridge.js +1 -0
- package/dist/platforms/react/useChattaBridge.js.map +1 -0
- package/dist/platforms/react/useChattaDeepLink.d.ts +2 -0
- package/dist/platforms/react/useChattaDeepLink.js +1 -0
- package/dist/platforms/react/useChattaDeepLink.js.map +1 -0
- package/dist/platforms/react/useChattaPermissions.d.ts +9 -0
- package/dist/platforms/react/useChattaPermissions.js +1 -0
- package/dist/platforms/react/useChattaPermissions.js.map +1 -0
- package/dist/platforms/react/useChattaUnread.d.ts +1 -0
- package/dist/platforms/react/useChattaUnread.js +1 -0
- package/dist/platforms/react/useChattaUnread.js.map +1 -0
- package/dist/platforms/react/useLiveChatta.d.ts +29 -0
- package/dist/platforms/react/useLiveChatta.js +1 -0
- package/dist/platforms/react/useLiveChatta.js.map +1 -0
- package/dist/platforms/react-native/LiveChattaView.d.ts +52 -0
- package/dist/platforms/react-native/LiveChattaView.js +1 -0
- package/dist/platforms/react-native/LiveChattaView.js.map +1 -0
- package/dist/platforms/react-native/useChattaBridge.d.ts +12 -0
- package/dist/platforms/react-native/useChattaBridge.js +1 -0
- package/dist/platforms/react-native/useChattaBridge.js.map +1 -0
- package/dist/platforms/react-native/useLiveChatta.d.ts +29 -0
- package/dist/platforms/react-native/useLiveChatta.js +1 -0
- package/dist/platforms/react-native/useLiveChatta.js.map +1 -0
- package/dist/platforms/svelte/LiveChattaEmbed.d.ts +54 -0
- package/dist/platforms/svelte/LiveChattaEmbed.js +1 -0
- package/dist/platforms/svelte/LiveChattaEmbed.js.map +1 -0
- package/dist/platforms/svelte/chattaBridgeStore.d.ts +19 -0
- package/dist/platforms/svelte/chattaBridgeStore.js +1 -0
- package/dist/platforms/svelte/chattaBridgeStore.js.map +1 -0
- package/dist/platforms/svelte/useLiveChatta.d.ts +61 -0
- package/dist/platforms/svelte/useLiveChatta.js +1 -0
- package/dist/platforms/svelte/useLiveChatta.js.map +1 -0
- package/dist/platforms/tauri/TauriBridge.d.ts +34 -0
- package/dist/platforms/tauri/TauriBridge.js +1 -0
- package/dist/platforms/tauri/TauriBridge.js.map +1 -0
- package/dist/platforms/tauri/TauriDeepLinks.d.ts +29 -0
- package/dist/platforms/tauri/TauriDeepLinks.js +1 -0
- package/dist/platforms/tauri/TauriDeepLinks.js.map +1 -0
- package/dist/platforms/tauri/TauriPermissions.d.ts +21 -0
- package/dist/platforms/tauri/TauriPermissions.js +1 -0
- package/dist/platforms/tauri/TauriPermissions.js.map +1 -0
- package/dist/platforms/tauri/TauriUpdater.d.ts +31 -0
- package/dist/platforms/tauri/TauriUpdater.js +1 -0
- package/dist/platforms/tauri/TauriUpdater.js.map +1 -0
- package/dist/platforms/tauri/index.d.ts +22 -0
- package/dist/platforms/tauri/index.js +1 -0
- package/dist/platforms/tauri/index.js.map +1 -0
- package/dist/platforms/vue/LiveChattaView.d.ts +1 -0
- package/dist/platforms/vue/LiveChattaView.js +1 -0
- package/dist/platforms/vue/LiveChattaView.js.map +1 -0
- package/dist/platforms/vue/useChattaBridge.d.ts +11 -0
- package/dist/platforms/vue/useChattaBridge.js +1 -0
- package/dist/platforms/vue/useChattaBridge.js.map +1 -0
- package/dist/platforms/vue/useChattaDeepLink.d.ts +2 -0
- package/dist/platforms/vue/useChattaDeepLink.js +1 -0
- package/dist/platforms/vue/useChattaDeepLink.js.map +1 -0
- package/dist/platforms/vue/useChattaPermissions.d.ts +9 -0
- package/dist/platforms/vue/useChattaPermissions.js +1 -0
- package/dist/platforms/vue/useChattaPermissions.js.map +1 -0
- package/dist/platforms/vue/useChattaUnread.d.ts +8 -0
- package/dist/platforms/vue/useChattaUnread.js +1 -0
- package/dist/platforms/vue/useChattaUnread.js.map +1 -0
- package/dist/platforms/vue/useLiveChatta.d.ts +58 -0
- package/dist/platforms/vue/useLiveChatta.js +1 -0
- package/dist/platforms/vue/useLiveChatta.js.map +1 -0
- package/dist/platforms/web/LiveChattaEmbed.d.ts +94 -0
- package/dist/platforms/web/LiveChattaEmbed.js +1 -0
- package/dist/platforms/web/LiveChattaEmbed.js.map +1 -0
- package/dist/platforms/web/bridge.d.ts +8 -0
- package/dist/platforms/web/bridge.js +1 -0
- package/dist/platforms/web/bridge.js.map +1 -0
- package/dist/platforms/web/permissions.d.ts +8 -0
- package/dist/platforms/web/permissions.js +1 -0
- package/dist/platforms/web/permissions.js.map +1 -0
- package/dist/types/billing.d.ts +355 -0
- package/dist/types/billing.js +53 -0
- package/dist/types/billing.js.map +1 -0
- package/dist/types/calendar.d.ts +132 -0
- package/dist/types/calendar.js +15 -0
- package/dist/types/calendar.js.map +1 -0
- package/dist/types/chat-core.d.ts +901 -0
- package/dist/types/chat-core.js +98 -0
- package/dist/types/chat-core.js.map +1 -0
- package/dist/types/chat-features.d.ts +775 -0
- package/dist/types/chat-features.js +50 -0
- package/dist/types/chat-features.js.map +1 -0
- package/dist/types/content.d.ts +138 -0
- package/dist/types/content.js +2 -0
- package/dist/types/content.js.map +1 -0
- package/dist/types/core/AutoRefresh.d.ts +68 -0
- package/dist/types/core/Bridge.d.ts +124 -0
- package/dist/types/core/Config.d.ts +26 -0
- package/dist/types/core/DeepLinks.d.ts +38 -0
- package/dist/types/core/EventBus.d.ts +15 -0
- package/dist/types/core/GrantStore.d.ts +29 -0
- package/dist/types/core/LiveChatta.d.ts +128 -0
- package/dist/types/core/Permissions.d.ts +34 -0
- package/dist/types/core/TokenManager.d.ts +25 -0
- package/dist/types/core/events.d.ts +140 -0
- package/dist/types/csat.d.ts +110 -0
- package/dist/types/csat.js +12 -0
- package/dist/types/csat.js.map +1 -0
- package/dist/types/events.d.ts +242 -0
- package/dist/types/events.js +275 -0
- package/dist/types/events.js.map +1 -0
- package/dist/types/extras.d.ts +353 -0
- package/dist/types/extras.js +31 -0
- package/dist/types/extras.js.map +1 -0
- package/dist/types/http/HttpAPI.d.ts +944 -0
- package/dist/types/http/HttpTransport.d.ts +66 -0
- package/dist/types/http/incomingWebhook.d.ts +17 -0
- package/dist/types/incoming-webhooks.d.ts +78 -0
- package/dist/types/incoming-webhooks.js +16 -0
- package/dist/types/incoming-webhooks.js.map +1 -0
- package/dist/types/index.d.ts +15 -0
- package/dist/types/index.js +16 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/liveflex.d.ts +578 -0
- package/dist/types/liveflex.js +7 -0
- package/dist/types/liveflex.js.map +1 -0
- package/dist/types/models.d.ts +1753 -0
- package/dist/types/models.js +148 -0
- package/dist/types/models.js.map +1 -0
- package/dist/types/options.d.ts +190 -0
- package/dist/types/options.js +43 -0
- package/dist/types/options.js.map +1 -0
- package/dist/types/shared-channels.d.ts +236 -0
- package/dist/types/shared-channels.js +50 -0
- package/dist/types/shared-channels.js.map +1 -0
- package/dist/types/socket/SocketAPI.d.ts +1026 -0
- package/dist/types/socket/SocketTransport.d.ts +44 -0
- package/dist/types/types/billing.d.ts +355 -0
- package/dist/types/types/calendar.d.ts +132 -0
- package/dist/types/types/chat-core.d.ts +901 -0
- package/dist/types/types/chat-features.d.ts +775 -0
- package/dist/types/types/content.d.ts +138 -0
- package/dist/types/types/csat.d.ts +110 -0
- package/dist/types/types/events.d.ts +242 -0
- package/dist/types/types/extras.d.ts +353 -0
- package/dist/types/types/incoming-webhooks.d.ts +78 -0
- package/dist/types/types/index.d.ts +15 -0
- package/dist/types/types/liveflex.d.ts +578 -0
- package/dist/types/types/models.d.ts +1753 -0
- package/dist/types/types/options.d.ts +190 -0
- package/dist/types/types/shared-channels.d.ts +236 -0
- package/dist/types/types/workspace-gifs.d.ts +95 -0
- package/dist/types/types/workspace.d.ts +390 -0
- package/dist/types/ui/EmbedConfig.d.ts +38 -0
- package/dist/types/ui/EmbedUI.d.ts +44 -0
- package/dist/types/ui/Launcher.d.ts +122 -0
- package/dist/types/ui/brand.d.ts +27 -0
- package/dist/types/ui/embedMessages.d.ts +23 -0
- package/dist/types/ui/hours.d.ts +35 -0
- package/dist/types/ui/prechat.d.ts +35 -0
- package/dist/types/ui/widgetConfig.d.ts +4 -0
- package/dist/types/utils/crypto.d.ts +6 -0
- package/dist/types/utils/hmac.d.ts +40 -0
- package/dist/types/utils/permissions.d.ts +5 -0
- package/dist/types/utils/platform.d.ts +18 -0
- package/dist/types/utils/visitor.d.ts +2 -0
- package/dist/types/workspace-gifs.d.ts +95 -0
- package/dist/types/workspace-gifs.js +3 -0
- package/dist/types/workspace-gifs.js.map +1 -0
- package/dist/types/workspace.d.ts +390 -0
- package/dist/types/workspace.js +13 -0
- package/dist/types/workspace.js.map +1 -0
- package/dist/umd/livechatta.umd.js +7263 -0
- package/dist/umd/livechatta.umd.js.map +1 -0
- package/dist/umd/livechatta.umd.min.js +2 -0
- package/dist/umd/livechatta.umd.min.js.map +1 -0
- package/package.json +274 -4
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
|
|
3
|
+
/// Result callback with a typed model instead of a dictionary: (model, errorMessage).
|
|
4
|
+
public typealias LiveChattaTypedCallback<T> = (T?, String?) -> Void
|
|
5
|
+
|
|
6
|
+
private func messageItem(_ v: Any?) -> LiveChattaMessage? { LiveChattaJSON.object(v).map { LiveChattaMessage(json: $0) } }
|
|
7
|
+
private func activityItem(_ v: Any?) -> LiveChattaActivityNotification? { LiveChattaJSON.object(v).map { LiveChattaActivityNotification(json: $0) } }
|
|
8
|
+
private func sharedChannelItem(_ v: Any?) -> LiveChattaSharedChannelView? { LiveChattaJSON.object(v).map { LiveChattaSharedChannelView(json: $0) } }
|
|
9
|
+
private func meetingItem(_ v: Any?) -> LiveChattaOwnerMeeting? { LiveChattaJSON.object(v).map { LiveChattaOwnerMeeting(json: $0) } }
|
|
10
|
+
|
|
11
|
+
extension LiveChattaHttpAPI {
|
|
12
|
+
/// Typed twin of the deprecated map-based sendMessage: the server sets senderId from the API key.
|
|
13
|
+
public func sendMessageTyped(_ payload: LiveChattaSendMessagePayload, callback: LiveChattaTypedCallback<LiveChattaMessage>? = nil) {
|
|
14
|
+
var body = payload.toJSON()
|
|
15
|
+
if payload.senderId.isEmpty { body.removeValue(forKey: "senderId") }
|
|
16
|
+
sendMessage(body) { json, error in callback?(json.map { LiveChattaMessage(json: $0) }, error) }
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/// Typed twin of the deprecated listSentMessages (conversationId is sent as chatMessageByConversationIds).
|
|
20
|
+
public func listSentMessagesTyped(_ query: LiveChattaSentMessagesQuery = LiveChattaSentMessagesQuery(), callback: LiveChattaTypedCallback<LiveChattaPaginatedResult<LiveChattaMessage>>? = nil) {
|
|
21
|
+
var q: [String: String] = [:]
|
|
22
|
+
if let v = query.conversationId { q["chatMessageByConversationIds"] = v }
|
|
23
|
+
if let v = query.nextCursor { q["nextCursor"] = v }
|
|
24
|
+
if let v = query.prevCursor { q["prevCursor"] = v }
|
|
25
|
+
if let v = query.limit { q["limit"] = v }
|
|
26
|
+
listSentMessages(query: q) { json, error in
|
|
27
|
+
callback?(json.map { LiveChattaPaginatedResult<LiveChattaMessage>(json: $0, item: messageItem) }, error)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/// A link's meetings (owner token).
|
|
32
|
+
public func listMeetingsTyped(linkId: String, status: String? = nil, limit: Int? = nil, nextCursor: String? = nil, callback: LiveChattaTypedCallback<LiveChattaPaginatedResult<LiveChattaOwnerMeeting>>? = nil) {
|
|
33
|
+
listMeetings(linkId: linkId, status: status, limit: limit, nextCursor: nextCursor) { json, error in
|
|
34
|
+
callback?(json.map { LiveChattaPaginatedResult<LiveChattaOwnerMeeting>(json: $0, item: meetingItem) }, error)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/// Schedule a meeting from a typed request (owner token); the same idempotencyKey replays the first result.
|
|
39
|
+
public func scheduleMeetingTyped(_ payload: LiveChattaScheduleOwnerMeetingPayload, idempotencyKey: String? = nil, callback: LiveChattaTypedCallback<LiveChattaScheduledOwnerMeeting>? = nil) {
|
|
40
|
+
scheduleMeeting(payload: payload.toJSON(), idempotencyKey: idempotencyKey) { json, error in callback?(json.map { LiveChattaScheduledOwnerMeeting(json: $0) }, error) }
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/// Cancel a meeting (owner token); repeating it is safe.
|
|
44
|
+
public func cancelMeetingTyped(meetingId: String, reason: String? = nil, callback: LiveChattaTypedCallback<LiveChattaOwnerMeetingCancelResult>? = nil) {
|
|
45
|
+
cancelMeeting(meetingId: meetingId, reason: reason) { json, error in callback?(json.map { LiveChattaOwnerMeetingCancelResult(json: $0) }, error) }
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/// A link's meetings with the API key (/external/meetings).
|
|
49
|
+
public func listMeetingsWithKeyTyped(linkId: String, status: String? = nil, limit: Int? = nil, nextCursor: String? = nil, callback: LiveChattaTypedCallback<LiveChattaPaginatedResult<LiveChattaOwnerMeeting>>? = nil) {
|
|
50
|
+
listMeetingsWithKey(linkId: linkId, status: status, limit: limit, nextCursor: nextCursor) { json, error in
|
|
51
|
+
callback?(json.map { LiveChattaPaginatedResult<LiveChattaOwnerMeeting>(json: $0, item: meetingItem) }, error)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/// Schedule a meeting with the API key (/external/meetings).
|
|
56
|
+
public func scheduleMeetingWithKeyTyped(_ payload: LiveChattaScheduleOwnerMeetingPayload, idempotencyKey: String? = nil, callback: LiveChattaTypedCallback<LiveChattaScheduledOwnerMeeting>? = nil) {
|
|
57
|
+
scheduleMeetingWithKey(payload: payload.toJSON(), idempotencyKey: idempotencyKey) { json, error in callback?(json.map { LiveChattaScheduledOwnerMeeting(json: $0) }, error) }
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/// Cancel a meeting with the API key (/external/meetings).
|
|
61
|
+
public func cancelMeetingWithKeyTyped(meetingId: String, reason: String? = nil, callback: LiveChattaTypedCallback<LiveChattaOwnerMeetingCancelResult>? = nil) {
|
|
62
|
+
cancelMeetingWithKey(meetingId: meetingId, reason: reason) { json, error in callback?(json.map { LiveChattaOwnerMeetingCancelResult(json: $0) }, error) }
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/// Deliveries kept while you listen to a webhook (owner token).
|
|
66
|
+
public func readWebhookCaptureTyped(webhookId: String, after: Int = 0, callback: LiveChattaTypedCallback<LiveChattaWebhookCaptureView>? = nil) {
|
|
67
|
+
readWebhookCapture(webhookId: webhookId, after: after) { json, error in callback?(json.map { LiveChattaWebhookCaptureView(json: $0) }, error) }
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/// Your links as a typed page (member token).
|
|
71
|
+
public func listMyChatLinksTyped(query: [String: String]? = nil, callback: LiveChattaTypedCallback<LiveChattaMyChatLinksPage>? = nil) {
|
|
72
|
+
listMyChatLinks(query: query) { json, error in callback?(json.map { LiveChattaMyChatLinksPage(json: $0) }, error) }
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/// Your calendar sync status as a typed model (member token).
|
|
76
|
+
public func getCalendarSyncStatusTyped(callback: LiveChattaTypedCallback<LiveChattaCalendarSyncStatus>? = nil) {
|
|
77
|
+
getCalendarSyncStatus { json, error in callback?(json.map { LiveChattaCalendarSyncStatus(json: $0) }, error) }
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/// Busy blocks of members who share their calendar, as a typed model (member token).
|
|
81
|
+
public func getCalendarBusyTyped(userIds: [String], from: String, to: String, callback: LiveChattaTypedCallback<LiveChattaCalendarBusy>? = nil) {
|
|
82
|
+
getCalendarBusy(userIds: userIds, from: from, to: to) { json, error in callback?(json.map { LiveChattaCalendarBusy(json: $0) }, error) }
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/// Mentions and reactions as a typed page (member or owner token).
|
|
86
|
+
public func listActivityTyped(query: [String: String]? = nil, callback: LiveChattaTypedCallback<LiveChattaPaginatedResult<LiveChattaActivityNotification>>? = nil) {
|
|
87
|
+
listActivity(query: query) { json, error in
|
|
88
|
+
callback?(json.map { LiveChattaPaginatedResult<LiveChattaActivityNotification>(json: $0, item: activityItem) }, error)
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/// GIF picker settings as a typed model (member or owner token; enabled=false when GIF search is off).
|
|
93
|
+
public func getGifConfigTyped(callback: LiveChattaTypedCallback<LiveChattaGifConfigView>? = nil) {
|
|
94
|
+
getGifConfig { json, error in callback?(json.map { LiveChattaGifConfigView(json: $0) }, error) }
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/// Search GIFs as a typed page; the LiveChatta pack answers when no provider is set; `source` is livechatta or provider (member or owner token).
|
|
98
|
+
public func searchGifsTyped(q: String? = nil, nextCursor: String? = nil, source: String? = nil, callback: LiveChattaTypedCallback<LiveChattaGifPage>? = nil) {
|
|
99
|
+
searchGifs(q: q, nextCursor: nextCursor, source: source) { json, error in callback?(json.map { LiveChattaGifPage(json: $0) }, error) }
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/// Trending GIFs as a typed page (member or owner token).
|
|
103
|
+
public func trendingGifsTyped(nextCursor: String? = nil, source: String? = nil, callback: LiveChattaTypedCallback<LiveChattaGifPage>? = nil) {
|
|
104
|
+
trendingGifs(nextCursor: nextCursor, source: source) { json, error in callback?(json.map { LiveChattaGifPage(json: $0) }, error) }
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/// Tell the provider a GIF was sent, as a typed result (member or owner token).
|
|
108
|
+
public func registerGifShareTyped(provider: String, id: String, q: String? = nil, callback: LiveChattaTypedCallback<LiveChattaGifShareResult>? = nil) {
|
|
109
|
+
registerGifShare(provider: provider, id: id, q: q) { json, error in callback?(json.map { LiveChattaGifShareResult(json: $0) }, error) }
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/// The incoming webhooks of a group or channel, as a typed page (API key).
|
|
113
|
+
public func listIncomingWebhooksTyped(conversationId: String, status: String? = nil, limit: Int? = nil, nextCursor: String? = nil, callback: LiveChattaTypedCallback<LiveChattaIncomingWebhookPage>? = nil) {
|
|
114
|
+
listIncomingWebhooks(conversationId: conversationId, status: status, limit: limit, nextCursor: nextCursor) { json, error in callback?(json.map { LiveChattaIncomingWebhookPage(json: $0) }, error) }
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/// Make an incoming webhook, as a typed result: the one-time `url` is in it (API key).
|
|
118
|
+
public func createIncomingWebhookTyped(conversationId: String, payload: LiveChattaCreateIncomingWebhookPayload, callback: LiveChattaTypedCallback<LiveChattaIncomingWebhook>? = nil) {
|
|
119
|
+
createIncomingWebhook(conversationId: conversationId, payload: payload.toJSON()) { json, error in callback?(json.map { LiveChattaIncomingWebhook(json: $0) }, error) }
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/// Rename an incoming webhook, as a typed result (API key).
|
|
123
|
+
public func updateIncomingWebhookTyped(conversationId: String, hookId: String, payload: LiveChattaUpdateIncomingWebhookPayload, callback: LiveChattaTypedCallback<LiveChattaIncomingWebhook>? = nil) {
|
|
124
|
+
updateIncomingWebhook(conversationId: conversationId, hookId: hookId, payload: payload.toJSON()) { json, error in callback?(json.map { LiveChattaIncomingWebhook(json: $0) }, error) }
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/// Swap an incoming webhook's secret, as a typed result: the new one-time `url` is in it (API key).
|
|
128
|
+
public func regenerateIncomingWebhookTyped(conversationId: String, hookId: String, callback: LiveChattaTypedCallback<LiveChattaIncomingWebhook>? = nil) {
|
|
129
|
+
regenerateIncomingWebhook(conversationId: conversationId, hookId: hookId) { json, error in callback?(json.map { LiveChattaIncomingWebhook(json: $0) }, error) }
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/// Revoke an incoming webhook, as a typed result (API key).
|
|
133
|
+
public func revokeIncomingWebhookTyped(conversationId: String, hookId: String, callback: LiveChattaTypedCallback<LiveChattaIncomingWebhook>? = nil) {
|
|
134
|
+
revokeIncomingWebhook(conversationId: conversationId, hookId: hookId) { json, error in callback?(json.map { LiveChattaIncomingWebhook(json: $0) }, error) }
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/// Fold the no-email guest this device held into the signed-in member, as a typed result (member token).
|
|
138
|
+
public func claimGuestTyped(guestToken: String, callback: LiveChattaTypedCallback<LiveChattaClaimGuestResult>? = nil) {
|
|
139
|
+
claimGuest(guestToken: guestToken) { json, error in callback?(json.map { LiveChattaClaimGuestResult(json: $0) }, error) }
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/// Report a GIF, as a typed result (member or owner token).
|
|
143
|
+
public func reportGifTyped(provider: String, id: String, reason: String, note: String? = nil, messageId: String? = nil, callback: LiveChattaTypedCallback<LiveChattaGifReportResult>? = nil) {
|
|
144
|
+
reportGif(provider: provider, id: id, reason: reason, note: note, messageId: messageId) { json, error in callback?(json.map { LiveChattaGifReportResult(json: $0) }, error) }
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/// Invite another workspace to a channel, as a typed result: the single-use token is in it once (member token).
|
|
148
|
+
public func inviteSharedChannelTyped(chatLinkId: String, conversationId: String, partnerLinkCode: String? = nil, expiresInHours: Int? = nil, callback: LiveChattaTypedCallback<LiveChattaSharedChannelInviteResult>? = nil) {
|
|
149
|
+
inviteSharedChannel(chatLinkId: chatLinkId, conversationId: conversationId, partnerLinkCode: partnerLinkCode, expiresInHours: expiresInHours) { json, error in callback?(json.map { LiveChattaSharedChannelInviteResult(json: $0) }, error) }
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/// Shares of your workspace as a typed page (member token).
|
|
153
|
+
public func listSharedChannelsTyped(chatLinkId: String, nextCursor: String? = nil, callback: LiveChattaTypedCallback<LiveChattaSharedChannelPage>? = nil) {
|
|
154
|
+
listSharedChannels(chatLinkId: chatLinkId, nextCursor: nextCursor) { json, error in callback?(json.map { LiveChattaSharedChannelPage(json: $0) }, error) }
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/// What an invite link holds, as a typed model; looking does not use it up (member token).
|
|
158
|
+
public func previewSharedChannelInviteTyped(token: String, callback: LiveChattaTypedCallback<LiveChattaSharedChannelPreview>? = nil) {
|
|
159
|
+
previewSharedChannelInvite(token: token) { json, error in callback?(json.map { LiveChattaSharedChannelPreview(json: $0) }, error) }
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/// People of your workspace to pick for a shared channel, as a typed page: name and handle only (member token).
|
|
163
|
+
public func listSharedChannelMembersTyped(chatLinkId: String, q: String? = nil, sharedChannelId: String? = nil, nextCursor: String? = nil, callback: LiveChattaTypedCallback<LiveChattaSharedChannelMembersPage>? = nil) {
|
|
164
|
+
listSharedChannelMembers(chatLinkId: chatLinkId, q: q, sharedChannelId: sharedChannelId, nextCursor: nextCursor) { json, error in callback?(json.map { LiveChattaSharedChannelMembersPage(json: $0) }, error) }
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/// The shares of one of your channels as a typed page (member token).
|
|
168
|
+
public func getConversationSharedChannelsTyped(conversationId: String, chatLinkId: String, callback: LiveChattaTypedCallback<LiveChattaPaginatedResult<LiveChattaSharedChannelView>>? = nil) {
|
|
169
|
+
getConversationSharedChannels(conversationId: conversationId, chatLinkId: chatLinkId) { json, error in
|
|
170
|
+
callback?(json.map { LiveChattaPaginatedResult<LiveChattaSharedChannelView>(json: $0, item: sharedChannelItem) }, error)
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/// What your workspace may do in a shared channel, as a typed model (member token).
|
|
175
|
+
public func getSharedChannelPermissionsTyped(conversationId: String, chatLinkId: String, callback: LiveChattaTypedCallback<LiveChattaSharedConversationPermissions>? = nil) {
|
|
176
|
+
getSharedChannelPermissions(conversationId: conversationId, chatLinkId: chatLinkId) { json, error in callback?(json.map { LiveChattaSharedConversationPermissions(json: $0) }, error) }
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/// Accept an invite sent to your link code, as a typed share (member token).
|
|
180
|
+
public func acceptSharedChannelTyped(sharedChannelId: String, chatLinkId: String, audience: String, memberIds: [String]? = nil, callback: LiveChattaTypedCallback<LiveChattaSharedChannelView>? = nil) {
|
|
181
|
+
acceptSharedChannel(sharedChannelId: sharedChannelId, chatLinkId: chatLinkId, audience: audience, memberIds: memberIds) { json, error in callback?(json.map { LiveChattaSharedChannelView(json: $0) }, error) }
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/// Accept a single-use invite link with its token, as a typed share (member token).
|
|
185
|
+
public func acceptSharedChannelByTokenTyped(token: String, chatLinkId: String, audience: String, memberIds: [String]? = nil, callback: LiveChattaTypedCallback<LiveChattaSharedChannelView>? = nil) {
|
|
186
|
+
acceptSharedChannelByToken(token: token, chatLinkId: chatLinkId, audience: audience, memberIds: memberIds) { json, error in callback?(json.map { LiveChattaSharedChannelView(json: $0) }, error) }
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/// End a share (remove the partner, leave, cancel or decline), as a typed share (member token).
|
|
190
|
+
public func endSharedChannelTyped(sharedChannelId: String, chatLinkId: String, callback: LiveChattaTypedCallback<LiveChattaSharedChannelView>? = nil) {
|
|
191
|
+
endSharedChannel(sharedChannelId: sharedChannelId, chatLinkId: chatLinkId) { json, error in callback?(json.map { LiveChattaSharedChannelView(json: $0) }, error) }
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/// Change who has the channel on the partner side, as a typed share (member token).
|
|
195
|
+
public func updateSharedChannelMembersTyped(sharedChannelId: String, chatLinkId: String, audience: String, memberIds: [String]? = nil, callback: LiveChattaTypedCallback<LiveChattaSharedChannelView>? = nil) {
|
|
196
|
+
updateSharedChannelMembers(sharedChannelId: sharedChannelId, chatLinkId: chatLinkId, audience: audience, memberIds: memberIds) { json, error in callback?(json.map { LiveChattaSharedChannelView(json: $0) }, error) }
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/// Your workspace's activity log for one share, as a typed page (member token).
|
|
200
|
+
public func getSharedChannelAuditTyped(sharedChannelId: String, chatLinkId: String, nextCursor: String? = nil, callback: LiveChattaTypedCallback<LiveChattaSharedChannelAuditPage>? = nil) {
|
|
201
|
+
getSharedChannelAudit(sharedChannelId: sharedChannelId, chatLinkId: chatLinkId, nextCursor: nextCursor) { json, error in callback?(json.map { LiveChattaSharedChannelAuditPage(json: $0) }, error) }
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/// Open a direct message with a partner workspace's person, as a typed result (member token).
|
|
205
|
+
public func openSharedDirectTyped(chatLinkId: String, conversationId: String, memberId: String, callback: LiveChattaTypedCallback<LiveChattaSharedDirectResult>? = nil) {
|
|
206
|
+
openSharedDirect(chatLinkId: chatLinkId, conversationId: conversationId, memberId: memberId) { json, error in callback?(json.map { LiveChattaSharedDirectResult(json: $0) }, error) }
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/// Host removes one partner member, as a typed share (member token).
|
|
210
|
+
public func removeSharedChannelMemberTyped(chatLinkId: String, conversationId: String, memberId: String, callback: LiveChattaTypedCallback<LiveChattaSharedChannelView>? = nil) {
|
|
211
|
+
removeSharedChannelMember(chatLinkId: chatLinkId, conversationId: conversationId, memberId: memberId) { json, error in callback?(json.map { LiveChattaSharedChannelView(json: $0) }, error) }
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/// Wipe a message in a shared channel for everyone, as a typed result (member token).
|
|
215
|
+
public func removeSharedChannelMessageTyped(chatLinkId: String, conversationId: String, messageId: String, callback: LiveChattaTypedCallback<LiveChattaRemoveSharedMessageResult>? = nil) {
|
|
216
|
+
removeSharedChannelMessage(chatLinkId: chatLinkId, conversationId: conversationId, messageId: messageId) { json, error in callback?(json.map { LiveChattaRemoveSharedMessageResult(json: $0) }, error) }
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/// Bind a verified teammate to their chat user, as a typed result (owner token).
|
|
220
|
+
public func linkChatUserToAccountTyped(accountId: String, chatUserId: String, callback: LiveChattaTypedCallback<LiveChattaLinkChatUserToAccountResult>? = nil) {
|
|
221
|
+
linkChatUserToAccount(accountId: accountId, chatUserId: chatUserId) { json, error in callback?(json.map { LiveChattaLinkChatUserToAccountResult(json: $0) }, error) }
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/// The app's store versions, typed; `platforms` is nil on older servers.
|
|
225
|
+
public func getAppVersionTyped(callback: LiveChattaTypedCallback<LiveChattaAppVersionInfo>? = nil) {
|
|
226
|
+
getAppVersion { json, error in callback?(json.map { LiveChattaAppVersionInfo(json: $0) }, error) }
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/// Rate a resolved support conversation, as a typed result (member token, the customer).
|
|
230
|
+
public func submitCsatTyped(conversationId: String, payload: LiveChattaSubmitCsatPayload, callback: LiveChattaTypedCallback<LiveChattaCsatRating>? = nil) {
|
|
231
|
+
submitCsat(conversationId: conversationId, payload: payload.toJSON()) { json, error in callback?(json.map { LiveChattaCsatRating(json: $0) }, error) }
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/// Satisfaction ratings, as a typed page (API key).
|
|
235
|
+
public func listCsatRatingsTyped(query: [String: String]? = nil, callback: LiveChattaTypedCallback<LiveChattaCsatRatingPage>? = nil) {
|
|
236
|
+
listCsatRatings(query: query) { json, error in callback?(json.map { LiveChattaCsatRatingPage(json: $0) }, error) }
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/// Satisfaction summary, typed (API key).
|
|
240
|
+
public func getCsatSummaryTyped(query: [String: String]? = nil, callback: LiveChattaTypedCallback<LiveChattaCsatSummary>? = nil) {
|
|
241
|
+
getCsatSummary(query: query) { json, error in callback?(json.map { LiveChattaCsatSummary(json: $0) }, error) }
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/// Satisfaction ratings, as a typed page (owner token).
|
|
245
|
+
public func listCsatRatingsAsOwnerTyped(query: [String: String]? = nil, callback: LiveChattaTypedCallback<LiveChattaCsatRatingPage>? = nil) {
|
|
246
|
+
listCsatRatingsAsOwner(query: query) { json, error in callback?(json.map { LiveChattaCsatRatingPage(json: $0) }, error) }
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/// Satisfaction summary, typed (owner token).
|
|
250
|
+
public func getCsatSummaryAsOwnerTyped(query: [String: String]? = nil, callback: LiveChattaTypedCallback<LiveChattaCsatSummary>? = nil) {
|
|
251
|
+
getCsatSummaryAsOwner(query: query) { json, error in callback?(json.map { LiveChattaCsatSummary(json: $0) }, error) }
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/// The owner Members list of a link, as a typed page.
|
|
255
|
+
public func getLinkMemberListTyped(linkId: String, query: [String: String]? = nil, callback: LiveChattaTypedCallback<LiveChattaLinkMemberPage>? = nil) {
|
|
256
|
+
getLinkMemberList(linkId: linkId, query: query) { json, error in callback?(json.map { LiveChattaLinkMemberPage(json: $0) }, error) }
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/// Take someone off an invite-only link's list, as a typed result (owner token).
|
|
260
|
+
public func revokeLinkInviteTyped(linkId: String, memberId: String, callback: LiveChattaTypedCallback<LiveChattaRevokeLinkInviteResult>? = nil) {
|
|
261
|
+
revokeLinkInvite(linkId: linkId, memberId: memberId) { json, error in callback?(json.map { LiveChattaRevokeLinkInviteResult(json: $0) }, error) }
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/// A call recording's download link, typed (member token).
|
|
265
|
+
public func getRecordingDownloadLinkTyped(messageId: String, callback: LiveChattaTypedCallback<LiveChattaRecordingDownloadLink>? = nil) {
|
|
266
|
+
getRecordingDownloadLink(messageId: messageId) { json, error in callback?(json.map { LiveChattaRecordingDownloadLink(json: $0) }, error) }
|
|
267
|
+
}
|
|
268
|
+
}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
// UIKit only: `swift build` on macOS compiles the headless client and skips this view.
|
|
2
|
+
#if canImport(UIKit) && canImport(WebKit)
|
|
3
|
+
import UIKit
|
|
4
|
+
import WebKit
|
|
5
|
+
import Security
|
|
6
|
+
|
|
7
|
+
// iOS WKWebView embed: configure(linkCode:apiKey:publicKey:chatUsername:…). Colours are sent only
|
|
8
|
+
// when set (link theme / Signal #D2400B otherwise; "6C5CE7" = no brand); theme: light|dark|system.
|
|
9
|
+
public protocol LiveChattaDelegate: AnyObject {
|
|
10
|
+
func liveChatta(_ webView: LiveChattaWebView, didReceiveMessage data: [String: Any])
|
|
11
|
+
func liveChatta(_ webView: LiveChattaWebView, didReceiveError error: String)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
public class LiveChattaWebView: WKWebView {
|
|
15
|
+
|
|
16
|
+
public weak var chattaDelegate: LiveChattaDelegate?
|
|
17
|
+
|
|
18
|
+
public var onMessage: (([String: Any]) -> Void)?
|
|
19
|
+
public var onError: ((String) -> Void)?
|
|
20
|
+
|
|
21
|
+
private var baseUrl = "https://api.livechatta.com"
|
|
22
|
+
|
|
23
|
+
/// Pre-Signal default primary; treated as "no brand".
|
|
24
|
+
public static let legacyBrand = "6C5CE7"
|
|
25
|
+
|
|
26
|
+
public override init(frame: CGRect, configuration: WKWebViewConfiguration = WKWebViewConfiguration()) {
|
|
27
|
+
let config = configuration
|
|
28
|
+
config.allowsInlineMediaPlayback = true
|
|
29
|
+
config.mediaTypesRequiringUserActionForPlayback = []
|
|
30
|
+
|
|
31
|
+
let contentController = WKUserContentController()
|
|
32
|
+
config.userContentController = contentController
|
|
33
|
+
|
|
34
|
+
super.init(frame: frame, configuration: config)
|
|
35
|
+
|
|
36
|
+
// WKUserContentController retains its handlers; a weak proxy lets this view deallocate.
|
|
37
|
+
contentController.add(WeakScriptMessageHandler(self), name: "LiveChattaBridge")
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
required init?(coder: NSCoder) {
|
|
41
|
+
super.init(coder: coder)
|
|
42
|
+
configuration.userContentController.add(WeakScriptMessageHandler(self), name: "LiveChattaBridge")
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public func configure(
|
|
46
|
+
linkCode: String,
|
|
47
|
+
apiKey: String,
|
|
48
|
+
publicKey: String? = nil,
|
|
49
|
+
baseUrl: String = "https://api.livechatta.com",
|
|
50
|
+
chatUsername: String,
|
|
51
|
+
primaryColor: String? = nil,
|
|
52
|
+
secondaryColor: String? = nil,
|
|
53
|
+
primaryLight: String? = nil,
|
|
54
|
+
primaryDark: String? = nil,
|
|
55
|
+
primaryBg: String? = nil,
|
|
56
|
+
bg: String? = nil,
|
|
57
|
+
bgDark: String? = nil,
|
|
58
|
+
textColor: String? = nil,
|
|
59
|
+
textLight: String? = nil,
|
|
60
|
+
textMuted: String? = nil,
|
|
61
|
+
borderColor: String? = nil,
|
|
62
|
+
borderLight: String? = nil,
|
|
63
|
+
fontFamily: String? = nil,
|
|
64
|
+
logoUrl: String? = nil,
|
|
65
|
+
theme: String = "light",
|
|
66
|
+
layout: String? = nil
|
|
67
|
+
) {
|
|
68
|
+
self.baseUrl = baseUrl
|
|
69
|
+
|
|
70
|
+
let token = encryptToken(apiKey: apiKey, linkCode: linkCode, chatUsername: chatUsername, publicKey: publicKey)
|
|
71
|
+
let encodedToken = token.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) ?? token
|
|
72
|
+
|
|
73
|
+
var urlString = "\(baseUrl)/in/\(linkCode)/embed/chat"
|
|
74
|
+
urlString += "?token=\(encodedToken)"
|
|
75
|
+
urlString += "&theme=\(["light", "dark", "system"].contains(theme) ? theme : "light")"
|
|
76
|
+
if let v = primaryColor?.replacingOccurrences(of: "#", with: ""), !v.isEmpty,
|
|
77
|
+
v.uppercased() != LiveChattaWebView.legacyBrand {
|
|
78
|
+
urlString += "&primaryColor=\(v)"
|
|
79
|
+
}
|
|
80
|
+
if let v = secondaryColor?.replacingOccurrences(of: "#", with: ""), !v.isEmpty {
|
|
81
|
+
urlString += "&secondaryColor=\(v)"
|
|
82
|
+
}
|
|
83
|
+
if let v = layout, v == "bubbles" || v == "lines" { urlString += "&layout=\(v)" }
|
|
84
|
+
|
|
85
|
+
// Optional theme overrides
|
|
86
|
+
if let v = primaryLight { urlString += "&primaryLight=\(v)" }
|
|
87
|
+
if let v = primaryDark { urlString += "&primaryDark=\(v)" }
|
|
88
|
+
if let v = primaryBg { urlString += "&primaryBg=\(v)" }
|
|
89
|
+
if let v = bg { urlString += "&bg=\(v)" }
|
|
90
|
+
if let v = bgDark { urlString += "&bgDark=\(v)" }
|
|
91
|
+
if let v = textColor { urlString += "&textColor=\(v)" }
|
|
92
|
+
if let v = textLight { urlString += "&textLight=\(v)" }
|
|
93
|
+
if let v = textMuted { urlString += "&textMuted=\(v)" }
|
|
94
|
+
if let v = borderColor { urlString += "&borderColor=\(v)" }
|
|
95
|
+
if let v = borderLight { urlString += "&borderLight=\(v)" }
|
|
96
|
+
if let v = fontFamily, let encoded = v.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) {
|
|
97
|
+
urlString += "&fontFamily=\(encoded)"
|
|
98
|
+
}
|
|
99
|
+
if let v = logoUrl, let encoded = v.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) {
|
|
100
|
+
urlString += "&logoUrl=\(encoded)"
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
guard let url = URL(string: urlString) else { return }
|
|
104
|
+
load(URLRequest(url: url))
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
private func encryptToken(apiKey: String, linkCode: String, chatUsername: String, publicKey: String?) -> String {
|
|
108
|
+
let payloadDict: [String: Any] = ["apiKey": apiKey, "linkCode": linkCode, "chatUsername": chatUsername]
|
|
109
|
+
|
|
110
|
+
guard let publicKey = publicKey else { return apiKey }
|
|
111
|
+
|
|
112
|
+
guard let payloadData = try? JSONSerialization.data(withJSONObject: payloadDict) else {
|
|
113
|
+
return apiKey
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Parse PEM to SecKey
|
|
117
|
+
let pem = publicKey
|
|
118
|
+
.replacingOccurrences(of: "-----BEGIN PUBLIC KEY-----", with: "")
|
|
119
|
+
.replacingOccurrences(of: "-----END PUBLIC KEY-----", with: "")
|
|
120
|
+
.replacingOccurrences(of: "\n", with: "")
|
|
121
|
+
.replacingOccurrences(of: "\r", with: "")
|
|
122
|
+
.replacingOccurrences(of: " ", with: "")
|
|
123
|
+
|
|
124
|
+
guard let keyData = Data(base64Encoded: pem) else { return apiKey }
|
|
125
|
+
|
|
126
|
+
let keyDict: [String: Any] = [
|
|
127
|
+
kSecAttrKeyType as String: kSecAttrKeyTypeRSA,
|
|
128
|
+
kSecAttrKeyClass as String: kSecAttrKeyClassPublic,
|
|
129
|
+
kSecAttrKeySizeInBits as String: 2048,
|
|
130
|
+
]
|
|
131
|
+
|
|
132
|
+
guard let secKey = SecKeyCreateWithData(keyData as CFData, keyDict as CFDictionary, nil) else {
|
|
133
|
+
return apiKey
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Encrypt with RSA-OAEP SHA-256
|
|
137
|
+
var error: Unmanaged<CFError>?
|
|
138
|
+
guard let encryptedData = SecKeyCreateEncryptedData(
|
|
139
|
+
secKey,
|
|
140
|
+
.rsaEncryptionOAEPSHA256,
|
|
141
|
+
payloadData as CFData,
|
|
142
|
+
&error
|
|
143
|
+
) as Data? else {
|
|
144
|
+
return apiKey
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Convert to base64url
|
|
148
|
+
return encryptedData
|
|
149
|
+
.base64EncodedString()
|
|
150
|
+
.replacingOccurrences(of: "+", with: "-")
|
|
151
|
+
.replacingOccurrences(of: "/", with: "_")
|
|
152
|
+
.replacingOccurrences(of: "=", with: "")
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
extension LiveChattaWebView: WKScriptMessageHandler {
|
|
157
|
+
public func userContentController(
|
|
158
|
+
_ userContentController: WKUserContentController,
|
|
159
|
+
didReceive message: WKScriptMessage
|
|
160
|
+
) {
|
|
161
|
+
guard message.name == "LiveChattaBridge" else { return }
|
|
162
|
+
|
|
163
|
+
if let body = message.body as? [String: Any] {
|
|
164
|
+
let type = body["type"] as? String ?? ""
|
|
165
|
+
|
|
166
|
+
if type == "error" {
|
|
167
|
+
let errorMsg = body["message"] as? String ?? "Unknown error"
|
|
168
|
+
onError?(errorMsg)
|
|
169
|
+
chattaDelegate?.liveChatta(self, didReceiveError: errorMsg)
|
|
170
|
+
} else {
|
|
171
|
+
onMessage?(body)
|
|
172
|
+
chattaDelegate?.liveChatta(self, didReceiveMessage: body)
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/// Forwards bridge messages without the content controller retaining the web view.
|
|
179
|
+
private final class WeakScriptMessageHandler: NSObject, WKScriptMessageHandler {
|
|
180
|
+
private weak var target: WKScriptMessageHandler?
|
|
181
|
+
|
|
182
|
+
init(_ target: WKScriptMessageHandler) {
|
|
183
|
+
self.target = target
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
|
|
187
|
+
target?.userContentController(userContentController, didReceive: message)
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
#endif
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const LiveChattaView: any;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{defineComponent,h,ref,onMounted,onUnmounted,watch}from"vue";import{LiveChattaEmbed}from"../web/LiveChattaEmbed";import{THEME_ALL_KEYS,EMBED_OPTION_KEYS,pickDefined}from"@livechatta/sdk";const THEME_KEYS=THEME_ALL_KEYS;export const LiveChattaView=defineComponent({name:"LiveChattaView",props:{linkCode:{type:String,required:!0},apiKey:{type:String,required:!0},publicKey:{type:String,default:void 0},chatUsername:{type:String,required:!0},baseUrl:{type:String,default:void 0},primaryColor:{type:String,default:void 0},secondaryColor:{type:String,default:void 0},primaryLight:{type:String,default:void 0},primaryDark:{type:String,default:void 0},primaryBg:{type:String,default:void 0},bg:{type:String,default:void 0},bgDark:{type:String,default:void 0},textColor:{type:String,default:void 0},textLight:{type:String,default:void 0},textMuted:{type:String,default:void 0},borderColor:{type:String,default:void 0},borderLight:{type:String,default:void 0},fontFamily:{type:String,default:void 0},logoUrl:{type:String,default:void 0},theme:{type:String,default:void 0},layout:{type:String,default:void 0},floating:{type:Boolean,default:void 0},position:{type:String,default:void 0},autoOpen:{type:Boolean,default:void 0},greeting:{type:String,default:void 0},greetingDelay:{type:Number,default:void 0},title:{type:String,default:void 0},subtitle:{type:String,default:void 0},launcherLabel:{type:String,default:void 0},zIndex:{type:Number,default:void 0},preload:{type:Boolean,default:void 0},width:{type:String,default:void 0},height:{type:String,default:void 0}},emits:["message","error","openChange"],setup(e,{emit:t}){const i=ref(null);let o=null;function r(){"undefined"!=typeof window&&i.value&&(o&&(o.unmount(),o=null),o=new LiveChattaEmbed({container:i.value,linkCode:e.linkCode,apiKey:e.apiKey,publicKey:e.publicKey,chatUsername:e.chatUsername,baseUrl:e.baseUrl,primaryColor:e.primaryColor,secondaryColor:e.secondaryColor,primaryLight:e.primaryLight,primaryDark:e.primaryDark,primaryBg:e.primaryBg,bg:e.bg,bgDark:e.bgDark,textColor:e.textColor,textLight:e.textLight,textMuted:e.textMuted,borderColor:e.borderColor,borderLight:e.borderLight,fontFamily:e.fontFamily,logoUrl:e.logoUrl,theme:e.theme,width:e.width,height:e.height,...pickDefined(e,EMBED_OPTION_KEYS),onOpenChange:e=>t("openChange",e)}),o.onMessage(e=>t("message",e)),o.onError(e=>t("error",e)),o.mount())}return onMounted(()=>{r()}),onUnmounted(()=>{o&&(o.unmount(),o=null)}),watch(()=>[e.linkCode,e.apiKey,e.chatUsername,e.publicKey,e.baseUrl,e.floating,e.position,e.layout],()=>{r()}),watch(()=>THEME_KEYS.map(t=>e[t]),()=>{if(!o)return;const t={};for(const i of THEME_KEYS){const o=e[i];void 0!==o&&(t[i]=o)}Object.keys(t).length>0&&o.updateTheme(t)}),()=>h("div",{ref:i,style:e.floating?void 0:{width:e.width||"100%",height:e.height||"600px"}})}});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LiveChattaView.js","sourceRoot":"","sources":["../../../src/platforms/nuxt/LiveChattaView.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB,6FAA6F;AAC7F,8FAA8F;AAC9F,OAAO,EAAE,eAAe,EAAE,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,KAAK,CAAC;AAC7E,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEjF,kDAAkD;AAClD,MAAM,UAAU,GAAG,cAAc,CAAC;AAElC,MAAM,CAAC,MAAM,cAAc,GAAG,eAAe,CAAC;IAC5C,IAAI,EAAE,gBAAgB;IACtB,KAAK,EAAE;QACL,gCAAgC;QAChC,QAAQ,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE;QAC1C,yBAAyB;QACzB,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE;QACxC,0DAA0D;QAC1D,SAAS,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE;QAC/C,8EAA8E;QAC9E,YAAY,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE;QAC9C,wCAAwC;QACxC,OAAO,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE;QAE7C,eAAe;QACf,YAAY,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EA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AK,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;YACjC,CAAC;QACH,CAAC,CACF,CAAC;QAEF,OAAO,GAAG,EAAE,CACV,CAAC,CAAC,KAAK,EAAE;YACP,GAAG,EAAE,YAAY;YACjB,KAAK,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,IAAI,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,IAAI,OAAO,EAAE;SACtG,CAAC,CAAC;IACP,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Nuxt 3 composable — alias for the Vue hook so Nuxt apps can import
|
|
3
|
+
* from `livechatta/platforms/nuxt/bridge` without depending on Vue's
|
|
4
|
+
* subpath. Identical runtime behaviour to `livechatta/platforms/vue/bridge`.
|
|
5
|
+
*/
|
|
6
|
+
export { useChattaBridge } from '../vue/useChattaBridge';
|
|
7
|
+
export { useChattaUnread } from '../vue/useChattaUnread';
|
|
8
|
+
export { useChattaDeepLink } from '../vue/useChattaDeepLink';
|
|
9
|
+
export { useChattaPermissions } from '../vue/useChattaPermissions';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export{useChattaBridge}from"../vue/useChattaBridge";export{useChattaUnread}from"../vue/useChattaUnread";export{useChattaDeepLink}from"../vue/useChattaDeepLink";export{useChattaPermissions}from"../vue/useChattaPermissions";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useChattaBridge.js","sourceRoot":"","sources":["../../../src/platforms/nuxt/useChattaBridge.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Nuxt 3 composable for using the LiveChatta SDK.
|
|
3
|
+
*
|
|
4
|
+
* SSR-safe version of the Vue composable — returns inert state on the server
|
|
5
|
+
* and initializes the SDK only on the client side.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* <script setup lang="ts">
|
|
9
|
+
* import { useLiveChatta } from '@livechatta/sdk/platforms/nuxt';
|
|
10
|
+
*
|
|
11
|
+
* const { sock, api, connectionState, isConnected, connect } = useLiveChatta({
|
|
12
|
+
* linkCode: 'your-link-code',
|
|
13
|
+
* apiKey: 'your-api-key',
|
|
14
|
+
* publicKey: '-----BEGIN PUBLIC KEY-----\n...\n-----END PUBLIC KEY-----',
|
|
15
|
+
* chatUsername: 'john_doe',
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* onMounted(() => connect());
|
|
19
|
+
*
|
|
20
|
+
* watchEffect(() => {
|
|
21
|
+
* if (!sock.value) return;
|
|
22
|
+
* sock.value.onMessage((msg) => console.log('New message:', msg));
|
|
23
|
+
* });
|
|
24
|
+
* </script>
|
|
25
|
+
*
|
|
26
|
+
* Requirements:
|
|
27
|
+
* - nuxt ^3.0.0 (includes vue ^3.0.0)
|
|
28
|
+
* - socket.io-client (peer dependency, already in the SDK package)
|
|
29
|
+
*
|
|
30
|
+
* SSR behavior:
|
|
31
|
+
* - On the server, all refs are inert (null/disconnected/false)
|
|
32
|
+
* - connect(), disconnect(), destroy() are no-ops on the server
|
|
33
|
+
* - The SDK initializes and subscribes to events only on the client
|
|
34
|
+
*/
|
|
35
|
+
import { type Ref, type ComputedRef } from 'vue';
|
|
36
|
+
import { ConnectionState } from '@livechatta/sdk';
|
|
37
|
+
import type { InitOptions, SocketAPI, HttpAPI } from '@livechatta/sdk';
|
|
38
|
+
export interface UseLiveChattaReturn {
|
|
39
|
+
/** Socket API for real-time messaging -- null until initialized */
|
|
40
|
+
sock: ComputedRef<SocketAPI | null>;
|
|
41
|
+
/** HTTP API for REST operations -- null until initialized */
|
|
42
|
+
api: ComputedRef<HttpAPI | null>;
|
|
43
|
+
/** Current WebSocket connection state */
|
|
44
|
+
connectionState: Ref<ConnectionState>;
|
|
45
|
+
/** Whether the WebSocket is currently connected */
|
|
46
|
+
isConnected: ComputedRef<boolean>;
|
|
47
|
+
/** Whether the SDK has been initialized */
|
|
48
|
+
isInitialized: Ref<boolean>;
|
|
49
|
+
/** Connect the WebSocket transport */
|
|
50
|
+
connect: () => Promise<void>;
|
|
51
|
+
/** Disconnect the WebSocket transport */
|
|
52
|
+
disconnect: () => void;
|
|
53
|
+
/** Destroy the SDK instance and clean up */
|
|
54
|
+
destroy: () => void;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Nuxt 3 composable that manages the LiveChatta SDK lifecycle.
|
|
58
|
+
*
|
|
59
|
+
* - SSR-safe: returns inert state on the server, initializes only on the client
|
|
60
|
+
* - Tracks connection state reactively via `ref()`
|
|
61
|
+
* - Auto-destroys on component unmount to prevent memory leaks
|
|
62
|
+
*/
|
|
63
|
+
export declare function useLiveChatta(options: InitOptions): UseLiveChattaReturn;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{ref,computed,onUnmounted}from"vue";import{LiveChatta,SDKEvent,ConnectionState}from"@livechatta/sdk";export function useLiveChatta(t){if("undefined"==typeof window){const t=ref(ConnectionState.DISCONNECTED),e=ref(!1);return{sock:computed(()=>null),api:computed(()=>null),connectionState:t,isConnected:computed(()=>!1),isInitialized:e,connect:async()=>{},disconnect:()=>{},destroy:()=>{}}}const e=ref(ConnectionState.DISCONNECTED),n=ref(!1);LiveChatta.init(t),n.value=!0;const o=()=>{e.value=ConnectionState.CONNECTED},a=()=>{e.value=ConnectionState.DISCONNECTED},C=()=>{e.value=ConnectionState.RECONNECTING},i=()=>{e.value=ConnectionState.CONNECTED};LiveChatta.on(SDKEvent.CONNECTED,o),LiveChatta.on(SDKEvent.DISCONNECTED,a),LiveChatta.on(SDKEvent.RECONNECTING,C),LiveChatta.on(SDKEvent.RECONNECTED,i);const c=computed(()=>{if(!n.value)return null;try{return LiveChatta.sock()}catch(t){return null}}),E=computed(()=>{if(!n.value)return null;try{return LiveChatta.api()}catch(t){return null}}),u=computed(()=>e.value===ConnectionState.CONNECTED),v=()=>{LiveChatta.off(SDKEvent.CONNECTED,o),LiveChatta.off(SDKEvent.DISCONNECTED,a),LiveChatta.off(SDKEvent.RECONNECTING,C),LiveChatta.off(SDKEvent.RECONNECTED,i),LiveChatta.destroy(),n.value=!1,e.value=ConnectionState.DISCONNECTED};return onUnmounted(v),{sock:c,api:E,connectionState:e,isConnected:u,isInitialized:n,connect:async()=>{await LiveChatta.connect()},disconnect:()=>{LiveChatta.disconnect()},destroy:v}}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useLiveChatta.js","sourceRoot":"","sources":["../../../src/platforms/nuxt/useLiveChatta.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,WAAW,EAA8B,MAAM,KAAK,CAAC;AAC7E,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAsBxE;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAAC,OAAoB;IAChD,2CAA2C;IAC3C,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;QAClC,MAAM,eAAe,GAAG,GAAG,CAAkB,eAAe,CAAC,YAAY,CAAC,CAAC;QAC3E,MAAM,aAAa,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC;QACjC,MAAM,IAAI,GAAG,QAAQ,CAAmB,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC;QACpD,MAAM,GAAG,GAAG,QAAQ,CAAiB,GAAG,EAAE,CA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AAC,OAAO,EAAE,CAAC;QACrB,aAAa,CAAC,KAAK,GAAG,KAAK,CAAC;QAC5B,eAAe,CAAC,KAAK,GAAG,eAAe,CAAC,YAAY,CAAC;IACvD,CAAC,CAAC;IAEF,WAAW,CAAC,OAAO,CAAC,CAAC;IAErB,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,eAAe,EAAE,WAAW,EAAE,aAAa,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,CAAC;AAClG,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { LauncherOptions, EmbedLayout, ThemeMode } from '@livechatta/sdk';
|
|
2
|
+
export interface LiveChattaViewProps extends LauncherOptions {
|
|
3
|
+
/** Required — chat link code */
|
|
4
|
+
linkCode: string;
|
|
5
|
+
/** Required — API key */
|
|
6
|
+
apiKey: string;
|
|
7
|
+
/** RSA public key (PEM) for encrypting the embed token */
|
|
8
|
+
publicKey?: string;
|
|
9
|
+
/** Required — chat username identifying the individual accessing the embed */
|
|
10
|
+
chatUsername: string;
|
|
11
|
+
/** Base URL of the LiveChatta server */
|
|
12
|
+
baseUrl?: string;
|
|
13
|
+
/** Primary brand colour (hex). Default: link theme, else Signal '#D2400B' */
|
|
14
|
+
primaryColor?: string;
|
|
15
|
+
/** Secondary colour (hex). Default: link theme, else Signal lagoon '#0B6E66' */
|
|
16
|
+
secondaryColor?: string;
|
|
17
|
+
/** Lighter shade of primary */
|
|
18
|
+
primaryLight?: string;
|
|
19
|
+
/** Darker shade of primary */
|
|
20
|
+
primaryDark?: string;
|
|
21
|
+
/** Primary background tint */
|
|
22
|
+
primaryBg?: string;
|
|
23
|
+
/** Main background color */
|
|
24
|
+
bg?: string;
|
|
25
|
+
/** Darker background color */
|
|
26
|
+
bgDark?: string;
|
|
27
|
+
/** Primary text color */
|
|
28
|
+
textColor?: string;
|
|
29
|
+
/** Secondary text color */
|
|
30
|
+
textLight?: string;
|
|
31
|
+
/** Muted text color */
|
|
32
|
+
textMuted?: string;
|
|
33
|
+
/** Border color */
|
|
34
|
+
borderColor?: string;
|
|
35
|
+
/** Light border color */
|
|
36
|
+
borderLight?: string;
|
|
37
|
+
/** Custom font family */
|
|
38
|
+
fontFamily?: string;
|
|
39
|
+
/** Custom logo URL */
|
|
40
|
+
logoUrl?: string;
|
|
41
|
+
/** Theme mode. Default: 'light' inline, 'system' floating */
|
|
42
|
+
theme?: ThemeMode;
|
|
43
|
+
/** Message layout. Default: the link's setting */
|
|
44
|
+
layout?: EmbedLayout;
|
|
45
|
+
/** Width (iframe inline / panel floating). Default: '100%' / '380px' */
|
|
46
|
+
width?: string;
|
|
47
|
+
/** Height (iframe inline / panel floating). Default: '600px' / '640px' */
|
|
48
|
+
height?: string;
|
|
49
|
+
/** CSS class name for the container div */
|
|
50
|
+
className?: string;
|
|
51
|
+
/** Inline style for the container div */
|
|
52
|
+
style?: Record<string, string | number>;
|
|
53
|
+
/** Callback when a message is received from the embed */
|
|
54
|
+
onMessage?: (data: any) => void;
|
|
55
|
+
/** Callback on errors */
|
|
56
|
+
onError?: (error: any) => void;
|
|
57
|
+
}
|
|
58
|
+
export declare function LiveChattaView(props: LiveChattaViewProps): any;
|