Skip to content

Commit

Permalink
Webhook channel bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
KartheekPa-Kore committed Sep 10, 2024
1 parent d02c300 commit c983a75
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 72 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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..<data.count{

let message: Message = Message()
message.messageType = .reply
let textComponent: Component = Component()
Expand Down Expand Up @@ -1153,17 +1152,25 @@ 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()
Expand All @@ -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] {
Expand Down Expand Up @@ -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)
Expand All @@ -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]{
Expand All @@ -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()
Expand All @@ -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] {
Expand Down Expand Up @@ -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)
Expand All @@ -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)
}
}
}
}
Expand All @@ -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)
}
Expand Down Expand Up @@ -1874,8 +1938,10 @@ extension ChatMessagesViewController {
})
}
func tableviewScrollDidEnd(){
if SDKConfiguration.botConfig.isShowChatHistory{
fetchMessages()
if !SDKConfiguration.botConfig.isWebhookEnabled{
if SDKConfiguration.botConfig.isShowChatHistory{
fetchMessages()
}
}
}
}
Expand Down
56 changes: 1 addition & 55 deletions Sources/KoreBotSDK/BrandindFiles/branding.json
Original file line number Diff line number Diff line change
@@ -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"}}

0 comments on commit c983a75

Please sign in to comment.