getProfileName method

Future<String?> getProfileName(
  1. String phoneNumber
)

Gets the profile name for a phone number.

phoneNumber is the phone number to look up. Returns the profile name if available, null otherwise.

Implementation

Future<String?> getProfileName(String phoneNumber) async {
  _logger.info('Getting profile name for: $phoneNumber');

  try {
    if (!isValidPhoneNumber(phoneNumber)) {
      throw MessageException.invalidRecipient('Invalid phone number format');
    }

    // TODO: Use normalized phone number when API client integration is implemented
    // ignore: unused_local_variable
    final normalized = normalizePhoneNumber(phoneNumber);

    // The WhatsApp API currently doesn't provide a direct way to get profile name
    // This is a placeholder for future implementation.

    _logger.warning('WhatsApp API does not provide a direct way to get profile name');
    return null;
  } catch (e) {
    if (e is MessageException) rethrow;

    _logger.error('Failed to get profile name', e);
    throw MessageException(
      code: 'get_profile_name_error',
      message: 'Failed to get profile name: ${e.toString()}',
      originalException: e,
    );
  }
}