kyuurzy

Check Username WhatsApp

Jul 10th, 2026 (edited)
226
0
Never
2
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 2.31 KB | Source Code | 0 0
  1. const wMexQuery = (variables, queryId) => {
  2.     return sock.query({
  3.         tag: 'iq',
  4.         attrs: {
  5.             id: sock.generateMessageTag(),
  6.             type: 'get',
  7.             to: 's.whatsapp.net',
  8.             xmlns: 'w:mex'
  9.         },
  10.         content: [
  11.             {
  12.                 tag: 'query',
  13.                 attrs: { query_id: queryId },
  14.                 content: Buffer.from(JSON.stringify({ variables }), 'utf-8')
  15.             }
  16.         ]
  17.     })
  18. }
  19.  
  20. const executeWMexQuery = async (variables, queryId, dataPath) => {
  21.     const result = await wMexQuery(variables, queryId)
  22.     const child = result?.content?.[0]
  23.     if (child?.content) {
  24.         const data = JSON.parse(child.content.toString())
  25.         if (data.errors && data.errors.length > 0) {
  26.             throw new Error(data.errors.map(err => err.message).join(', '))
  27.         }
  28.         const response = dataPath ? data?.data?.[dataPath] : data?.data
  29.         if (typeof response !== 'undefined') {
  30.             return response
  31.         }
  32.     }
  33.     throw new Error('Failed to execute query')
  34. }
  35.  
  36. const USERNAME_QUERY_IDS = {
  37.     CHECK: '26124072630599518'
  38. }
  39.  
  40. const USERNAME_CHECK_RESULT = {
  41.     SUCCESS: 'SUCCESS'
  42. }
  43.  
  44. const USERNAME_SOURCE = {
  45.     USER_INPUT: 'USER_INPUT'
  46. }
  47.  
  48. const checkUsername = async (username, includeSuggestions = true, sessionId) => {
  49.     const crypto = require('crypto')
  50.     const session_id = sessionId || crypto.randomUUID()
  51.     const data = await executeWMexQuery(
  52.         {
  53.             username,
  54.             include_suggestions: includeSuggestions,
  55.             session_id,
  56.             source: USERNAME_SOURCE.USER_INPUT
  57.         },
  58.         USERNAME_QUERY_IDS.CHECK,
  59.         'xwa2_username_check'
  60.     )
  61.     if (data?.result === USERNAME_CHECK_RESULT.SUCCESS) {
  62.         return { available: true, username, session_id }
  63.     }
  64.     return {
  65.         available: false,
  66.         username,
  67.         session_id,
  68.         suggestions: data?.suggestions ?? [],
  69.         rejectionReasons: data?.rejection_reasons ?? [],
  70.         suggestionsEligible: data?.suggestions_eligible ?? true
  71.     }
  72. }
  73.  
  74. /* result:
  75. {
  76.   available: false,
  77.   username: 'username',
  78.   session_id: 'xxxx-35a9-4f4a-xxxx-xxxx',
  79.   suggestions: [ 'username1', 'username2', 'usermame3' ],
  80.   rejectionReasons: [],
  81.   suggestionsEligible: true
  82. }
  83.  
  84. */
Advertisement
Comments
  • User was banned
  • User was banned
Add Comment
Please, Sign In to add comment