Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Something went wrong #372

Open
BasitCh opened this issue Nov 12, 2023 · 0 comments
Open

Something went wrong #372

BasitCh opened this issue Nov 12, 2023 · 0 comments

Comments

@BasitCh
Copy link

BasitCh commented Nov 12, 2023

I am unable to login identified user here is my code and it always say Something went wrong

import 'dart:convert';
import 'dart:io';

import 'package:bamboo_connected/src/infrastructure/services/user_singleton.dart';
import 'package:crypto/crypto.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:intercom_flutter/intercom_flutter.dart';

class IntercomService {
  static Future<void> initialize() async {
    await Intercom.instance.initialize(
      '',
      iosApiKey: '',
      androidApiKey: '',
    );
  }

  static Future<void> display() async {
    await Intercom.instance.displayMessenger();
  }

  static Future<void> sendToken() async {
    final firebaseMessaging = FirebaseMessaging.instance;
    final intercomToken = Platform.isIOS
        ? await firebaseMessaging.getAPNSToken()
        : await firebaseMessaging.getToken();

    await Intercom.instance.sendTokenToIntercom(intercomToken!);
  }

  static Future<void> register({
    dynamic Function()? onSuccess,
    dynamic Function(IntercomError)? onFailure,
  }) async {
    IntercomStatusCallback? callback;
    if (onSuccess != null || onFailure != null) {
      callback =
          IntercomStatusCallback(onSuccess: onSuccess, onFailure: onFailure);
    }
    final user = UserSingleton().user;
    print(user?.toJson());
    final userId = user?.iccId ?? user?.id??'';
    final secretKey = Platform.isAndroid
        ? ''
        : Platform.isIOS
            ? ''
            : '';
    final key = utf8.encode(secretKey);
    final bytes = utf8.encode(userId);
    final hmac = Hmac(sha256, key);
    final userHash = hmac.convert(bytes).toString();
    await Intercom.instance.setUserHash(userHash);
    await Intercom.instance
        .loginIdentifiedUser(userId: userId, statusCallback: callback);
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant