wppconnect-team / wppconnect

WPPConnect is an open source project developed by the JavaScript community with the aim of exporting functions from WhatsApp Web to the node, which can be used to support the creation of any interaction, such as customer service, media sending, intelligence recognition based on phrases artificial and many other things, use your imagination
https://wppconnect.io
Other
1.92k stars 336 forks source link

sanitization error if no session name is specified #2194

Closed gekkedev closed 5 months ago

gekkedev commented 5 months ago

Description

Specifying no session name during client creation causes a crash although the documentation suggests it is optional, especially in the minimal 4 line + 1 import example: https://wppconnect.io/docs/tutorial/basics/creating-client

Environment

Steps to Reproduce

  1. Use the example code but do not specify a session name
  2. Observe being unable to start it

Log Output

  _       ______  ____  ______                            __
  | |     / / __ \/ __ \/ ____/___  ____  ____  ___  _____/ /_
  | | /| / / /_/ / /_/ / /   / __ \/ __ \/ __ \/ _ \/ ___/ __/
  | |/ |/ / ____/ ____/ /___/ /_/ / / / / / / /  __/ /__/ /_
  |__/|__/_/   /_/    \____/\____/_/ /_/_/ /_/\___/\___/\__/
info:     Checking for updates
info:     You're up to date
Error: Input must be string
    at sanitize (C:\wppconnect\node_modules\sanitize-filename\index.js:41:11)
    at module.exports (C:\wppconnect\node_modules\sanitize-filename\index.js:54:16)
    at Object.<anonymous> (C:\wppconnect\node_modules\@wppconnect-team\wppconnect\dist\controllers\initializer.js:173:171)
    at step (C:\wppconnect\node_modules\@wppconnect-team\wppconnect\dist\controllers\initializer.js:83:23)
    at Object.next (C:\wppconnect\node_modules\@wppconnect-team\wppconnect\dist\controllers\initializer.js:64:53)
    at fulfilled (C:\wppconnect\node_modules\@wppconnect-team\wppconnect\dist\controllers\initializer.js:55:58)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

Your Code

// Supports ES6
// import { create, Whatsapp } from '@wppconnect-team/wppconnect';
const wppconnect = require('@wppconnect-team/wppconnect');

wppconnect
  .create({
    session: 'sessionName', //Pass the name of the client you want to start the bot
    catchQR: (base64Qrimg, asciiQR, attempts, urlCode) => {
      console.log('Number of attempts to read the qrcode: ', attempts);
      console.log('Terminal qrcode: ', asciiQR);
      console.log('base64 image string qrcode: ', base64Qrimg);
      console.log('urlCode (data-ref): ', urlCode);
    },
    statusFind: (statusSession, session) => {
      console.log('Status Session: ', statusSession);
      console.log('Session name: ', session);
    },
    statusFind: (statusSession, session) => {
      console.log('Status Session: ', statusSession);
      console.log('Session name: ', session);
    }
  })
  .then((client) => start(client))
  .catch((error) => console.log(error));

Adding this to the client creation config resolves it:

    session: 'sessionName', //Pass the name of the client you want to start the bot
gekkedev commented 5 months ago

I can confirm this works now 👍 quebom