Skip to content

feat: expose conversation handle to plugins#134

Merged
KnorpelSenf merged 8 commits intomainfrom
session-inside-plugins
Apr 17, 2025
Merged

feat: expose conversation handle to plugins#134
KnorpelSenf merged 8 commits intomainfrom
session-inside-plugins

Conversation

@KnorpelSenf
Copy link
Member

The plugins option allows plugins to be installed inside a conversation, and external allows the conversation to read the session data. It was pointed out in https://t.me/grammyjs/291998 that it is currently impossible to access the session data from inside a plugin.

This PQ introduces a plugins option that has access to the conversation handle. That way, the following code becomes possible.

bot.use(createConversation(convo, {
  plugins: conversation => [async (ctx, next) => {
    // can now install session data on the context:
    ctx.sess = await conversation.external(ctx => ctx.session)
  }]
}))

@KnorpelSenf KnorpelSenf requested a review from KnightNiwrem March 2, 2025 13:09
Copy link

@OfficialCodinary OfficialCodinary left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested in production, No bugs in a long run.

@KnorpelSenf KnorpelSenf merged commit 66c353e into main Apr 17, 2025
6 checks passed
@KnorpelSenf KnorpelSenf deleted the session-inside-plugins branch April 17, 2025 11:05
KnorpelSenf added a commit to grammyjs/grammY that referenced this pull request Apr 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants