updateUser method

  1. @override
Future<void> updateUser({
  1. String? email,
  2. String? name,
  3. String? phone,
  4. String? company,
  5. String? companyId,
  6. String? userId,
  7. int? signedUpAt,
  8. String? language,
  9. Map<String, dynamic>? customAttributes,
  10. IntercomStatusCallback? statusCallback,
})
override

Updates the attributes of the current Intercom user.

The signedUpAt param should be seconds since epoch.

The language param should be an an ISO 639-1 two-letter code such as en for English or fr for French. You’ll need to use a four-letter code for Chinese like zh-CN. check this link https://www.intercom.com/help/en/articles/180-localize-intercom-to-work-with-multiple-languages.

See also:

Implementation

@override
Future<void> updateUser({
  String? email,
  String? name,
  String? phone,
  String? company,
  String? companyId,
  String? userId,
  int? signedUpAt,
  String? language,
  Map<String, dynamic>? customAttributes,
  IntercomStatusCallback? statusCallback,
}) async {
  Map<String, dynamic> userAttributes = {};

  if (name != null) {
    userAttributes['name'] = name;
  }

  if (email != null) {
    userAttributes['email'] = email;
  }

  if (phone != null) {
    userAttributes['phone'] = phone;
  }

  if (userId != null) {
    userAttributes['user_id'] = userId;
  }

  if (company != null && companyId != null) {
    Map<String, dynamic> companyObj = {};
    companyObj['company_id'] = companyId;
    companyObj['name'] = company;

    userAttributes['company'] = companyObj;
  }

  if (customAttributes != null) {
    customAttributes.forEach((key, value) {
      userAttributes[key] = value;
    });
  }

  if (signedUpAt != null) {
    userAttributes['created_at'] = signedUpAt;
  }

  if (language != null) {
    userAttributes['language_override'] = language;
  }

  await js.context.callMethod('Intercom', [
    'update',
    js.JsObject.jsify(userAttributes),
  ]);
  // send the success callback only as web doesnot support the statusCallback.
  statusCallback?.onSuccess?.call();
}