-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
read/write values of another session #16
Comments
Hi @Iniro, Short answer: const session = new LocalSession({
database: 'example_db.json',
storage: LocalSession.storageFileSync
})
bot.use(session.middleware());
console.log(session.getSession('170062604:170062604')); Detailed answer: telegraf-session-local/lib/session.js Lines 1 to 6 in 14c0a9f
telegraf-session-local/lib/session.js Lines 24 to 27 in 14c0a9f
And there's a little bug - we cannot use sessions database before it actually initialized. Meanwhile I'm working on telegraf-session-local , you can simply set storage type to be synchronous, like:
const session = new LocalSession({
database: 'example_db.json',
storage: LocalSession.storageFileSync
}) It's not so easy to keep code backward compatible, but I will try to introduce in v0.0.6 something new on how to deal with asynchronous adapters. |
Thank you, your response was extremely helpful. |
* Improved detection of empty session data * ✅ Improved tests (better coverage) * ✅ Added new tests (better coverage) * Tests for `format.serialize` and `format.deserialize` functions of lowdb storage * Test for `isPromise()` function * Exporting `isPromise()` function now * 🔧 Ignoring file `sessions.json`, which comes after running tests * ⬆️ Upgrading dependencies * Added .npmrc (disable package-lock.json) * 📝 Improve documentation & JSDoc config [ci skip] * 💥 Default storage type: storageFileAsync -> storageFileSync, see #16 * 👌 Possible fix for #16 and #13 * 🔧 Move ESLint config from package.json to .eslintrc [ci skip] * Fixing tests (TravisCI failing builds for Node 6)
@Iniro now you can access database (and sessions in it) in two ways:
const session = new LocalSession()
bot.use(session.middleware())
console.log(session.getSession('170062604:170062604'))
const session = new LocalSession({
storage: LocalSession.storageFileAsync,
})
bot.use(session.middleware())
session.DB.then((db) => {
console.log(db.get('sessions').getById('170062604:170062604').value())
}) |
Hi, I'm learning about this library. Could I be able to access values from other sessions?
I'm trying like this,
const session = (new LocalSession({ database: 'example_db.json' }));
bot.use(session.middleware());
console.log(session.getSession('170062604:170062604'));
//<-- This like gives me the error belowTypeError: Cannot read property '_' of undefined
The text was updated successfully, but these errors were encountered: