Skip to content

Commit 7aca00a

Browse files
JoshKiffclaude
andcommitted
feat: add changeWorkspace method
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent b77e32e commit 7aca00a

File tree

6 files changed

+71
-0
lines changed

6 files changed

+71
-0
lines changed

intercom_flutter/android/src/main/kotlin/io/maido/intercom/IntercomFlutterPlugin.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,16 @@ class IntercomFlutterPlugin : FlutterPlugin, MethodCallHandler, EventChannel.Str
298298
})
299299
}
300300
}
301+
"changeWorkspace" -> {
302+
val appId = call.argument<String>("appId")
303+
val androidApiKey = call.argument<String>("androidApiKey")
304+
if (appId != null && androidApiKey != null) {
305+
Intercom.client().changeWorkspace(androidApiKey, appId)
306+
result.success("Workspace changed")
307+
} else {
308+
result.error("INVALID_ARGUMENTS", "appId and androidApiKey are required", null)
309+
}
310+
}
301311
else -> result.notImplemented()
302312
}
303313
}

intercom_flutter/ios/Classes/IntercomFlutterPlugin.m

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,20 @@ - (void) handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
285285
details: [self getIntercomError:errorCode:errorMsg]]);
286286
}];
287287
}
288+
} else if([@"changeWorkspace" isEqualToString:call.method]) {
289+
NSString *iosApiKey = call.arguments[@"iosApiKey"];
290+
NSString *appId = call.arguments[@"appId"];
291+
if (iosApiKey != nil && iosApiKey != (id)[NSNull null] &&
292+
appId != nil && appId != (id)[NSNull null]) {
293+
// iOS doesn't have native changeWorkspace, so logout and re-initialize
294+
[Intercom logout];
295+
[Intercom setApiKey:iosApiKey forAppId:appId];
296+
result(@"Workspace changed");
297+
} else {
298+
result([FlutterError errorWithCode:@"INVALID_ARGUMENTS"
299+
message:@"appId and iosApiKey are required"
300+
details:nil]);
301+
}
288302
}
289303
else {
290304
result(FlutterMethodNotImplemented);

intercom_flutter/lib/intercom_flutter.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,4 +304,19 @@ class Intercom {
304304
Future<void> setAuthTokens(Map<String, String> tokens) {
305305
return IntercomFlutterPlatform.instance.setAuthTokens(tokens);
306306
}
307+
308+
/// Changes the Intercom workspace.
309+
///
310+
/// On Android: Uses native changeWorkspace API (SDK 16.1.0+)
311+
/// On iOS: Logs out and re-initializes with new credentials
312+
///
313+
/// This will logout the current user and clear all SDK data.
314+
/// You must call login again after changing workspace.
315+
///
316+
/// [appId] is required for both platforms.
317+
/// [androidApiKey] is required for Android.
318+
/// [iosApiKey] is required for iOS.
319+
Future<void> changeWorkspace(String appId, {String? androidApiKey, String? iosApiKey}) {
320+
return IntercomFlutterPlatform.instance.changeWorkspace(appId, androidApiKey: androidApiKey, iosApiKey: iosApiKey);
321+
}
307322
}

intercom_flutter_platform_interface/lib/intercom_flutter_platform_interface.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,4 +295,19 @@ abstract class IntercomFlutterPlatform extends PlatformInterface {
295295
Future<void> setAuthTokens(Map<String, String> tokens) {
296296
throw UnimplementedError('setAuthTokens() has not been implemented.');
297297
}
298+
299+
/// Changes the Intercom workspace.
300+
///
301+
/// On Android: Uses native changeWorkspace API (SDK 16.1.0+)
302+
/// On iOS: Logs out and re-initializes with new credentials
303+
///
304+
/// This will logout the current user and clear all SDK data.
305+
/// You must call login again after changing workspace.
306+
///
307+
/// [appId] is required for both platforms.
308+
/// [androidApiKey] is required for Android.
309+
/// [iosApiKey] is required for iOS.
310+
Future<void> changeWorkspace(String appId, {String? androidApiKey, String? iosApiKey}) {
311+
throw UnimplementedError('changeWorkspace() has not been implemented.');
312+
}
298313
}

intercom_flutter_platform_interface/lib/method_channel_intercom_flutter.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,11 @@ class MethodChannelIntercomFlutter extends IntercomFlutterPlatform {
265265
await _channel.invokeMethod('setAuthTokens', {'tokens': tokens});
266266
}
267267

268+
@override
269+
Future<void> changeWorkspace(String appId, {String? androidApiKey, String? iosApiKey}) async {
270+
await _channel.invokeMethod('changeWorkspace', {'appId': appId, 'androidApiKey': androidApiKey, 'iosApiKey': iosApiKey});
271+
}
272+
268273
/// Convert the [PlatformException] details to [IntercomError].
269274
/// From the Platform side if the intercom operation failed then error details
270275
/// will be sent as details in [PlatformException].

intercom_flutter_web/lib/intercom_flutter_web.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,18 @@ class IntercomFlutterWeb extends IntercomFlutterPlatform {
352352
print("Auth tokens added");
353353
}
354354

355+
@override
356+
Future<void> changeWorkspace(String appId, {String? androidApiKey, String? iosApiKey}) async {
357+
// For web, we shutdown the current workspace and boot with the new appId
358+
// Clear user data first
359+
removeIntercomSettings(['user_hash', 'intercom_user_jwt', 'user_id', 'email', 'auth_tokens']);
360+
// Shutdown current workspace
361+
globalContext.callMethod('Intercom'.toJS, 'shutdown'.toJS);
362+
// Boot with new workspace
363+
globalContext.callMethod('Intercom'.toJS, 'boot'.toJS, updateIntercomSettings('app_id', appId).jsify());
364+
print("Workspace changed");
365+
}
366+
355367
/// get the [window.intercomSettings]
356368
Map<dynamic, dynamic> getIntercomSettings() {
357369
if (globalContext.hasProperty('intercomSettings'.toJS).toDart) {

0 commit comments

Comments
 (0)