@wppconnect/wa-js - v4.6.0
    Preparing search index...

    Function getUsername

    • Get the username (@username) currently associated with a LID

      This is the reverse of queryUsernameExists: it answers "which username does this contact have now?". Use it to refresh a username you displayed earlier, since usernames are mutable while the LID is not.

      By default the locally stored username is returned when there is one. Pass refresh to always query the server, which also updates the local record.

      Parameters

      • contactId: string | Wid

        The contact LID. Only LIDs carry a username.

      • refresh: boolean = false

        Skip the local record and query the server

      Returns Promise<GetUsernameResult>

      // Cached when available, otherwise queried
      const result = await WPP.contact.getUsername('[lid]@lid');
      console.log(result.username);

      // Always hit the server and refresh the stored value
      const result = await WPP.contact.getUsername('[lid]@lid', true);
      if (result.usernameChanged) {
      console.log(`${result.oldUsername} is now ${result.username}`);
      }