billbarsch / myzap

Free Open Source Whatsapp Api
837 stars 337 forks source link

Cannot read property 'onStateChange' of undefined #97

Closed FernandoGambaro closed 3 years ago

FernandoGambaro commented 3 years ago

Hola, estoy probando vuestra api para utilizar Whatsapp y me da el error al intentar iniciar sesión.

Para poder utilizar la api he realizado algunos cambios en sessions.js ////////////////////////////////////////////////////////////////////////////////////////////////////// import os from 'os'; import fs from 'fs'; import path from 'path'; import venom from 'venom-bot'; import wppconnect from '@wppconnect-team/wppconnect'; import axios from 'axios'; ////////////////////////////////////////////////////////////////////////////////////////////////////// Las dependencias instalaras son: "dependencies": { "@wppconnect-team/wppconnect": "^1.8.13", "axios": "^0.21.4", "cors": "^2.8.5", "dotenv": "^10.0.0", "ejs": "^3.1.6", "express": "^4.17.1", "express-session": "^1.17.2", "https": "^1.0.0", "mime": "^2.5.2", "sessions": "^0.0.2-7", "venom-bot": "https://github.com/orkestral/venom/releases/download/nightly/venom-bot-nightly.tgz" }

El error es:

UnhandledRejection: Cannot read property 'onStateChange' of undefined at sessions.js:210:20 at processTicksAndRejections (node:internal/process/task_queues:94:5) at async Function.setup (sessions.js:209:9)


Las líneas de código donde refieren el error son:

static async setup(sessionName) {
    var session = Sessions.getSession(sessionName);

(209) await session.client.then(client => { (210) client.onStateChange(state => { session.state = state; if (state == "CONNECTED") { .....

No logro encontrar el porque del error.

Si pudieran orientarme. Muchas gracias

FernandoGambaro commented 3 years ago

Finalmente, encontré la falla, process.env.ENGINE no estaba definido