Skip to content

Commit 043e335

Browse files
committed
override reset, change init types, depreciation flags
1 parent 5342cda commit 043e335

File tree

1 file changed

+73
-4
lines changed

1 file changed

+73
-4
lines changed

EmbedFramework/AdaWebHost.swift

+73-4
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ public class AdaWebHost: NSObject {
2727

2828
/// Metafields can be passed in during init; use `setMetaFields()` and `setSensitiveMetafields()`
2929
/// to send values in at runtime
30-
private var metafields: [String: String] = [:]
31-
private var sensitiveMetafields: [String: String] = [:]
30+
private var metafields: [String: Any] = [:]
31+
private var sensitiveMetafields: [String: Any] = [:]
3232

3333
public var openWebLinksInSafari = false
3434
public var appScheme = ""
@@ -71,8 +71,8 @@ public class AdaWebHost: NSObject {
7171
language: String = "",
7272
styles: String = "",
7373
greeting: String = "",
74-
metafields: [String: String] = [:],
75-
sensitiveMetafields: [String:String] = [:],
74+
metafields: [String: Any] = [:],
75+
sensitiveMetafields: [String:Any] = [:],
7676
openWebLinksInSafari: Bool = false,
7777
appScheme: String = "",
7878
zdChatterAuthCallback: (((@escaping (_ token: String) -> Void)) -> Void)? = nil,
@@ -142,6 +142,7 @@ public class AdaWebHost: NSObject {
142142
// MARK: - Public Methods
143143

144144
/// Push a dictionary of fields to the server
145+
@available(*, deprecated, message: "This method will be deprecated in the future, please upgrade to MetaFields.Builder.", renamed: "setMetaFields(builder:)")
145146
public func setMetaFields(_ fields: [String: Any]) {
146147
guard let json = try? JSONSerialization.data(withJSONObject: fields, options: []),
147148
let jsonString = String(data: json, encoding: .utf8) else { return }
@@ -151,6 +152,7 @@ public class AdaWebHost: NSObject {
151152
}
152153

153154
/// Push a dictionary of fields to the server
155+
@available(*, deprecated, message: "This method will be deprecated in the future, please upgrade to MetaFields.Builder.", renamed: "setSensitiveMetaFields(builder:)")
154156
public func setSensitiveMetaFields(_ fields: [String: Any]) {
155157
guard let json = try? JSONSerialization.data(withJSONObject: fields, options: []),
156158
let jsonString = String(data: json, encoding: .utf8) else { return }
@@ -179,6 +181,8 @@ public class AdaWebHost: NSObject {
179181
}
180182

181183
/// Re-initialize chat and optionally reset history, language, meta data, etc
184+
@available(*, deprecated, message: "This method will be deprecated in the future, please upgrade to MetaFields.Builder.", renamed: "reset(metaFields:sensitiveMetaFields:)")
185+
/// When this method is depreciated, the 4 override reset methods should be replaced
182186
public func reset(language: String? = nil, greeting: String? = nil, metaFields: [String: Any]? = nil, sensitiveMetaFields: [String: Any]? = nil, resetChatHistory: Bool? = true) {
183187

184188
let data: [String: Any?] = [
@@ -196,6 +200,71 @@ public class AdaWebHost: NSObject {
196200
self.evalJS(toRun)
197201
}
198202

203+
public func reset(language: String? = nil, greeting: String? = nil, metaFields: MetaFields.Builder, resetChatHistory: Bool? = true) {
204+
205+
let data: [String: Any?] = [
206+
"language": language,
207+
"greeting": greeting,
208+
"metaFields": metaFields.build().metaFields,
209+
"sensitiveMetaFields": nil,
210+
"resetChatHistory": resetChatHistory
211+
]
212+
guard let json = try? JSONSerialization.data(withJSONObject: data, options: .fragmentsAllowed),
213+
let jsonString = String(data: json, encoding: .utf8) else { return }
214+
let toRun = "adaEmbed.reset(\(jsonString));"
215+
216+
self.evalJS(toRun)
217+
}
218+
219+
public func reset(language: String? = nil, greeting: String? = nil, sensitiveMetaFields: MetaFields.Builder, resetChatHistory: Bool? = true) {
220+
221+
let data: [String: Any?] = [
222+
"language": language,
223+
"greeting": greeting,
224+
"metaFields": nil,
225+
"sensitiveMetaFields": sensitiveMetaFields.build().metaFields,
226+
"resetChatHistory": resetChatHistory
227+
]
228+
guard let json = try? JSONSerialization.data(withJSONObject: data, options: .fragmentsAllowed),
229+
let jsonString = String(data: json, encoding: .utf8) else { return }
230+
231+
let toRun = "adaEmbed.reset(\(jsonString));"
232+
233+
self.evalJS(toRun)
234+
}
235+
236+
public func reset(language: String? = nil, greeting: String? = nil, metaFields: MetaFields.Builder, sensitiveMetaFields: MetaFields.Builder, resetChatHistory: Bool? = true) {
237+
238+
let data: [String: Any?] = [
239+
"language": language,
240+
"greeting": greeting,
241+
"metaFields": metaFields.build().metaFields,
242+
"sensitiveMetaFields": sensitiveMetaFields.build().metaFields,
243+
"resetChatHistory": resetChatHistory
244+
]
245+
guard let json = try? JSONSerialization.data(withJSONObject: data, options: .fragmentsAllowed),
246+
let jsonString = String(data: json, encoding: .utf8) else { return }
247+
let toRun = "adaEmbed.reset(\(jsonString));"
248+
249+
self.evalJS(toRun)
250+
}
251+
252+
public func reset(language: String? = nil, greeting: String? = nil, resetChatHistory: Bool? = true) {
253+
254+
let data: [String: Any?] = [
255+
"language": language,
256+
"greeting": greeting,
257+
"metaFields": nil,
258+
"sensitiveMetaFields": nil,
259+
"resetChatHistory": resetChatHistory
260+
]
261+
guard let json = try? JSONSerialization.data(withJSONObject: data, options: .fragmentsAllowed),
262+
let jsonString = String(data: json, encoding: .utf8) else { return }
263+
let toRun = "adaEmbed.reset(\(jsonString));"
264+
265+
self.evalJS(toRun)
266+
}
267+
199268
/// Re-initialize chat and optionally reset history, language, meta data, etc
200269
public func deleteHistory() {
201270
let toRun = "adaEmbed.deleteHistory();"

0 commit comments

Comments
 (0)