Giter VIP home page Giter VIP logo

telegraf-session-local's People

Contributors

dependabot-preview[bot] avatar edjopato avatar greenkeeper[bot] avatar lgtm-com[bot] avatar temasm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

telegraf-session-local's Issues

can't find module telegraf-session

C:\Users\ASUS\ocr-bot>node main.js
internal/modules/cjs/loader.js:438
throw e;
^

Error: Cannot find module 'C:\Users\ASUS\ocr-bot\node_modules\telegraf\session'
at createEsmNotFoundErr (internal/modules/cjs/loader.js:907:15)
at finalizeEsmResolution (internal/modules/cjs/loader.js:900:15)
at resolveExports (internal/modules/cjs/loader.js:432:14)
at Function.Module._findPath (internal/modules/cjs/loader.js:472:31)
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:867:27)
at Function.Module._load (internal/modules/cjs/loader.js:725:27)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object. (C:\Users\ASUS\ocr-bot\main.js:2:17)
at Module._compile (internal/modules/cjs/loader.js:1063:30) {
code: 'MODULE_NOT_FOUND',
path: 'C:\Users\ASUS\ocr-bot\node_modules\telegraf\package.json'
}

An in-range update of eslint is breaking the build 🚨

Version 5.0.1 of eslint was just published.

