Skip to content

Commit

Permalink
Merge pull request #130 from Kommunicate-io/CM-2026
Browse files Browse the repository at this point in the history
[CM-2026] Added Support for EU Servers
  • Loading branch information
kandpal025 committed Apr 23, 2024
2 parents 933ef4b + 363ee9b commit 1877fc9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result;
import io.flutter.plugin.common.PluginRegistry.Registrar;
import io.kommunicate.KMServerConfiguration;
import io.kommunicate.KmConversationBuilder;
import io.kommunicate.KmSettings;
import io.kommunicate.Kommunicate;
Expand Down Expand Up @@ -55,7 +56,6 @@ public class KmMethodHandler implements MethodCallHandler {
private static final String ERROR = "Error";
private Activity context;
private MethodChannel methodChannel;

public KmMethodHandler(Activity context) {
this.context = context;
}
Expand All @@ -64,6 +64,22 @@ public KmMethodHandler(Activity context) {
public void onMethodCall(MethodCall call, final Result result) {
if (call.method.equals("getPlatformVersion")) {
result.success("Android " + android.os.Build.VERSION.RELEASE);
} else if (call.method.equals("setServerConfiguration")){
try {
String serverConfigText = (String) call.arguments();
if (!TextUtils.isEmpty(serverConfigText)) {
if (serverConfigText == "euConfiguration") {
Kommunicate.setServerConfiguration(context, KMServerConfiguration.EUCONFIGURATION);
} else {
Kommunicate.setServerConfiguration(context, KMServerConfiguration.DEFAULTCONFIGURATION);
}
} else {
result.error(ERROR, "Invalid Server Config", null);
return;
}
} catch (Exception e) {
result.error(ERROR, e.toString(), null);
}
} else if (call.method.equals("isLoggedIn")) {
result.success(Kommunicate.isLoggedIn(context));
} else if (call.method.equals("login")) {
Expand Down
16 changes: 12 additions & 4 deletions ios/Classes/SwiftKommunicateFlutterPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class SwiftKommunicateFlutterPlugin: NSObject, FlutterPlugin, KMPreChatFo
}

func addListener() {
Kommunicate.subscribeCustomEvents(events: [CustomEvent.messageReceive, CustomEvent.messageSend,CustomEvent.faqClick, CustomEvent.newConversation, CustomEvent.submitRatingClick, CustomEvent.restartConversationClick, CustomEvent.richMessageClick, CustomEvent.conversationBackPress, CustomEvent.conversationListBackPress, CustomEvent.conversationInfoClick ], callback: self)
Kommunicate.subscribeCustomEvents(events: [KMCustomEvent.messageReceive, KMCustomEvent.messageSend,KMCustomEvent.faqClick, KMCustomEvent.newConversation, KMCustomEvent.submitRatingClick, KMCustomEvent.restartConversationClick, KMCustomEvent.richMessageClick, KMCustomEvent.conversationBackPress, KMCustomEvent.conversationListBackPress, KMCustomEvent.conversationInfoClick ], callback: self)
}
func removeListener() {
Kommunicate.unsubcribeCustomEvents()
Expand All @@ -46,6 +46,16 @@ public class SwiftKommunicateFlutterPlugin: NSObject, FlutterPlugin, KMPreChatFo

if(call.method == "getPlatformVersion") {
result("iOS " + UIDevice.current.systemVersion)
} else if(call.method == "setServerConfiguration") {
guard let serverConfig = call.arguments as? String else {
self.sendErrorResultWithCallback(result: result, message: "Invalid Server Config")
return
}
if (serverConfig == "euConfiguration") {
Kommunicate.setServerConfiguration(.euConfiguration)
} else {
Kommunicate.setServerConfiguration(.defaultConfiguration)
}
} else if(call.method == "isLoggedIn") {
result(Kommunicate.isLoggedIn)
} else if(call.method == "login") {
Expand Down Expand Up @@ -84,7 +94,6 @@ public class SwiftKommunicateFlutterPlugin: NSObject, FlutterPlugin, KMPreChatFo
self.sendErrorResultWithCallback(result: result, message: "Invalid or missing appId")
return
}

Kommunicate.setup(applicationId: appId)
let kmUser = Kommunicate.createVisitorUser()
kmUser.applicationId = appId
Expand Down Expand Up @@ -322,7 +331,6 @@ public class SwiftKommunicateFlutterPlugin: NSObject, FlutterPlugin, KMPreChatFo

self.agentIds = agentIds
self.botIds = botIds

if Kommunicate.isLoggedIn{
self.handleCreateConversation()
}else{
Expand Down Expand Up @@ -753,7 +761,7 @@ public class SwiftKommunicateFlutterPlugin: NSObject, FlutterPlugin, KMPreChatFo
public func richMessageClicked(conversationId: String, action: Any, type: String) {
let jsonEncoder = JSONEncoder()
var actionString: String = ""
if action is ListTemplate.Element, let actionElement = action as? ListTemplate.Element,
if action is KMListTemplate.Element, let actionElement = action as? KMListTemplate.Element,
let jsonData = try? jsonEncoder.encode(actionElement)
{
actionString = String(data: jsonData, encoding: String.Encoding.utf8) ?? ""
Expand Down
3 changes: 3 additions & 0 deletions lib/kommunicate_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,7 @@ class KommunicateFlutterPlugin {
static Future<dynamic> hideAssigneeStatus(bool hide) async {
return await _channel.invokeMethod('hideAssigneeStatus', hide);
}
static Future<dynamic> setServerConfiguration(String serverName) async {
return await _channel.invokeListMethod('setServerConfiguration', serverName);
}
}

0 comments on commit 1877fc9

Please sign in to comment.