import { Context as BaseContext } from 'grammy' ; import { suffixHTML , suffixMarkdown , suffixMarkdownV2 , isContextReplyToMessage , isReplyToQuestion , ReplyToMessageContext , getAdditionalState } from './identifier' ; type ConstOrPromise < T > = T | Promise < T > ; export class StatelessQuestion < Context extends BaseContext > { constructor ( public readonly uniqueIdentifier , private readonly answer ) { } middleware ( ) { return async ( context , next ) => { if ( isContextReplyToMessage ( context ) && isReplyToQuestion ( context , this . uniqueIdentifier ) ) { const additionalState = getAdditionalState ( context , this . uniqueIdentifier ) ; return this . answer ( context , additionalState ) ; } await next ( ) ; } ; } messageSuffixHTML ( additionalState ? ) { return suffixHTML ( this . uniqueIdentifier , additionalState ) ; } messageSuffixMarkdown ( additionalState ? ) { return suffixMarkdown ( this . uniqueIdentifier , additionalState ) ; } messageSuffixMarkdownV2 ( additionalState ? ) { return suffixMarkdownV2 ( this . uniqueIdentifier , additionalState ) ; } async replyWithHTML ( context , text , additionalState ? ) { const textResult = text + this . messageSuffixHTML ( additionalState ) ; return context . reply ( textResult , { reply_markup : { force_reply : true } , parse_mode : 'HTML' } ) ; } async replyWithMarkdown ( context , text , additionalState ? ) { const textResult = text + this . messageSuffixMarkdown ( additionalState ) ; return context . reply ( textResult , { reply_markup : { force_reply : true } , parse_mode : 'Markdown' } ) ; } async replyWithMarkdownV2 ( context , text , additionalState ? ) { const textResult = text + this . messageSuffixMarkdownV2 ( additionalState ) ; return context . reply ( textResult , { reply_markup : { force_reply : true } , parse_mode : 'MarkdownV2' } ) ; } }