@grammy-x/conversations 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grammy-x/conversations",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "type": "module",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
@@ -2,15 +2,14 @@ import type { ConversationConfig } from "@grammyjs/conversations"
2
2
  import { createConversation } from "@grammyjs/conversations"
3
3
  import type { Conversation } from "@grammyjs/conversations"
4
4
  import { hydrate } from "@grammyjs/hydrate"
5
- import type { MiddlewareFn } from "grammy"
6
- import type { GrammyXFlavor } from "@grammy-x/core"
5
+ import type { Context, MiddlewareFn } from "grammy"
7
6
 
8
- export type ConversationFn<C extends GrammyXFlavor = GrammyXFlavor> = (
7
+ export type ConversationFn<C extends Context = Context> = (
9
8
  conversation: Conversation<C>,
10
9
  ctx: C
11
10
  ) => unknown | Promise<unknown>
12
11
 
13
- export function createCustomConversation<C extends GrammyXFlavor = GrammyXFlavor>(
12
+ export function createCustomConversation<C extends Context = Context>(
14
13
  builder: ConversationFn<C>,
15
14
  config?: string | ConversationConfig
16
15
  ): MiddlewareFn<any> {
@@ -2,7 +2,6 @@ import type { Conversation } from "@grammyjs/conversations"
2
2
  import { CallbackQueryContext, Context, InlineKeyboard, Keyboard } from "grammy"
3
3
  import type { ChatAdministratorRights, ChatShared } from "grammy/types"
4
4
  import { smartReply } from "@grammy-x/core"
5
- import type { GrammyXFlavor } from "@grammy-x/core"
6
5
 
7
6
  type MaybePromise<T> = PromiseLike<T> | T
8
7
  type ButtonsMarkup = InlineKeyboard | Keyboard
@@ -67,7 +66,7 @@ function randomInteger(minimum: number, maximum: number): number {
67
66
  }
68
67
 
69
68
  export class QuestionHelper<
70
- C extends GrammyXFlavor = GrammyXFlavor,
69
+ C extends Context = Context,
71
70
  T extends Conversation<C> = Conversation<C>,
72
71
  > {
73
72
  private conversation: T
@@ -81,7 +80,7 @@ export class QuestionHelper<
81
80
  this.ctx = ctx
82
81
  }
83
82
 
84
- private updateCtx = <U extends GrammyXFlavor>(ctx: U) => {
83
+ private updateCtx = <U extends Context>(ctx: U) => {
85
84
  Object.keys(this.ctx).forEach((key) => delete (this.ctx as any)[key])
86
85
  Object.assign(this.ctx, ctx)
87
86
  }
@@ -271,7 +270,7 @@ export class QuestionHelper<
271
270
  > {
272
271
  const markup = new InlineKeyboard()
273
272
  const session = (await this.conversation.external(
274
- () => this.ctx.session
273
+ () => (this.ctx as any).session
275
274
  )) as unknown as QuestionHelperSession
276
275
  if (!session.questionHelper) this.resetChoice(session)
277
276
  await this.conversation.external(() => !inProgress && this.resetChoice(session))
@@ -365,7 +364,7 @@ export class QuestionHelper<
365
364
 
366
365
  if (callbackData == "continue" || additionalTriggerCalled) {
367
366
  const choices = Array.from(session.questionHelper.currentChoices)
368
- ;(this.ctx.session as unknown as QuestionHelperSession).questionHelper.currentChoices = new Set()
367
+ ;((this.ctx as any).session as unknown as QuestionHelperSession).questionHelper.currentChoices = new Set()
369
368
  if (additionalTriggerCalled) return { result: choices as R[], callbackQuery: callbackData, message }
370
369
  return { result: choices as R[], message }
371
370
  }
@@ -383,7 +382,7 @@ export class QuestionHelper<
383
382
  if (questionData.currentChoices!.has(data)) questionData.currentChoices!.delete(data)
384
383
  else questionData.currentChoices!.add(data)
385
384
  }
386
- ;(this.ctx.session as unknown as QuestionHelperSession).questionHelper = session.questionHelper =
385
+ ;((this.ctx as any).session as unknown as QuestionHelperSession).questionHelper = session.questionHelper =
387
386
  questionData
388
387
  if (paginationsCallbacks.includes(callbackData) && questionData.currentPage == currentPage) {
389
388
  await this.ctx.answerCallbackQuery()
@@ -392,7 +391,7 @@ export class QuestionHelper<
392
391
  })
393
392
  if (skip) return this.conversation.skip({ drop: true })
394
393
  if (!multi && data) {
395
- ;(this.ctx.session as unknown as QuestionHelperSession).questionHelper.currentChoices = new Set()
394
+ ;((this.ctx as any).session as unknown as QuestionHelperSession).questionHelper.currentChoices = new Set()
396
395
  return {
397
396
  result: data as R,
398
397
  message,