From c983a751eb52f8fa9d2b61ca2d2add32c5b823bf Mon Sep 17 00:00:00 2001 From: Kartheek Pagidimarri Date: Tue, 10 Sep 2024 16:20:55 +0530 Subject: [PATCH] Webhook channel bug fixes --- README.md | 2 +- .../ChatMessagesViewController.swift | 98 ++++++++++++++++--- .../KoreBotSDK/BrandindFiles/branding.json | 56 +---------- 3 files changed, 84 insertions(+), 72 deletions(-) diff --git a/README.md b/README.md index 91af75f9..38f67b9b 100755 --- a/README.md +++ b/README.md @@ -92,7 +92,7 @@ Enable the webhook channel - This should be either true (in case of Webhook conn #### 1. Setup KoreBotSDK ###### a. Using SPM dependencies: [ - .package(url: "https://github.com/Koredotcom/iOS-kore-sdk", .upToNextMajor(from: "1.0.6")) + .package(url: "https://github.com/Koredotcom/iOS-kore-sdk", .upToNextMajor(from: "1.0.7")) ] ###### b. In your ViewController add below lines 1. import KoreBotSDK diff --git a/Sources/KoreBotSDK/AppKit/Controllers/ChatMessages/ChatMessagesViewController.swift b/Sources/KoreBotSDK/AppKit/Controllers/ChatMessages/ChatMessagesViewController.swift index 7ad15bdd..0e4da944 100755 --- a/Sources/KoreBotSDK/AppKit/Controllers/ChatMessages/ChatMessagesViewController.swift +++ b/Sources/KoreBotSDK/AppKit/Controllers/ChatMessages/ChatMessagesViewController.swift @@ -943,7 +943,9 @@ class ChatMessagesViewController: UIViewController, BotMessagesViewDelegate, Com case .reachable(.ethernetOrWiFi), .reachable(.cellular): if isTryConnect{ isInternetAvailable = true - self.establishBotConnection() + if !SDKConfiguration.botConfig.isWebhookEnabled{ + self.establishBotConnection() + } if isAgentConnect{ Timer.scheduledTimer(withTimeInterval: 3.0, repeats: false) { (_) in self.stopLoader() @@ -1118,11 +1120,8 @@ class ChatMessagesViewController: UIViewController, BotMessagesViewDelegate, Com } func receviceMessage(dictionary:[String: Any]){ - - let data: Array = dictionary["data"] != nil ? dictionary["data"] as! Array : [] for i in 0.. 0 && (componentType == .carousel || componentType == .chart || componentType == .table || componentType == .minitable || componentType == .responsiveTable) { textMessage = Message() @@ -1178,9 +1185,17 @@ class ChatMessagesViewController: UIViewController, BotMessagesViewDelegate, Com textMessage?.addComponent(textComponent) } - let optionsComponent: Component = Component(componentType) - optionsComponent.payload = Utilities.stringFromJSONObject(object: dictionary) - message.addComponent(optionsComponent) + if templateType == "SYSTEM" || templateType == "live_agent" || templateType == ""{ + let textComponent = Component(.text) + let text = dictionary["text"] as? String ?? "" + textComponent.payload = text + ttsBody = text + message.addComponent(textComponent) + }else{ + let optionsComponent: Component = Component(componentType) + optionsComponent.payload = Utilities.stringFromJSONObject(object: dictionary) + message.addComponent(optionsComponent) + } } case "image": if let _ = jsonObject["payload"] as? [String: Any] { @@ -1216,6 +1231,13 @@ class ChatMessagesViewController: UIViewController, BotMessagesViewDelegate, Com message.sentDate = self.dateFormatter().date(from: valData["createdOn"] as? String ?? "") message.addComponent(optionsComponent) } + case "link": + if let dictionary = jsonObject["payload"] as? [String: Any] { + let componentType = Component(.linkDownload) + let optionsComponent: Component = componentType + optionsComponent.payload = Utilities.stringFromJSONObject(object: dictionary) + message.addComponent(optionsComponent) + } case "error": if let dictionary = jsonObject["payload"] as? [String: Any] { let errorComponent: Component = Component(.error) @@ -1228,6 +1250,14 @@ class ChatMessagesViewController: UIViewController, BotMessagesViewDelegate, Com let textComponent: Component = Component() textComponent.payload = text message.addComponent(textComponent) + }else{ + if let dictionary = jsonObject["payload"] as? [String: Any], + let text = dictionary["text"] as? String{ + let textComponent = Component() + textComponent.payload = text + ttsBody = text + message.addComponent(textComponent) + } } } }else if let jsonObject: [String: Any] = valData["val"] as? [String : Any]{ @@ -1237,17 +1267,27 @@ class ChatMessagesViewController: UIViewController, BotMessagesViewDelegate, Com switch type { case "template": if let dictionary = jsonObject["payload"] as? [String: Any] { - let templateType = dictionary["template_type"] as? String ?? "" + var templateType = dictionary["template_type"] as? String ?? "" var tabledesign = "responsive" if let value = dictionary["table_design"] as? String { tabledesign = value } + if !isShowQuickRepliesBottom{ + if templateType == "quick_replies"{ + templateType = "quick_replies_top" + } + } let componentType = getComponentType(templateType, tabledesign) if componentType != .quickReply { } + if templateType == "feedbackTemplate"{ + //if !history{ + feedBackTemplateSelectedValue = "" + //} + } ttsBody = dictionary["speech_hint"] != nil ? dictionary["speech_hint"] as? String : nil if let tText = dictionary["text"] as? String, tText.count > 0 && (componentType == .carousel || componentType == .chart || componentType == .table || componentType == .minitable || componentType == .responsiveTable) { textMessage = Message() @@ -1262,9 +1302,17 @@ class ChatMessagesViewController: UIViewController, BotMessagesViewDelegate, Com textMessage?.addComponent(textComponent) } - let optionsComponent: Component = Component(componentType) - optionsComponent.payload = Utilities.stringFromJSONObject(object: dictionary) - message.addComponent(optionsComponent) + if templateType == "SYSTEM" || templateType == "live_agent" || templateType == ""{ + let textComponent = Component(.text) + let text = dictionary["text"] as? String ?? "" + textComponent.payload = text + ttsBody = text + message.addComponent(textComponent) + }else{ + let optionsComponent: Component = Component(componentType) + optionsComponent.payload = Utilities.stringFromJSONObject(object: dictionary) + message.addComponent(optionsComponent) + } } case "image": if let _ = jsonObject["payload"] as? [String: Any] { @@ -1300,6 +1348,13 @@ class ChatMessagesViewController: UIViewController, BotMessagesViewDelegate, Com message.sentDate = self.dateFormatter().date(from: valData["createdOn"] as? String ?? "") message.addComponent(optionsComponent) } + case "link": + if let dictionary = jsonObject["payload"] as? [String: Any] { + let componentType = Component(.linkDownload) + let optionsComponent: Component = componentType + optionsComponent.payload = Utilities.stringFromJSONObject(object: dictionary) + message.addComponent(optionsComponent) + } case "error": if let dictionary = jsonObject["payload"] as? [String: Any] { let errorComponent: Component = Component(.error) @@ -1312,6 +1367,14 @@ class ChatMessagesViewController: UIViewController, BotMessagesViewDelegate, Com let textComponent: Component = Component() textComponent.payload = text message.addComponent(textComponent) + }else{ + if let dictionary = jsonObject["payload"] as? [String: Any], + let text = dictionary["text"] as? String{ + let textComponent = Component() + textComponent.payload = text + ttsBody = text + message.addComponent(textComponent) + } } } } @@ -1326,6 +1389,7 @@ class ChatMessagesViewController: UIViewController, BotMessagesViewDelegate, Com message.addComponent(textComponent) lastMessageID = valData["messageId"] as? String } + historyLimit += 1 addMessages(message, ttsBody) NotificationCenter.default.post(name: Notification.Name("StopTyping"), object: nil) } @@ -1874,8 +1938,10 @@ extension ChatMessagesViewController { }) } func tableviewScrollDidEnd(){ - if SDKConfiguration.botConfig.isShowChatHistory{ - fetchMessages() + if !SDKConfiguration.botConfig.isWebhookEnabled{ + if SDKConfiguration.botConfig.isShowChatHistory{ + fetchMessages() + } } } } diff --git a/Sources/KoreBotSDK/BrandindFiles/branding.json b/Sources/KoreBotSDK/BrandindFiles/branding.json index a01ec8ee..208cb44b 100755 --- a/Sources/KoreBotSDK/BrandindFiles/branding.json +++ b/Sources/KoreBotSDK/BrandindFiles/branding.json @@ -1,55 +1 @@ -{ - "_id": "wsth-07f8a741-8cb5-54e8-aefb-acc9748a9f06", - "streamId": "st-183e9c7d-fc8a-56d8-ba47-2733f8767d6b", - "__v": 0, - "activeTheme": true, - "botMessage": { - "bubbleColor": "#abfd07", - "fontColor": "#202124", - "borderColor": "#F3F5F8" - }, - "buttons": { - "defaultButtonColor": "#ff0069", - "defaultFontColor": "#ffffff", - "onHoverButtonColor": "#0659d2", - "onHoverFontColor": "#ffffff", - "borderColor": "#0D6EFD" - }, - "createdBy": "u-5e260374-e615-5d10-8617-1f98b5cc2ab8", - "createdOn": "2024-06-06T06:37:29.890Z", - "defaultTheme": false, - "digitalViews": { - "panelTheme": "theme_one" - }, - "generalAttributes": { - "fontStyle": "arial", - "bubbleShape": "square", - "borderColor": "#F3F5F8" - }, - "lastModifiedBy": "u-5e260374-e615-5d10-8617-1f98b5cc2ab8", - "lastModifiedOn": "2024-06-06T06:37:29.890Z", - "refId": "b99b82ae-dbf7-5506-98fa-7d4e5bccd2f3", - "state": "published", - "themeName": "Theme2", - "userMessage": { - "bubbleColor": "#ff0000", - "fontColor": "#ffffff", - "borderColor": "#0D6EFD" - }, - "widgetBody": { - "backgroundImage": "", - "backgroundColor": "#ffffff", - "useBackgroundImage": false - }, - "widgetFooter": { - "backgroundColor": "#FFFFFF", - "fontColor": "#262626", - "borderColor": "#E4E5E7", - "placeHolder": "#D0D0D0" - }, - "widgetHeader": { - "backgroundColor": "#0D6EFD", - "fontColor": "#ffffff", - "borderColor": "#e5e8ec" - } -} +{"_id":"wsth-17fc51b0-8e94-5e71-9546-aade57580d66","streamId":"st-3f826975-eadb-53af-92b7-3430a1f5353a","__v":0,"activeTheme":true,"botMessage":{"bubbleColor":"#F3F5F8","fontColor":"#202124","borderColor":"#F3F5F8"},"buttons":{"defaultButtonColor":"#0D6EFD","defaultFontColor":"#ffffff","borderColor":"#0D6EFD","onHoverButtonColor":"#0659d2","onHoverFontColor":"#ffffff"},"createdBy":"u-4e544230-10fd-5c14-9fb5-9120bdba169b","createdOn":"2024-02-14T16:14:33.784Z","defaultTheme":true,"digitalViews":{"panelTheme":"theme_one"},"generalAttributes":{"fontStyle":"arial","bubbleShape":"square","borderColor":"#F3F5F8","backgroundColor":"F3F5F8"},"lastModifiedBy":"u-4e544230-10fd-5c14-9fb5-9120bdba169b","lastModifiedOn":"2024-02-14T16:14:33.783Z","refId":"12b50ae4-f90e-5f81-88c9-c2828e695673","state":"published","themeName":"Default light theme","userMessage":{"bubbleColor":"#0D6EFD","fontColor":"#ffffff","borderColor":"#0D6EFD"},"widgetBody":{"backgroundImage":"","backgroundColor":"#ffffff"},"widgetFooter":{"borderColor":"#E4E5E7","fontColor":"#262626","backgroundColor":"#FFFFFF","placeHolderColor":"#262626"},"widgetHeader":{"backgroundColor":"#0D6EFD","fontColor":"#ffffff","borderColor":"#e5e8ec"}}