Branch Build failing 🚨
Dependency [eslint](https://github.com/eslint/eslint)
Current Version 5.0.0
Type devDependency

This version is covered by your current version range and after updating it in your project the build failed.

eslint is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • ❌ continuous-integration/travis-ci/push The Travis CI build failed Details
  • βœ… coverage/coveralls First build on greenkeeper/eslint-5.0.1 at 98.376% Details

Release Notes v5.0.1
  • 196c102 Fix: valid-jsdoc should allow optional returns for async (fixes #10386) (#10480) (Mark Banner)
  • 4c823bd Docs: Fix max-lines-per-function correct code's max value (#10513) (Rhys Bower)
Commits

The new version differs by 4 commits.

  • caeb223 5.0.1
  • 125dc34 Build: changelog update for 5.0.1
  • 196c102 Fix: valid-jsdoc should allow optional returns for async (fixes #10386) (#10480)
  • 4c823bd Docs: Fix max-lines-per-function correct code's max value (#10513)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

read/write values of another session

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 below
TypeError: Cannot read property '_' of undefined

Not all data is saved in a local file

Hi. I have this problem: I have 2 scene.enter handlers, in both I save the bot message, but one handler saves the message and the other doesn't.

scene.enter(async (ctx) => {
    const msg = await ctx.reply("login");
    ctx.scene.state.editMsg = { chatId: msg.chat.id, messageId: msg.message_id };
  });

This code works well and the message is saved

scene.enter(async (ctx) => {
    const msg = await ctx.replyWithPhoto(
      { source: `${process.env.rootDir}/assets/img/settings.png` },
      Extra.load({ caption: "Settings" })
        .markdown()
        .markup((m) =>
          m.inlineKeyboard([
            [m.callbackButton("Profile", "profile"), m.callbackButton("Social", "social")],
            [m.callbackButton("Wallet", "wallet"), m.callbackButton("Back", "back")],
          ])
        )
    );

    ctx.scene.state.delMsg = { chatId: msg.chat.id, messageId: msg.message_id };
  });

But this code doesn't save the message.
What could be the problem?

node: v12.16.1
npm: v6.13.4

Typo in the full example

Hello,

Thank you for sharing this project, it really helps me out.

I think there is a small typo in the documentation and examples regarding the full example.
When you have used the property 'data', it seems that it has been forgotten to be updated on extra.jsfile, on the following lines:
13. property: 'session', rather using only property,
38. ctx.session.counter, rather ctx[property].counter.

Thank you again.
Taoufik

Property 'session' does not exist on type 'TelegrafContext'

Hi, I'm new to typescript and I'm working on a Telegraf bot using this library.

I have the following code

import { Telegraf } from 'telegraf'
import LocalSession from 'telegraf-session-local'
import config from './config'

const bot = new Telegraf(config.botToken)
const session = new LocalSession({ database: 'db.json' })

bot.use(session.middleware())

bot.on('text', (ctx, next) => {
  ctx.session.counter = ctx.session.counter || 0
  // eslint-disable-next-line no-plusplus
  ctx.session.counter++
  ctx.replyWithMarkdown(
    `Counter updated, new value: \`${ctx.session.counter}\``,
  )
  return next()
})

bot.launch().then(() => {
  // eslint-disable-next-line no-console
  console.log('Bot started successfully')
})

which shows a typescript error Property 'session' does not exist on type 'TelegrafContext'

How can I let typescript now that session is added by the library and give it the correct type?

Session doesn't updated in 2nd middleware in row

Here is the code example

bot.command('/foo', (ctx, next) => {
    console.log('foo');
    //ctx.session.myvar = 'val1';// will update session if uncomment
    next();
});
bot.command(['/foo', '/bar'], (ctx, next) => {
    console.log('foo & bar');
    ctx.session.myvar = 'var2'; // will not update session if user send /foo, but will do update session if user send /bar
    next();
});

If user send command /foo than both middlewares calls as expected, but session myvar variable updates from 2nd middleware never persist on disk.
But when user send /bar then only 2nd middleware calls and myvar save val2 value in session.

Cannot find module './lodash-id.js

Error: Cannot find module './lodash-id.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:668:15)
    at Function.Module._load (internal/modules/cjs/loader.js:591:27)
    at Module.require (internal/modules/cjs/loader.js:723:19)
    at require (internal/modules/cjs/helpers.js:14:16)
    at LocalSession._initDB (/home/amao/Git/R6statsTGbot/node_modules/telegraf-session-local/lib/session.js:274:19)
    at new LocalSession (/home/amao/Git/R6statsTGbot/node_modules/telegraf-session-local/lib/session.js:84:15)
    at Object.<anonymous> (/home/amao/Git/R6statsTGbot/index.js:19:10)
    at Module._compile (internal/modules/cjs/loader.js:816:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:827:10)
    at Module.load (internal/modules/cjs/loader.js:685:32)

The break line in my file is

bot.use((new LocalSession({ database: 'example_db.json' })).middleware())

I installed the lodash-id by npm but not solve the problem

Arch Linux + zsh
Webstorm

Save a session on bot start?

Hello,

I want to save user's information as he/she starts using my bot but I figured out setting sessions on bot.start() doesn't work or at least I'm doing something wrong. Manipulating sessions on other event handlers (.hears(), on('audio'), etc.) works well though.
Here's the code:

Screenshot from 2019-08-16 15-33-26

Where did I go wrong? Is this a Telegram bot API limitation?

Session with AWS Lambdas does not persist state when it is set after an async operation.

Hi there.

In my project, I use a bunch of middlewares as a steps to collect data from different sources and found some strange behaviour. The user sends some links to the BOT and I save it to the session, then I invoke the next function. The next middleware is the async function and I request a page from the provided link. So, I also save some data from that page in the session.

If I will chain another middleware after this, I will be able to get this data, but if the user will send another message this data will be lost, but the previous link anyway still stay.

I guess this is because the link is set in a synchronous manner but data from the link is asynchronous.

Session not cleared after async task

Working code

  const logout = async (ctx) => {
    try {
      ctx.session = null;
    } catch (error) {}
  };

Not working code

  const logout = async (ctx) => {
  try {
    await new Promise((resolve) => setTimeout(resolve, 1000));
    ctx.session = null;
  } catch (error) {}
};

issue with nodemon

Nodemon works perfectly but when I include const LocalSession = require('telegraf-session-local') it keeps failing to restart like: [nodemon] restarting due to changes... [nodemon] starting 'node index.js' again and again.

I'm using nodemon 2.0.15 and the latest telegraf-session-local version

created session value is missing on the "poll_answer" ctx

Hey πŸ™‹πŸΌβ€β™‚οΈ,

I faced such issue: I can't get the session object on the poll_answer ctx which is triggered after selecting an option in the quiz.

  // command for sending quiz
  bot.command('quiz', async (ctx) => {
    // βœ… create session object with counter
    ctx.session = { counter: 0 };

    ctx.telegram.sendQuiz(args);
    return ctx;
  });

  bot.on('poll_answer', async (ctx) => {
    console.log(ctx.session); // ⛔️ undefined, unable to increment counter
    return ctx;
  });

Read/Write

Hi, thanks for your work !

I have a problem with the local file in Debian, nothing is written inside except {"sessions" : []}
I don't get it because I work in my telegram bot on Windows 10 and everything work great ! But when I push my code to my Debian server, it doesn't work.

The rights (permission) file was (rw-r--r--). I decided to change it :

I try to set default permission to parent folder : thanks to this link. I have all rights (rw-rw-rw) but I have still the same issue.

Any idea ? Thanks !

(sorry for my english)

Error with Session version 1.0.3 with telegraf-js v 3.38

I just updated to 1.0.3 because of the Promise fix.
However, when I now try to init my LocalSession I am getting an error:

Node: 12.16.3
TS: 3.9.3

import LocalSession from 'telegraf-session-local';
const localSession = new LocalSession({
    database: 'example_db.json',
    property: 'session'
});
Exception has occurred: TypeError
TypeError: telegraf_session_local_1.default is not a constructor
    at Object.<anonymous> (e:\workspace\project\src\telegram\telegram.service.ts:35:22)
    at Module._compile (internal/modules/cjs/loader.js:1133:30)
    at Module._compile (E:\workspace\project\node_modules\ts-node\src\index.ts:858:23)

session is not saved inside Promise.then

Hi.
Example:
getSources().then(src => {ctx.session.sources = src});
just modifies the session and doesn't save it, while
ctx.session.sources = "test";
modifies and saves the session.

First example gets the session, modifies it - we can check it there by console.log for example. But it doesn't affect the database file.
The same issue using async/await:
ctx.session.sources = await getSources()
and all the code above modifies session, but it isn't saved

Problem with types

Hey, just install package and got types error:


node_modules/telegraf-session-local/lib/session.d.ts:34:3 - error TS2309: An export assignment cannot be used in a module with other exported elements.

34   export = LocalSession
     ~~~~~~~~~~~~~~~~~~~~~

Seems it because also interface exported. I think change export = LocalSession to export default LocalSession can fix this.
Now I can't really use this package.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.