Code Monkey home page Code Monkey logo

storages's People

Contributors

arthurgubaidullin avatar daniharo avatar edjopato avatar github-actions[bot] avatar knorpelsenf avatar leonekmi avatar mobinaskari avatar ponomarevlad avatar renovate-bot avatar renovate[bot] avatar rnbsov avatar roj1512 avatar roziscoding avatar satont avatar shevernitskiy avatar simple7575 avatar thecoorum avatar ubertao avatar waptik avatar web-flow avatar yosle 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

Watchers

 avatar  avatar  avatar  avatar  avatar

storages's Issues

Requirement to use Cloudflare Adapter

Do I need to host my bot on Cloudflare to use Cloudflare adapter? Also, I saw that the example contain R2_BUCKET setting, can I use this instead of KV?

INVALID_ARGUMENT

After I managed to install this plugin, my bot completely stop working the way it ws before. Crash after crash. I`m not sure if I should not use it or can it be fixed is some way?

Error: 3 INVALID_ARGUMENT: Cannot convert an array value in an array value. at callErrorFromStatus

DEFAULT 2023-03-02T12:46:16.591903Z [resource.labels.functionName: valimisedBot] [labels.executionId: 1u84fc1geo2s] at /workspace/node_modules/@google-cloud/firestore/build/src/v1/firestore_client.js:225:29

Caused by: Error
DEFAULT 2023-03-02T12:46:16.591951Z [resource.labels.functionName: valimisedBot] [labels.executionId: 1u84fc1geo2s] at WriteBatch.commit (/workspace/node_modules/@google-cloud/firestore/build/src/write-batch.js:433:23)
DEFAULT 2023-03-02T12:46:16.591956Z [resource.labels.functionName: valimisedBot] [labels.executionId: 1u84fc1geo2s] at DocumentReference.set (/workspace/node_modules/@google-cloud/firestore/build/src/reference.js:392:27)
DEFAULT 2023-03-02T12:46:16.591961Z [resource.labels.functionName: valimisedBot] [labels.executionId: 1u84fc1geo2s] at Object.write (/workspace/node_modules/@grammyjs/storage-firestore/dist/cjs/index.js:11:39)
DEFAULT 2023-03-02T12:46:16.591968Z [resource.labels.functionName: valimisedBot] [labels.executionId: 1u84fc1geo2s] at PropertySession.finish (/workspace/node_modules/grammy/out/convenience/session.js:232:40)

DEBUG 2023-03-02T12:46:16.598473367Z [resource.labels.functionName: valimisedBot] [labels.executionId: 1u84fc1geo2s] Function execution took 1877 ms, finished with status: 'crash'

Use workspace file for each adapter.

With this approach, we will be able to control the deno settings more precisely. This way we can exclude nodejs files from the deno language server.

Problems with installing

Failed to load function definition from source: Failed to generate manifest from function source: Error: Cannot find module '/Users/xxx/vue/vite-project/node_modules/@grammyjs/storage-firestore/dist/cjs/mod.js'

Add server status badge to free-storage README

The freeStorage seems to be down, giving a 503 error: 503 in free session service, retrying!.

It would be good for users to know if the server is down. An easy way to do this, depending on the deployment, would be adding a server status badge to the README file.

(redis, question | docs) How to work with external storage to initialize the initial data of the user's session?

It is not very clear how to work with data from external storage to initialize the initial data of the user's session.

For example, when working with Redis adapter and lazySession:

import { Bot, Context, LazySessionFlavor, Enhance, lazySession, enhanceStorage } from 'grammy'
import { RedisAdapter } from '@grammyjs/storage-redis'
import { Redis } from 'ioredis'

// ...

interface IUserSessionData {
  counter: number
}

type TUserContext = Context & LazySessionFlavor<IUserSessionData>

const bot = new Bot<TUserContext>(process.env.TELEGRAM_BOT_TOKEN)

const redis = new Redis({
  host: process.env.REDIS_HOST,
  password: process.env.REDIS_PASSWORD,
  username: process.env.REDIS_USERNAME ? process.env.REDIS_USERNAME : 'default',
  port: process.env.REDIS_PORT ? Number(process.env.REDIS_PORT) : 6379,
  lazyConnect: true,
})

const enhanced = new RedisAdapter<Enhance<IUserSessionData>>({ instance: redis })

const storage = enhanceStorage({
  storage: enhanced,
  millisecondsToLive: 30 * 60 * 1000,
})

bot.use(
  lazySession({
    initial: () => ({ /* ??? */ }),
    getSessionKey: (ctx: Omit<TUserContext, 'session'>) => ctx.from?.id.toString(),
    storage,
  }),
)

// ...

What do I need to do so that when creating middleware with session settings, I can pick up the current data? Now, every time the bot is rebooted, the session is reset to those specified in initial block in lazySession.

Since the session key in Redis is equal to the user ID in Telegram (according to the snippet above), in order to programmatically insert all data from Redis into the ctx.session, I need to make a separate function, which should be at the beginning of each bot.*(...), etc.?

How would I improve this?

It would be convenient if the session initialization method could retrieve data from the remote storage itself.
And if there is no data (or the storage is unavailable), then take the specified fallback values.

Or let the developer configure the function himself, which will take data from Redis and put it in the ctx.session of the current bot user:

bot.use(
  lazySession({
    initial: () => ({ counter: 0 }), // <-- fallback values here
    getInitialSessionData: (ctx) => myFunc(ctx), // <-- send context with current Telegram user ID to get Redis record by key
    getSessionKey: (ctx: Omit<TUserContext, 'session'>) => ctx.from?.id.toString(),
    storage,
  }),
)

I think, such an improvement would be useful for everyone (especially for beginners) and would make the bot code much easier.

Firestore adapter cannot write conversation sessions

Problem

Firestore cannot store conversations session data with current adapter.

Cause

Firestore cannot encode the function definitions of the stored update objects under log e.g. copy, forward.

While the Admin SDK throws the error Error: Cannot encode value: (chat_id, other, signal), which wasn't too informative, testing with the Web SDK produced a more useful error Function setDoc() called with invalid data. Unsupported field value: a function.

Solution (?)

Perhaps the Firestore adapter should JSON.stringify / parse when writing to and reading from the database, at least for conversation sessions? It's slightly inelegant but can get the job done.

I could well be missing something very obvious, so would appreciate somebody suggesting a better approach. Thanks!

Supabase adapter not working in deno (dependency import brocken/deprecated)

Using this import, like pointed out in the docs (https://grammy.dev/plugins/session#external-storage-solutions)

import { supabaseAdapter } from 'https://deno.land/x/grammy_storages/supabase/src/mod.ts';

throws this error, when trying to execute.

Warning Implicitly using latest version (v2.24.0) for https://deno.land/x/supabase/mod.ts
error: Module not found "https://deno.land/x/supabase/mod.ts".
    at https://deno.land/x/[email protected]/supabase/src/deps.deno.ts:1:32

I suspect the supabase module import beeing deprecated, since it originates from an empty repo. I guess using https://esm.sh/@supabase/supabase-js@2 could do the trick.

Add TTL

It's possible to add TTL check on read operations for all adapters.

Remove creating of table for PostgreSQL adapter

I thought about it, and came to the conclusion that this should be taken care of by the user himself. I see a leak of abstraction here. The adapter is not doing just one thing that it should be doing.

Firebase not supported conversations

Error in middleware: 3 INVALID_ARGUMENT: Cannot convert an array value in an array value.
    Error: 3 INVALID_ARGUMENT: Cannot convert an array value in an array value.
        at callErrorFromStatus (D:\Projects\code-now-bot\node_modules\@grpc\grpc-js\src\call.ts:81:17)
        at Object.onReceiveStatus (D:\Projects\code-now-bot\node_modules\@grpc\grpc-js\src\client.ts:356:55)
        at Object.onReceiveStatus (D:\Projects\code-now-bot\node_modules\@grpc\grpc-js\src\client-interceptors.ts:454:34)
        at Object.onReceiveStatus (D:\Projects\code-now-bot\node_modules\@grpc\grpc-js\src\client-interceptors.ts:416:48)
        at D:\Projects\code-now-bot\node_modules\@grpc\grpc-js\src\resolving-call.ts:111:24
        at processTicksAndRejections (node:internal/process/task_queues:77:11)
export async function checkoutOrder(
  conversation: MyConversation,
  ctx: CodeNowBotContext,
) {
  await ctx.reply(getTextByContext("questions.details.message", ctx));
  const orderDetails = await conversation.form.text();
  botLogger.debug(orderDetails);
  return;
}

I got this when try to use conversations with firebase storage adapter

[MongoDB] Adapter should ignore unefined fields

When writing a session, specially when using conversations, we don't really want to write undefined values as null to the database, because conversations expects some properties to be undefined, and when they're null, they break.

Reference: https://t.me/grammyjs/73326

If it makes sense, we could pass ignoreUndefined: true to the updateOne method, which would solve this problem.

Although, I don't know if it really makes sense, since we'll be changing the behavior of the adapter for inumerous cases exclusevely because of the conversations case, so maybe we should give the user an option to turn this on when installing the adapter, which would make them aware of this behavior, and could be enabled only when the user actually needs it to behave this way. What do you think?

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Warning

These dependencies are deprecated:

Datasource Name Replacement PR?
npm @types/ioredis Unavailable

Warning

Renovate failed to look up the following dependencies: Failed to look up npm package @grammyjs/storage-utils.

Files affected: packages/file/package.json, packages/mongodb/package.json, packages/prisma/package.json, packages/psql/package.json, packages/redis/package.json, packages/typeorm/package.json


Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Ignored or Blocked

These are blocked by an existing closed PR and will not be recreated unless you click a checkbox below.

Detected dependencies

docker-compose
packages/psql/docker-compose.yml
  • postgres 15
github-actions
.github/workflows/deno_deps_update.yml
  • actions/checkout v3
  • denoland/setup-deno v1
  • peter-evans/create-pull-request v5
.github/workflows/pr_title_lint.yml
  • amannn/action-semantic-pull-request v5
.github/workflows/release_node.yml
  • actions/checkout v3
  • actions/setup-node v3
.github/workflows/tests.yml
  • actions/checkout v3
  • actions/setup-node v3
  • actions/checkout v3
  • maximousblk/setup-deno v2
  • actions/setup-node v3
npm
libs/utils/package.json
  • grammy ^1.21.1
package.json
  • @types/node ^20.11.22
  • @typescript-eslint/eslint-plugin ^7.1.0
  • @typescript-eslint/parser ^7.1.0
  • deno2node ^1.11.0
  • eslint ^8.57.0
  • husky ^9.0.11
  • lerna ^8.1.2
  • lint-staged ^15.2.2
  • prettier ^3.2.5
  • rimraf ^5.0.5
  • tsx ^4.7.1
  • typescript ^5.3.3
  • pnpm >=7.0.0
  • node >=12.0.0
packages/cloudflare/package.json
  • @cloudflare/workers-types ^4.20240222.0
  • grammy ^1.21.1
  • wrangler ^3.30.0
packages/denodb/package.json
packages/denokv/package.json
packages/deta/package.json
  • node-fetch ^2.6.6
  • @types/node-fetch ^2.6.11
  • grammy ^1.21.1
packages/file/package.json
  • @grammyjs/storage-utils ^2.4.2
  • grammy ^1.21.1
packages/firestore/package.json
  • @google-cloud/firestore ^6.6.0
packages/free/package.json
  • node-fetch ^2.6.6
  • @types/node-fetch ^2.6.11
packages/mongodb/package.json
  • @grammyjs/storage-utils ^2.4.2
  • grammy ^1.21.1
  • mongodb ^6.3.0
  • mongodb-memory-server ^9.1.6
packages/pocketbase/package.json
  • pocketbase ^0.21.1
  • grammy ^1.21.1
packages/prisma/package.json
  • @grammyjs/storage-utils ^2.4.2
  • @prisma/client ^5.10.2
  • grammy ^1.21.1
  • prisma ^5.10.2
  • vite ^5.1.4
  • vitest ^1.3.1
packages/psql/package.json
  • @grammyjs/storage-utils ^2.4.2
  • @types/pg ^8.11.2
  • grammy ^1.21.1
  • pg ^8.11.3
  • pg-mem ^2.8.1
packages/redis/package.json
  • @grammyjs/storage-utils ^2.4.2
  • @types/ioredis ^5.0.0
  • grammy ^1.21.1
  • ioredis ^5.3.2
packages/supabase/package.json
  • @supabase/supabase-js ^1.24.0
  • @supabase/supabase-js ^1.0.0 || ^2.0.0
packages/typeorm/package.json
  • @grammyjs/storage-utils ^2.4.2
  • better-sqlite3 ^9.4.3
  • grammy ^1.21.1
  • mongodb ^6.3.0
  • mongodb-memory-server ^9.1.6
  • typeorm ^0.3.20
  • vite ^5.1.4
  • vitest ^1.3.1

  • Check this box to trigger a request for Renovate to run again on this repository

file storage not work

package.json

"dependencies": {
    "@grammyjs/files": "^1.0.3",
    "@grammyjs/menu": "^1.0.4",
    "@grammyjs/router": "^1.1.1",
    "@satont/grammy-file-storage": "^1.2.0",
    "filesize": "^8.0.7",
    "grammy": "^1.7.1",
    "https-proxy-agent": "^5.0.0",
    "node-fetch": "^3.2.3",
    "node-json-db": "^1.5.0",
    "nodejs-file-downloader": "^4.9.3",
    "sequelize": "^6.18.0",
    "sqlite3": "^5.0.2"
  }

use example code, get error

TSError: ⨯ Unable to compile TypeScript:
test.ts:24:7 - error TS2322: Type '() => { counter: number; }' is not assignable to type '() => undefined'.

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.