Closed LuisArteModelo closed 1 year ago
+1
any update ?
I'm create a function ahead inside a "src\api\class\session.js" file, create a route in "src\api\routes\instance.route.js"
async restoreSessionByKey(key) { let restoredSessions = new Array() try { const db = mongoClient.db('whatsapp-api') const query = {} db.collection(key) .find(query) .toArray(async (err, result) => { if (err) throw err const webhook = !config.webhookEnabled ? undefined : config.webhookEnabled const webhookUrl = !config.webhookUrl ? undefined : config.webhookUrl const instance = new WhatsAppInstance( key, webhook, webhookUrl ) await instance.init() WhatsAppInstances[key] = instance }) restoredSessions.push(key) } catch (e) { logger.error('Error restoring session') logger.error(e) } return restoredSessions }
it is working from your side ?
Yes
async restoreSessionByKey(key) {
let restoredSessions = new Array()
try {
const db = mongoClient.db('whatsapp-api')
const query = {}
db.collection(key).find(query).toArray(async (err, result) => {
if (err) throw err
const webhook = !config.webhookEnabled ? undefined : config.webhookEnabled
const webhookUrl = !config.webhookUrl ? undefined : config.webhookUrl
const instance = new WhatsAppInstance(key, webhook, webhookUrl)
await instance.init()
WhatsAppInstances[key] = instance
})
restoredSessions.push(key)
}
catch (e) {
logger.error('Error restoring session')
logger.error(e)
}
return restoredSessions
}
Error: Route.get() requires a callback function but got a [object Undefined]
at Route.
router.route('/restoreSessionByKey').get(controller.restoreSessionByKey)
may be on typescript version this feature will be done to
How can restore only one instance?