grammy-inline-menu
Advanced tools
Comparing version 7.0.2 to 8.0.0
@@ -1,2 +0,2 @@ | ||
import { ContextPathFunc, RegExpLike, ConstOrPromise } from './generic-types'; | ||
import { ContextPathFunc, RegExpLike, ConstOrPromise } from './generic-types.js'; | ||
export declare type ActionFunc<Context> = (context: Context, path: string) => ConstOrPromise<string | boolean>; | ||
@@ -3,0 +3,0 @@ export interface ButtonAction<Context> { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ActionHive = void 0; | ||
const path_1 = require("./path"); | ||
const path_js_1 = require("./path.js"); | ||
class ActionHive { | ||
@@ -15,3 +15,3 @@ constructor() { | ||
add(trigger, doFunction, hide) { | ||
(0, path_1.ensureTriggerChild)(trigger); | ||
(0, path_js_1.ensureTriggerChild)(trigger); | ||
const alreadyExisting = [...this._actions] | ||
@@ -25,4 +25,4 @@ .map(o => o.trigger.source) | ||
trigger, | ||
doFunction: async (context, path) => { | ||
if (await (hide === null || hide === void 0 ? void 0 : hide(context, path))) { | ||
async doFunction(context, path) { | ||
if (await hide?.(context, path)) { | ||
return '.'; | ||
@@ -38,3 +38,3 @@ } | ||
result.add({ | ||
trigger: (0, path_1.combineTrigger)(path, trigger), | ||
trigger: (0, path_js_1.combineTrigger)(path, trigger), | ||
doFunction, | ||
@@ -41,0 +41,0 @@ }); |
import { InputFile } from 'grammy'; | ||
import { LabeledPrice, Location, ParseMode, Venue } from '@grammyjs/types'; | ||
import { ReadonlyDeep } from 'type-fest'; | ||
export declare type Body = string | TextBody | MediaBody | LocationBody | VenueBody | InvoiceBody; | ||
@@ -22,3 +23,3 @@ export declare type MediaType = 'animation' | 'audio' | 'document' | 'photo' | 'video'; | ||
export interface VenueBody { | ||
readonly venue: Readonly<Venue>; | ||
readonly venue: ReadonlyDeep<Venue>; | ||
} | ||
@@ -32,3 +33,3 @@ export interface InvoiceBody { | ||
readonly currency: string; | ||
readonly prices: readonly LabeledPrice[]; | ||
readonly prices: ReadonlyArray<Readonly<LabeledPrice>>; | ||
}; | ||
@@ -35,0 +36,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getBodyText = exports.isInvoiceBody = exports.isVenueBody = exports.isLocationBody = exports.isMediaBody = exports.isTextBody = exports.MEDIA_TYPES = void 0; | ||
const generic_types_1 = require("./generic-types"); | ||
const generic_types_js_1 = require("./generic-types.js"); | ||
exports.MEDIA_TYPES = ['animation', 'audio', 'document', 'photo', 'video']; | ||
@@ -19,3 +19,3 @@ function isKnownMediaType(type) { | ||
} | ||
if (!(0, generic_types_1.isObject)(body)) { | ||
if (!(0, generic_types_js_1.isObject)(body)) { | ||
return false; | ||
@@ -35,7 +35,7 @@ } | ||
} | ||
return (0, generic_types_1.hasTruthyKey)(body, 'text'); | ||
return (0, generic_types_js_1.hasTruthyKey)(body, 'text'); | ||
} | ||
exports.isTextBody = isTextBody; | ||
function isMediaBody(body) { | ||
if (!(0, generic_types_1.isObject)(body)) { | ||
if (!(0, generic_types_js_1.isObject)(body)) { | ||
return false; | ||
@@ -46,3 +46,3 @@ } | ||
} | ||
return (0, generic_types_1.hasTruthyKey)(body, 'media'); | ||
return (0, generic_types_js_1.hasTruthyKey)(body, 'media'); | ||
} | ||
@@ -54,7 +54,7 @@ exports.isMediaBody = isMediaBody; | ||
function isLocationBody(body) { | ||
if (!(0, generic_types_1.hasTruthyKey)(body, 'location')) { | ||
if (!(0, generic_types_js_1.hasTruthyKey)(body, 'location')) { | ||
return false; | ||
} | ||
// Locations can't have text | ||
if ((0, generic_types_1.hasTruthyKey)(body, 'text')) { | ||
if ((0, generic_types_js_1.hasTruthyKey)(body, 'text')) { | ||
return false; | ||
@@ -67,7 +67,7 @@ } | ||
function isVenueBody(body) { | ||
if (!(0, generic_types_1.hasTruthyKey)(body, 'venue')) { | ||
if (!(0, generic_types_js_1.hasTruthyKey)(body, 'venue')) { | ||
return false; | ||
} | ||
// Locations can't have text | ||
if ((0, generic_types_1.hasTruthyKey)(body, 'text')) { | ||
if ((0, generic_types_js_1.hasTruthyKey)(body, 'text')) { | ||
return false; | ||
@@ -83,7 +83,7 @@ } | ||
function isInvoiceBody(body) { | ||
if (!(0, generic_types_1.hasTruthyKey)(body, 'invoice')) { | ||
if (!(0, generic_types_js_1.hasTruthyKey)(body, 'invoice')) { | ||
return false; | ||
} | ||
// Invoices can't have text | ||
if ((0, generic_types_1.hasTruthyKey)(body, 'text')) { | ||
if ((0, generic_types_js_1.hasTruthyKey)(body, 'text')) { | ||
return false; | ||
@@ -90,0 +90,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { ContextPathFunc } from '../generic-types'; | ||
import { ContextPathFunc } from '../generic-types.js'; | ||
export interface BasicOptions<Context> { | ||
@@ -3,0 +3,0 @@ /** |
@@ -1,3 +0,3 @@ | ||
import { ConstOrPromise } from '../generic-types'; | ||
import { ManyChoicesOptions } from '../choices'; | ||
import { ConstOrPromise } from '../generic-types.js'; | ||
import { ManyChoicesOptions } from '../choices/index.js'; | ||
export declare type ChooseActionFunc<Context> = (context: Context, key: string) => ConstOrPromise<string | boolean>; | ||
@@ -4,0 +4,0 @@ export interface ChooseOptions<Context> extends ManyChoicesOptions<Context> { |
@@ -1,3 +0,3 @@ | ||
import { ContextFunc, ConstOrPromise } from '../generic-types'; | ||
import { BasicOptions } from './basic'; | ||
import { ContextFunc, ConstOrPromise } from '../generic-types.js'; | ||
import { BasicOptions } from './basic.js'; | ||
export declare type SetPageFunction<Context> = (context: Context, page: number) => ConstOrPromise<void>; | ||
@@ -4,0 +4,0 @@ export declare type GetCurrentPageFunction<Context> = ContextFunc<Context, number | undefined>; |
@@ -1,4 +0,4 @@ | ||
import { CallbackButtonTemplate } from '../keyboard'; | ||
import { ConstOrPromise, ConstOrContextFunc } from '../generic-types'; | ||
import { ManyChoicesOptions, Choices } from '../choices'; | ||
import { CallbackButtonTemplate } from '../keyboard.js'; | ||
import { ConstOrPromise, ConstOrContextFunc } from '../generic-types.js'; | ||
import { ManyChoicesOptions, Choices } from '../choices/index.js'; | ||
export declare type IsSetFunction<Context> = (context: Context, key: string) => ConstOrPromise<boolean>; | ||
@@ -5,0 +5,0 @@ export declare type SetFunction<Context> = (context: Context, key: string, newState: boolean) => ConstOrPromise<string | boolean>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.generateSelectButtons = void 0; | ||
const understand_choices_1 = require("../choices/understand-choices"); | ||
const choices_1 = require("../choices"); | ||
const prefix_1 = require("../prefix"); | ||
const align_1 = require("./align"); | ||
const understand_choices_js_1 = require("../choices/understand-choices.js"); | ||
const index_js_1 = require("../choices/index.js"); | ||
const prefix_js_1 = require("../prefix.js"); | ||
const align_js_1 = require("./align.js"); | ||
function generateSelectButtons(actionPrefix, choices, options) { | ||
return async (context, path) => { | ||
var _a, _b, _c; | ||
if (await ((_a = options.hide) === null || _a === void 0 ? void 0 : _a.call(options, context, path))) { | ||
if (await options.hide?.(context, path)) { | ||
return []; | ||
} | ||
const choicesConstant = typeof choices === 'function' ? await choices(context) : choices; | ||
const choiceKeys = (0, understand_choices_1.getChoiceKeysFromChoices)(choicesConstant); | ||
(0, understand_choices_1.ensureCorrectChoiceKeys)(actionPrefix, path, choiceKeys); | ||
const textFunction = (0, choices_1.createChoiceTextFunction)(choicesConstant, options.buttonText); | ||
const formatFunction = (_b = options.formatState) !== null && _b !== void 0 ? _b : ((_, textResult, state) => (0, prefix_1.prefixEmoji)(textResult, state, { hideFalseEmoji: !options.showFalseEmoji })); | ||
const currentPage = await ((_c = options.getCurrentPage) === null || _c === void 0 ? void 0 : _c.call(options, context)); | ||
const keysOfPage = (0, align_1.getButtonsOfPage)(choiceKeys, options.columns, options.maxRows, currentPage); | ||
const choiceKeys = (0, understand_choices_js_1.getChoiceKeysFromChoices)(choicesConstant); | ||
(0, understand_choices_js_1.ensureCorrectChoiceKeys)(actionPrefix, path, choiceKeys); | ||
const textFunction = (0, index_js_1.createChoiceTextFunction)(choicesConstant, options.buttonText); | ||
const formatFunction = options.formatState ?? ((_, textResult, state) => (0, prefix_js_1.prefixEmoji)(textResult, state, { hideFalseEmoji: !options.showFalseEmoji })); | ||
const currentPage = await options.getCurrentPage?.(context); | ||
const keysOfPage = (0, align_js_1.getButtonsOfPage)(choiceKeys, options.columns, options.maxRows, currentPage); | ||
const buttonsOfPage = await Promise.all(keysOfPage | ||
@@ -30,5 +29,5 @@ .map(async (key) => { | ||
})); | ||
const rows = (0, align_1.getButtonsAsRows)(buttonsOfPage, options.columns); | ||
const rows = (0, align_js_1.getButtonsAsRows)(buttonsOfPage, options.columns); | ||
if (options.setPage) { | ||
rows.push((0, choices_1.generateChoicesPaginationButtons)(actionPrefix, choiceKeys.length, currentPage, options)); | ||
rows.push((0, index_js_1.generateChoicesPaginationButtons)(actionPrefix, choiceKeys.length, currentPage, options)); | ||
} | ||
@@ -35,0 +34,0 @@ return rows; |
@@ -1,3 +0,3 @@ | ||
import { ManyChoicesOptions } from '../choices'; | ||
import { SingleButtonOptions } from './basic'; | ||
import { ManyChoicesOptions } from '../choices/index.js'; | ||
import { SingleButtonOptions } from './basic.js'; | ||
export interface SubmenuOptions<Context> extends SingleButtonOptions<Context> { | ||
@@ -4,0 +4,0 @@ } |
@@ -1,4 +0,4 @@ | ||
import { CallbackButtonTemplate } from '../keyboard'; | ||
import { ContextPathFunc, ConstOrPromise, ConstOrContextPathFunc } from '../generic-types'; | ||
import { SingleButtonOptions } from './basic'; | ||
import { CallbackButtonTemplate } from '../keyboard.js'; | ||
import { ContextPathFunc, ConstOrPromise, ConstOrContextPathFunc } from '../generic-types.js'; | ||
import { SingleButtonOptions } from './basic.js'; | ||
export declare type FormatStateFunction<Context> = (context: Context, text: string, state: boolean, path: string) => ConstOrPromise<string>; | ||
@@ -5,0 +5,0 @@ export interface ToggleOptions<Context> extends SingleButtonOptions<Context> { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.generateToggleButton = void 0; | ||
const prefix_1 = require("../prefix"); | ||
const prefix_js_1 = require("../prefix.js"); | ||
function generateToggleButton(text, actionPrefix, options) { | ||
var _a; | ||
const formatFunction = (_a = options.formatState) !== null && _a !== void 0 ? _a : ((_, text, state) => (0, prefix_1.prefixEmoji)(text, state)); | ||
const formatFunction = options.formatState ?? ((_, text, state) => (0, prefix_js_1.prefixEmoji)(text, state)); | ||
return async (context, path) => { | ||
var _a; | ||
if (await ((_a = options.hide) === null || _a === void 0 ? void 0 : _a.call(options, context, path))) { | ||
if (await options.hide?.(context, path)) { | ||
return undefined; | ||
@@ -12,0 +10,0 @@ } |
@@ -1,3 +0,3 @@ | ||
import { ConstOrContextFunc, ContextPathFunc } from '../generic-types'; | ||
import { Choices } from './types'; | ||
import { ConstOrContextFunc, ContextPathFunc } from '../generic-types.js'; | ||
import { Choices } from './types.js'; | ||
export declare function combineHideAndChoices<Context>(actionPrefix: string, choices: ConstOrContextFunc<Context, Choices>, hide: undefined | ContextPathFunc<Context, boolean>): ContextPathFunc<Context, boolean>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.combineHideAndChoices = void 0; | ||
const understand_choices_1 = require("./understand-choices"); | ||
const understand_choices_js_1 = require("./understand-choices.js"); | ||
function combineHideAndChoices(actionPrefix, choices, hide) { | ||
return async (context, path) => { | ||
if (await (hide === null || hide === void 0 ? void 0 : hide(context, path))) { | ||
if (await hide?.(context, path)) { | ||
return true; | ||
} | ||
const match = new RegExp('/' + actionPrefix + ':([^/]+)/?$').exec(path); | ||
const toBeFound = match === null || match === void 0 ? void 0 : match[1]; | ||
const toBeFound = match?.[1]; | ||
if (!toBeFound) { | ||
@@ -16,3 +16,3 @@ throw new TypeError('could not read choice from path'); | ||
const choicesConstant = typeof choices === 'function' ? await choices(context) : choices; | ||
const choiceKeys = (0, understand_choices_1.getChoiceKeysFromChoices)(choicesConstant); | ||
const choiceKeys = (0, understand_choices_js_1.getChoiceKeysFromChoices)(choicesConstant); | ||
const keyExists = choiceKeys.includes(toBeFound); | ||
@@ -19,0 +19,0 @@ if (!keyExists) { |
@@ -1,6 +0,6 @@ | ||
import { CallbackButtonTemplate } from '../keyboard'; | ||
import { ConstOrContextFunc } from '../generic-types'; | ||
import { Choices, ManyChoicesOptions, ChoiceTextFunc } from './types'; | ||
import { CallbackButtonTemplate } from '../keyboard.js'; | ||
import { ConstOrContextFunc } from '../generic-types.js'; | ||
import { Choices, ManyChoicesOptions, ChoiceTextFunc } from './types.js'; | ||
export declare function generateChoicesButtons<Context>(actionPrefix: string, isSubmenu: boolean, choices: ConstOrContextFunc<Context, Choices>, options: ManyChoicesOptions<Context>): (context: Context, path: string) => Promise<CallbackButtonTemplate[][]>; | ||
export declare function generateChoicesPaginationButtons<Context>(actionPrefix: string, choiceKeys: number, currentPage: number | undefined, options: ManyChoicesOptions<Context>): CallbackButtonTemplate[]; | ||
export declare function createChoiceTextFunction<Context>(choices: Choices, buttonText: undefined | ChoiceTextFunc<Context>): ChoiceTextFunc<Context>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.createChoiceTextFunction = exports.generateChoicesPaginationButtons = exports.generateChoicesButtons = void 0; | ||
const pagination_1 = require("../buttons/pagination"); | ||
const align_1 = require("../buttons/align"); | ||
const understand_choices_1 = require("./understand-choices"); | ||
const pagination_js_1 = require("../buttons/pagination.js"); | ||
const align_js_1 = require("../buttons/align.js"); | ||
const understand_choices_js_1 = require("./understand-choices.js"); | ||
function generateChoicesButtons(actionPrefix, isSubmenu, choices, options) { | ||
return async (context, path) => { | ||
var _a, _b; | ||
if (await ((_a = options.hide) === null || _a === void 0 ? void 0 : _a.call(options, context, path))) { | ||
if (await options.hide?.(context, path)) { | ||
return []; | ||
} | ||
const choicesConstant = typeof choices === 'function' ? await choices(context) : choices; | ||
const choiceKeys = (0, understand_choices_1.getChoiceKeysFromChoices)(choicesConstant); | ||
(0, understand_choices_1.ensureCorrectChoiceKeys)(actionPrefix, path, choiceKeys); | ||
const choiceKeys = (0, understand_choices_js_1.getChoiceKeysFromChoices)(choicesConstant); | ||
(0, understand_choices_js_1.ensureCorrectChoiceKeys)(actionPrefix, path, choiceKeys); | ||
const textFunction = createChoiceTextFunction(choicesConstant, options.buttonText); | ||
const currentPage = await ((_b = options.getCurrentPage) === null || _b === void 0 ? void 0 : _b.call(options, context)); | ||
const keysOfPage = (0, align_1.getButtonsOfPage)(choiceKeys, options.columns, options.maxRows, currentPage); | ||
const currentPage = await options.getCurrentPage?.(context); | ||
const keysOfPage = (0, align_js_1.getButtonsOfPage)(choiceKeys, options.columns, options.maxRows, currentPage); | ||
const buttonsOfPage = await Promise.all(keysOfPage | ||
@@ -25,3 +24,3 @@ .map(async (key) => { | ||
})); | ||
const rows = (0, align_1.getButtonsAsRows)(buttonsOfPage, options.columns); | ||
const rows = (0, align_js_1.getButtonsAsRows)(buttonsOfPage, options.columns); | ||
if (options.setPage) { | ||
@@ -35,6 +34,6 @@ rows.push(generateChoicesPaginationButtons(actionPrefix, choiceKeys.length, currentPage, options)); | ||
function generateChoicesPaginationButtons(actionPrefix, choiceKeys, currentPage, options) { | ||
const entriesPerPage = (0, align_1.maximumButtonsPerPage)(options.columns, options.maxRows); | ||
const entriesPerPage = (0, align_js_1.maximumButtonsPerPage)(options.columns, options.maxRows); | ||
const totalPages = choiceKeys / entriesPerPage; | ||
const pageRecord = (0, pagination_1.createPaginationChoices)(totalPages, currentPage); | ||
const pageKeys = Object.keys(pageRecord).map(o => Number(o)); | ||
const pageRecord = (0, pagination_js_1.createPaginationChoices)(totalPages, currentPage); | ||
const pageKeys = Object.keys(pageRecord).map(Number); | ||
const pageButtons = pageKeys | ||
@@ -52,5 +51,5 @@ .map((page) => ({ | ||
} | ||
return (_, key) => (0, understand_choices_1.getChoiceTextByKey)(choices, key); | ||
return (_, key) => (0, understand_choices_js_1.getChoiceTextByKey)(choices, key); | ||
} | ||
exports.createChoiceTextFunction = createChoiceTextFunction; | ||
//# sourceMappingURL=buttons.js.map |
@@ -1,3 +0,3 @@ | ||
export * from './actions'; | ||
export * from './buttons'; | ||
export * from './types'; | ||
export * from './actions.js'; | ||
export * from './buttons.js'; | ||
export * from './types.js'; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -13,5 +17,5 @@ if (k2 === undefined) k2 = k; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./actions"), exports); | ||
__exportStar(require("./buttons"), exports); | ||
__exportStar(require("./types"), exports); | ||
__exportStar(require("./actions.js"), exports); | ||
__exportStar(require("./buttons.js"), exports); | ||
__exportStar(require("./types.js"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -1,4 +0,4 @@ | ||
import { BasicOptions } from '../buttons/basic'; | ||
import { ConstOrPromise } from '../generic-types'; | ||
import { GenericPaginationOptions } from '../buttons/pagination'; | ||
import { BasicOptions } from '../buttons/basic.js'; | ||
import { ConstOrPromise } from '../generic-types.js'; | ||
import { GenericPaginationOptions } from '../buttons/pagination.js'; | ||
export declare type Choice = string | number; | ||
@@ -8,3 +8,3 @@ export declare type ChoiceText = string; | ||
export declare type ChoicesRecord = Readonly<Record<Choice, ChoiceText>>; | ||
export declare type ChoicesMap = ReadonlyMap<Choice, ChoiceText>; | ||
export declare type ChoicesMap = Readonly<ReadonlyMap<Choice, ChoiceText>>; | ||
export declare type Choices = ChoicesArray | ChoicesRecord | ChoicesMap; | ||
@@ -11,0 +11,0 @@ export declare type ChoiceTextFunc<Context> = (context: Context, key: string) => ConstOrPromise<string>; |
@@ -1,2 +0,2 @@ | ||
import { Choices, ChoicesArray, ChoicesMap } from './types'; | ||
import { Choices, ChoicesArray, ChoicesMap } from './types.js'; | ||
export declare function choicesIsArray(choices: Choices): choices is ChoicesArray; | ||
@@ -3,0 +3,0 @@ export declare function choicesIsMap(choices: Choices): choices is ChoicesMap; |
@@ -14,6 +14,6 @@ "use strict"; | ||
if (choicesIsArray(choices)) { | ||
return choices.map(o => String(o)); | ||
return choices.map(String); | ||
} | ||
if (choicesIsMap(choices)) { | ||
return [...choices.keys()].map(o => String(o)); | ||
return [...choices.keys()].map(String); | ||
} | ||
@@ -24,3 +24,2 @@ return Object.keys(choices); | ||
function getChoiceTextByKey(choices, key) { | ||
var _a; | ||
if (choicesIsArray(choices)) { | ||
@@ -30,3 +29,3 @@ return key; | ||
if (choicesIsMap(choices)) { | ||
return (_a = choices.get(key)) !== null && _a !== void 0 ? _a : key; | ||
return choices.get(key) ?? key; | ||
} | ||
@@ -33,0 +32,0 @@ const choice = choices[key]; |
@@ -1,6 +0,6 @@ | ||
export { Body } from './body'; | ||
export { getMenuOfPath } from './path'; | ||
export * from './menu-middleware'; | ||
export * from './menu-template'; | ||
export * from './row-creators'; | ||
export * from './send-menu'; | ||
export { Body } from './body.js'; | ||
export { getMenuOfPath } from './path.js'; | ||
export * from './menu-middleware.js'; | ||
export * from './menu-template.js'; | ||
export * from './row-creators/index.js'; | ||
export * from './send-menu.js'; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -14,8 +18,8 @@ if (k2 === undefined) k2 = k; | ||
exports.getMenuOfPath = void 0; | ||
var path_1 = require("./path"); | ||
Object.defineProperty(exports, "getMenuOfPath", { enumerable: true, get: function () { return path_1.getMenuOfPath; } }); | ||
__exportStar(require("./menu-middleware"), exports); | ||
__exportStar(require("./menu-template"), exports); | ||
__exportStar(require("./row-creators"), exports); | ||
__exportStar(require("./send-menu"), exports); | ||
var path_js_1 = require("./path.js"); | ||
Object.defineProperty(exports, "getMenuOfPath", { enumerable: true, get: function () { return path_js_1.getMenuOfPath; } }); | ||
__exportStar(require("./menu-middleware.js"), exports); | ||
__exportStar(require("./menu-template.js"), exports); | ||
__exportStar(require("./row-creators/index.js"), exports); | ||
__exportStar(require("./send-menu.js"), exports); | ||
//# sourceMappingURL=index.js.map |
import { InlineKeyboardButton as TelegramInlineKeyboardButton } from '@grammyjs/types'; | ||
import { ConstOrContextPathFunc, ContextPathFunc } from './generic-types'; | ||
import { ReadonlyDeep } from 'type-fest'; | ||
import { ConstOrContextPathFunc, ContextPathFunc } from './generic-types.js'; | ||
export interface CallbackButtonTemplate { | ||
@@ -7,3 +8,3 @@ readonly text: string; | ||
} | ||
export declare type InlineKeyboardButton = Readonly<TelegramInlineKeyboardButton>; | ||
export declare type InlineKeyboardButton = ReadonlyDeep<TelegramInlineKeyboardButton>; | ||
export declare type InlineKeyboard = ReadonlyArray<readonly InlineKeyboardButton[]>; | ||
@@ -10,0 +11,0 @@ export declare type ButtonTemplate = CallbackButtonTemplate | InlineKeyboardButton; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Keyboard = void 0; | ||
const generic_types_1 = require("./generic-types"); | ||
const path_1 = require("./path"); | ||
const node_buffer_1 = require("node:buffer"); | ||
const generic_types_js_1 = require("./generic-types.js"); | ||
const path_js_1 = require("./path.js"); | ||
function isRow(entry) { | ||
@@ -33,3 +34,5 @@ return Array.isArray(entry); | ||
async render(context, path) { | ||
const arrayOfRowArrays = await Promise.all(this._entries.map(async (o) => entryToRows(o, context, path))); | ||
const arrayOfRowArrays = await Promise.all( | ||
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types | ||
this._entries.map(async (o) => entryToRows(o, context, path))); | ||
const rows = arrayOfRowArrays | ||
@@ -44,8 +47,8 @@ .flat(1) | ||
async function entryToRows(entry, context, path) { | ||
if (isRow(entry)) { | ||
const buttonsInRow = await Promise.all(entry.map(async (button) => typeof button === 'function' ? button(context, path) : button)); | ||
const filtered = buttonsInRow.filter((0, generic_types_1.filterNonNullable)()); | ||
return [filtered]; | ||
if (typeof entry === 'function') { | ||
return entry(context, path); | ||
} | ||
return entry(context, path); | ||
const buttonsInRow = await Promise.all(entry.map(async (button) => typeof button === 'function' ? button(context, path) : button)); | ||
const filtered = buttonsInRow.filter((0, generic_types_js_1.filterNonNullable)()); | ||
return [filtered]; | ||
} | ||
@@ -57,5 +60,6 @@ function renderRow(templates, path) { | ||
function renderCallbackButtonTemplate(template, path) { | ||
const absolutePath = (0, path_1.combinePath)(path, template.relativePath); | ||
if (absolutePath.length > 64) { | ||
throw new Error(`callback_data only supports 1-64 bytes. With this button (${template.relativePath}) it would get too long (${absolutePath.length}). Full path: ${absolutePath}`); | ||
const absolutePath = (0, path_js_1.combinePath)(path, template.relativePath); | ||
const absolutePathLength = node_buffer_1.Buffer.byteLength(absolutePath, 'utf8'); | ||
if (absolutePathLength > 64) { | ||
throw new Error(`callback_data only supports 1-64 bytes. With this button (${template.relativePath}) it would get too long (${absolutePathLength}). Full path: ${absolutePath}`); | ||
} | ||
@@ -62,0 +66,0 @@ return { |
@@ -1,5 +0,5 @@ | ||
import { Body } from './body'; | ||
import { ButtonAction } from './action-hive'; | ||
import { ContextPathFunc, RegExpLike } from './generic-types'; | ||
import { InlineKeyboard } from './keyboard'; | ||
import { Body } from './body.js'; | ||
import { ButtonAction } from './action-hive.js'; | ||
import { ContextPathFunc, RegExpLike } from './generic-types.js'; | ||
import { InlineKeyboard } from './keyboard.js'; | ||
export interface MenuLike<Context> { | ||
@@ -6,0 +6,0 @@ readonly renderBody: ContextPathFunc<Context, Body>; |
import { Context as BaseContext } from 'grammy'; | ||
import { RegExpLike } from './generic-types'; | ||
import { MenuLike } from './menu-like'; | ||
import { SendMenuFunc } from './send-menu'; | ||
import { RegExpLike } from './generic-types.js'; | ||
import { MenuLike } from './menu-like.js'; | ||
import { SendMenuFunc } from './send-menu.js'; | ||
export interface Options<Context> { | ||
@@ -6,0 +6,0 @@ /** |
@@ -5,7 +5,6 @@ "use strict"; | ||
const grammy_1 = require("grammy"); | ||
const path_1 = require("./path"); | ||
const send_menu_1 = require("./send-menu"); | ||
const path_js_1 = require("./path.js"); | ||
const send_menu_js_1 = require("./send-menu.js"); | ||
class MenuMiddleware { | ||
constructor(rootTrigger, rootMenu, options = {}) { | ||
var _a; | ||
Object.defineProperty(this, "rootTrigger", { | ||
@@ -41,5 +40,5 @@ enumerable: true, | ||
}); | ||
const rootTriggerRegex = (0, path_1.createRootMenuTrigger)(rootTrigger); | ||
const rootTriggerRegex = (0, path_js_1.createRootMenuTrigger)(rootTrigger); | ||
this._responder = createResponder(rootTriggerRegex, () => true, rootMenu); | ||
this._sendMenu = (_a = options.sendMenu) !== null && _a !== void 0 ? _a : send_menu_1.editMenuOnContext; | ||
this._sendMenu = options.sendMenu ?? send_menu_js_1.editMenuOnContext; | ||
} | ||
@@ -67,3 +66,3 @@ /** | ||
} | ||
return (0, send_menu_1.replyMenuToContext)(responder.menu, context, path); | ||
return (0, send_menu_js_1.replyMenuToContext)(responder.menu, context, path); | ||
} | ||
@@ -89,10 +88,10 @@ /** | ||
const { match, responder } = await getLongestMatchActionResponder(context, path, this._responder); | ||
if ((match === null || match === void 0 ? void 0 : match[0]) && responder.type === 'action') { | ||
if (match?.[0] && responder.type === 'action') { | ||
context.match = match; | ||
const afterwardsTarget = await responder.do(context, match[0]); | ||
if (typeof afterwardsTarget === 'string' && afterwardsTarget) { | ||
target = (0, path_1.combinePath)(path, afterwardsTarget); | ||
target = (0, path_js_1.combinePath)(path, afterwardsTarget); | ||
} | ||
else if (afterwardsTarget === true) { | ||
target = (0, path_1.combinePath)(path, '.'); | ||
target = (0, path_js_1.combinePath)(path, '.'); | ||
} | ||
@@ -109,3 +108,3 @@ else if (afterwardsTarget === false) { | ||
const { match, responder } = await getLongestMatchMenuResponder(context, target, this._responder); | ||
if (!(match === null || match === void 0 ? void 0 : match[0])) { | ||
if (!match?.[0]) { | ||
// TODO: think about using next() in this case? | ||
@@ -133,3 +132,3 @@ throw new Error(`There is no menu "${target}" which can be reached in this menu`); | ||
function responderMatch(responder, path) { | ||
return new RegExp(responder.trigger.source, responder.trigger.flags).exec(path); | ||
return new RegExp(responder.trigger.source, responder.trigger.flags).exec(path) ?? undefined; | ||
} | ||
@@ -139,3 +138,3 @@ async function getLongestMatchMenuResponder(context, path, current) { | ||
const match = responderMatch(sub, path); | ||
if (!(match === null || match === void 0 ? void 0 : match[0])) { | ||
if (!match?.[0]) { | ||
continue; | ||
@@ -157,3 +156,3 @@ } | ||
const match = responderMatch(sub, path); | ||
if (!(match === null || match === void 0 ? void 0 : match[0])) { | ||
if (!match?.[0]) { | ||
continue; | ||
@@ -187,6 +186,5 @@ } | ||
.map((submenu) => { | ||
const submenuTrigger = (0, path_1.combineTrigger)(menuTrigger, submenu.action); | ||
const submenuTrigger = (0, path_js_1.combineTrigger)(menuTrigger, submenu.action); | ||
const canEnterSubmenu = async (context, path) => { | ||
var _a; | ||
if (await ((_a = submenu.hide) === null || _a === void 0 ? void 0 : _a.call(submenu, context, path))) { | ||
if (await submenu.hide?.(context, path)) { | ||
return false; | ||
@@ -193,0 +191,0 @@ } |
@@ -1,13 +0,13 @@ | ||
import { Body } from './body'; | ||
import { ButtonAction, ActionFunc } from './action-hive'; | ||
import { Choices } from './choices'; | ||
import { ChooseOptions } from './buttons/choose'; | ||
import { ContextPathFunc, ConstOrContextFunc, ConstOrContextPathFunc, RegExpLike } from './generic-types'; | ||
import { ButtonTemplate, ButtonTemplateRow, InlineKeyboard } from './keyboard'; | ||
import { MenuLike, Submenu } from './menu-like'; | ||
import { PaginationOptions } from './buttons/pagination'; | ||
import { SelectOptions } from './buttons/select'; | ||
import { SingleButtonOptions } from './buttons/basic'; | ||
import { SubmenuOptions, ChooseIntoSubmenuOptions } from './buttons/submenu'; | ||
import { ToggleOptions } from './buttons/toggle'; | ||
import { Body } from './body.js'; | ||
import { ButtonAction, ActionFunc } from './action-hive.js'; | ||
import { Choices } from './choices/index.js'; | ||
import { ChooseOptions } from './buttons/choose.js'; | ||
import { ContextPathFunc, ConstOrContextFunc, ConstOrContextPathFunc, RegExpLike } from './generic-types.js'; | ||
import { ButtonTemplate, ButtonTemplateRow, InlineKeyboard } from './keyboard.js'; | ||
import { MenuLike, Submenu } from './menu-like.js'; | ||
import { PaginationOptions } from './buttons/pagination.js'; | ||
import { SelectOptions } from './buttons/select.js'; | ||
import { SingleButtonOptions } from './buttons/basic.js'; | ||
import { SubmenuOptions, ChooseIntoSubmenuOptions } from './buttons/submenu.js'; | ||
import { ToggleOptions } from './buttons/toggle.js'; | ||
export interface InteractionOptions<Context> extends SingleButtonOptions<Context> { | ||
@@ -14,0 +14,0 @@ /** |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.MenuTemplate = void 0; | ||
const action_hive_1 = require("./action-hive"); | ||
const choices_1 = require("./choices"); | ||
const path_1 = require("./path"); | ||
const keyboard_1 = require("./keyboard"); | ||
const pagination_1 = require("./buttons/pagination"); | ||
const select_1 = require("./buttons/select"); | ||
const toggle_1 = require("./buttons/toggle"); | ||
const action_hive_js_1 = require("./action-hive.js"); | ||
const index_js_1 = require("./choices/index.js"); | ||
const path_js_1 = require("./path.js"); | ||
const keyboard_js_1 = require("./keyboard.js"); | ||
const pagination_js_1 = require("./buttons/pagination.js"); | ||
const select_js_1 = require("./buttons/select.js"); | ||
const toggle_js_1 = require("./buttons/toggle.js"); | ||
class MenuTemplate { | ||
constructor(body) { | ||
constructor( | ||
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types | ||
body) { | ||
Object.defineProperty(this, "_body", { | ||
@@ -23,3 +25,3 @@ enumerable: true, | ||
writable: true, | ||
value: new keyboard_1.Keyboard() | ||
value: new keyboard_js_1.Keyboard() | ||
}); | ||
@@ -30,3 +32,3 @@ Object.defineProperty(this, "_actions", { | ||
writable: true, | ||
value: new action_hive_1.ActionHive() | ||
value: new action_hive_js_1.ActionHive() | ||
}); | ||
@@ -210,3 +212,3 @@ Object.defineProperty(this, "_submenus", { | ||
submenu(text, action, submenu, options = {}) { | ||
(0, path_1.ensureTriggerChild)(action); | ||
(0, path_js_1.ensureTriggerChild)(action); | ||
const actionRegex = new RegExp(action + '/'); | ||
@@ -237,3 +239,3 @@ if ([...this._submenus].map(o => o.action.source).includes(actionRegex.source)) { | ||
const trigger = new RegExp(actionPrefix + ':(.+)$'); | ||
this._actions.add(trigger, async (context, path) => options.do(context, getKeyFromPath(trigger, path)), options.disableChoiceExistsCheck ? options.hide : (0, choices_1.combineHideAndChoices)(actionPrefix, choices, options.hide)); | ||
this._actions.add(trigger, async (context, path) => options.do(context, getKeyFromPath(trigger, path)), options.disableChoiceExistsCheck ? options.hide : (0, index_js_1.combineHideAndChoices)(actionPrefix, choices, options.hide)); | ||
if (options.setPage) { | ||
@@ -243,3 +245,3 @@ const pageTrigger = new RegExp(actionPrefix + 'P:(\\d+)$'); | ||
} | ||
this._keyboard.addCreator((0, choices_1.generateChoicesButtons)(actionPrefix, false, choices, options)); | ||
this._keyboard.addCreator((0, index_js_1.generateChoicesButtons)(actionPrefix, false, choices, options)); | ||
} | ||
@@ -266,3 +268,3 @@ /** | ||
chooseIntoSubmenu(actionPrefix, choices, submenu, options = {}) { | ||
(0, path_1.ensureTriggerChild)(actionPrefix); | ||
(0, path_js_1.ensureTriggerChild)(actionPrefix); | ||
const actionRegex = new RegExp(actionPrefix + ':([^/]+)/'); | ||
@@ -274,3 +276,3 @@ if ([...this._submenus].map(o => o.action.source).includes(actionRegex.source)) { | ||
action: actionRegex, | ||
hide: options.disableChoiceExistsCheck ? options.hide : (0, choices_1.combineHideAndChoices)(actionPrefix, choices, options.hide), | ||
hide: options.disableChoiceExistsCheck ? options.hide : (0, index_js_1.combineHideAndChoices)(actionPrefix, choices, options.hide), | ||
menu: submenu, | ||
@@ -282,3 +284,3 @@ }); | ||
} | ||
this._keyboard.addCreator((0, choices_1.generateChoicesButtons)(actionPrefix, true, choices, options)); | ||
this._keyboard.addCreator((0, index_js_1.generateChoicesButtons)(actionPrefix, true, choices, options)); | ||
} | ||
@@ -321,3 +323,3 @@ /** | ||
return options.set(context, key, true); | ||
}, options.disableChoiceExistsCheck ? options.hide : (0, choices_1.combineHideAndChoices)(actionPrefix + 'T', choices, options.hide)); | ||
}, options.disableChoiceExistsCheck ? options.hide : (0, index_js_1.combineHideAndChoices)(actionPrefix + 'T', choices, options.hide)); | ||
const falseTrigger = new RegExp(actionPrefix + 'F:(.+)$'); | ||
@@ -327,3 +329,3 @@ this._actions.add(falseTrigger, async (context, path) => { | ||
return options.set(context, key, false); | ||
}, options.disableChoiceExistsCheck ? options.hide : (0, choices_1.combineHideAndChoices)(actionPrefix + 'F', choices, options.hide)); | ||
}, options.disableChoiceExistsCheck ? options.hide : (0, index_js_1.combineHideAndChoices)(actionPrefix + 'F', choices, options.hide)); | ||
if (options.setPage) { | ||
@@ -333,3 +335,3 @@ const pageTrigger = new RegExp(actionPrefix + 'P:(\\d+)$'); | ||
} | ||
this._keyboard.addCreator((0, select_1.generateSelectButtons)(actionPrefix, choices, options)); | ||
this._keyboard.addCreator((0, select_js_1.generateSelectButtons)(actionPrefix, choices, options)); | ||
} | ||
@@ -350,7 +352,7 @@ /** | ||
const currentPage = await options.getCurrentPage(context); | ||
return (0, pagination_1.createPaginationChoices)(totalPages, currentPage); | ||
return (0, pagination_js_1.createPaginationChoices)(totalPages, currentPage); | ||
}; | ||
const trigger = new RegExp(actionPrefix + ':(\\d+)$'); | ||
this._actions.add(trigger, setPageAction(trigger, options.setPage), options.hide); | ||
this._keyboard.addCreator((0, choices_1.generateChoicesButtons)(actionPrefix, false, paginationChoices, { | ||
this._keyboard.addCreator((0, index_js_1.generateChoicesButtons)(actionPrefix, false, paginationChoices, { | ||
columns: 5, | ||
@@ -394,3 +396,3 @@ hide: options.hide, | ||
this._actions.add(new RegExp(actionPrefix + ':false$'), async (context, path) => options.set(context, false, path), options.hide); | ||
this._keyboard.add(Boolean(options.joinLastRow), (0, toggle_1.generateToggleButton)(text, actionPrefix, options)); | ||
this._keyboard.add(Boolean(options.joinLastRow), (0, toggle_js_1.generateToggleButton)(text, actionPrefix, options)); | ||
} | ||
@@ -401,3 +403,3 @@ } | ||
return async (context, path) => { | ||
if (await (hide === null || hide === void 0 ? void 0 : hide(context, path))) { | ||
if (await hide?.(context, path)) { | ||
return undefined; | ||
@@ -413,3 +415,3 @@ } | ||
const match = new RegExp(trigger.source, trigger.flags).exec(path); | ||
const key = match === null || match === void 0 ? void 0 : match[1]; | ||
const key = match?.[1]; | ||
if (!key) { | ||
@@ -416,0 +418,0 @@ throw new Error(`Could not read key from path '${path}' for trigger '${trigger.source}'`); |
@@ -1,2 +0,2 @@ | ||
import { RegExpLike } from './generic-types'; | ||
import { RegExpLike } from './generic-types.js'; | ||
export declare function ensureTriggerChild(trigger: string | RegExpLike): void; | ||
@@ -3,0 +3,0 @@ export declare function ensureTriggerLastChild(trigger: string | RegExpLike): void; |
@@ -36,5 +36,4 @@ "use strict"; | ||
function createRootMenuTrigger(rootTrigger) { | ||
var _a; | ||
if (typeof rootTrigger === 'string') { | ||
const count = (_a = rootTrigger.match(/\//g)) === null || _a === void 0 ? void 0 : _a.length; | ||
const count = rootTrigger.match(/\//g)?.length; | ||
if (count !== 1) { | ||
@@ -41,0 +40,0 @@ throw new Error('The root menu trigger can only trigger exactly one slash as each slash represents a submenu /'); |
@@ -14,7 +14,6 @@ "use strict"; | ||
function prefixEmoji(text, prefix, options = {}) { | ||
var _a, _b; | ||
const internalOptions = { | ||
...options, | ||
prefixTrue: (_a = options.prefixTrue) !== null && _a !== void 0 ? _a : exports.emojiTrue, | ||
prefixFalse: (_b = options.prefixFalse) !== null && _b !== void 0 ? _b : exports.emojiFalse, | ||
prefixTrue: options.prefixTrue ?? exports.emojiTrue, | ||
prefixFalse: options.prefixFalse ?? exports.emojiFalse, | ||
}; | ||
@@ -21,0 +20,0 @@ const prefixContent = applyOptionsToPrefix(prefix, internalOptions); |
@@ -1,3 +0,3 @@ | ||
import { CallbackButtonTemplate } from '../keyboard'; | ||
import { ConstOrContextPathFunc } from '../generic-types'; | ||
import { CallbackButtonTemplate } from '../keyboard.js'; | ||
import { ConstOrContextPathFunc } from '../generic-types.js'; | ||
export declare function createBackMainMenuButtons<Context>(backButtonText?: ConstOrContextPathFunc<Context, string>, mainMenuButtonText?: ConstOrContextPathFunc<Context, string>): (context: Context, path: string) => Promise<CallbackButtonTemplate[][]>; |
@@ -1,1 +0,1 @@ | ||
export * from './back-main-buttons'; | ||
export * from './back-main-buttons.js'; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
@@ -13,3 +17,3 @@ if (k2 === undefined) k2 = k; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./back-main-buttons"), exports); | ||
__exportStar(require("./back-main-buttons.js"), exports); | ||
//# sourceMappingURL=index.js.map |
import { Context as BaseContext, Api } from 'grammy'; | ||
import { Message } from '@grammyjs/types'; | ||
import { MenuLike } from './menu-like'; | ||
import { MenuLike } from './menu-like.js'; | ||
/** | ||
@@ -5,0 +5,0 @@ * Generic Method which is able to send a menu to a context (given a path where it is) |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.generateEditMessageIntoMenuFunction = exports.generateSendMenuToChatFunction = exports.resendMenuToContext = exports.deleteMenuFromContext = exports.editMenuOnContext = exports.replyMenuToContext = void 0; | ||
const body_1 = require("./body"); | ||
const path_1 = require("./path"); | ||
const body_js_1 = require("./body.js"); | ||
const path_js_1 = require("./path.js"); | ||
/** | ||
@@ -14,3 +14,3 @@ * Reply a menu to a context as a new message | ||
async function replyMenuToContext(menu, context, path, other) { | ||
(0, path_1.ensurePathMenu)(path); | ||
(0, path_js_1.ensurePathMenu)(path); | ||
const body = await menu.renderBody(context, path); | ||
@@ -29,11 +29,10 @@ const keyboard = await menu.renderKeyboard(context, path); | ||
async function editMenuOnContext(menu, context, path, other = {}) { | ||
var _a; | ||
(0, path_1.ensurePathMenu)(path); | ||
(0, path_js_1.ensurePathMenu)(path); | ||
const body = await menu.renderBody(context, path); | ||
const keyboard = await menu.renderKeyboard(context, path); | ||
const message = (_a = context.callbackQuery) === null || _a === void 0 ? void 0 : _a.message; | ||
const message = context.callbackQuery?.message; | ||
if (!message) { | ||
return replyRenderedMenuPartsToContext(body, keyboard, context, other); | ||
} | ||
if ((0, body_1.isMediaBody)(body)) { | ||
if ((0, body_js_1.isMediaBody)(body)) { | ||
if ('animation' in message || 'audio' in message || 'document' in message || 'photo' in message || 'video' in message) { | ||
@@ -46,14 +45,12 @@ return context.editMessageMedia({ | ||
}, createGenericOther(keyboard, other)) | ||
// eslint-disable-next-line promise/prefer-await-to-then | ||
.catch(catchMessageNotModified); | ||
} | ||
} | ||
else if ((0, body_1.isLocationBody)(body) || (0, body_1.isVenueBody)(body) || (0, body_1.isInvoiceBody)(body)) { | ||
else if ((0, body_js_1.isLocationBody)(body) || (0, body_js_1.isVenueBody)(body) || (0, body_js_1.isInvoiceBody)(body)) { | ||
// Dont edit the message, just recreate it. | ||
} | ||
else if ((0, body_1.isTextBody)(body)) { | ||
const text = (0, body_1.getBodyText)(body); | ||
else if ((0, body_js_1.isTextBody)(body)) { | ||
const text = (0, body_js_1.getBodyText)(body); | ||
if ('text' in message) { | ||
return context.editMessageText(text, createTextOther(body, keyboard, other)) | ||
// eslint-disable-next-line promise/prefer-await-to-then | ||
.catch(catchMessageNotModified); | ||
@@ -109,4 +106,5 @@ } | ||
} | ||
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types | ||
async function replyRenderedMenuPartsToContext(body, keyboard, context, other = {}) { | ||
if ((0, body_1.isMediaBody)(body)) { | ||
if ((0, body_js_1.isMediaBody)(body)) { | ||
const mediaOther = createSendMediaOther(body, keyboard, other); | ||
@@ -127,15 +125,15 @@ // eslint-disable-next-line default-case | ||
} | ||
if ((0, body_1.isLocationBody)(body)) { | ||
if ((0, body_js_1.isLocationBody)(body)) { | ||
return context.replyWithLocation(body.location.latitude, body.location.longitude, createLocationOther(body, keyboard, other)); | ||
} | ||
if ((0, body_1.isVenueBody)(body)) { | ||
if ((0, body_js_1.isVenueBody)(body)) { | ||
const { location, title, address } = body.venue; | ||
return context.replyWithVenue(location.latitude, location.longitude, title, address, createVenueOther(body, keyboard, other)); | ||
} | ||
if ((0, body_1.isInvoiceBody)(body)) { | ||
if ((0, body_js_1.isInvoiceBody)(body)) { | ||
const { title, description, payload, provider_token, currency, prices } = body.invoice; | ||
return context.replyWithInvoice(title, description, payload, provider_token, currency, prices, createGenericOther(keyboard, other)); | ||
} | ||
if ((0, body_1.isTextBody)(body)) { | ||
const text = (0, body_1.getBodyText)(body); | ||
if ((0, body_js_1.isTextBody)(body)) { | ||
const text = (0, body_js_1.getBodyText)(body); | ||
return context.reply(text, createTextOther(body, keyboard, other)); | ||
@@ -156,3 +154,3 @@ } | ||
const keyboard = await menu.renderKeyboard(context, path); | ||
if ((0, body_1.isMediaBody)(body)) { | ||
if ((0, body_js_1.isMediaBody)(body)) { | ||
const mediaOther = createSendMediaOther(body, keyboard, other); | ||
@@ -173,15 +171,15 @@ // eslint-disable-next-line default-case | ||
} | ||
if ((0, body_1.isLocationBody)(body)) { | ||
if ((0, body_js_1.isLocationBody)(body)) { | ||
return telegram.sendLocation(chatId, body.location.latitude, body.location.longitude, createLocationOther(body, keyboard, other)); | ||
} | ||
if ((0, body_1.isVenueBody)(body)) { | ||
if ((0, body_js_1.isVenueBody)(body)) { | ||
const { location, title, address } = body.venue; | ||
return telegram.sendVenue(chatId, location.latitude, location.longitude, title, address, createVenueOther(body, keyboard, other)); | ||
} | ||
if ((0, body_1.isInvoiceBody)(body)) { | ||
if ((0, body_js_1.isInvoiceBody)(body)) { | ||
const { title, description, payload, provider_token, currency, prices } = body.invoice; | ||
return telegram.sendInvoice(chatId, title, description, payload, provider_token, currency, prices, createGenericOther(keyboard, other)); | ||
} | ||
if ((0, body_1.isTextBody)(body)) { | ||
const text = (0, body_1.getBodyText)(body); | ||
if ((0, body_js_1.isTextBody)(body)) { | ||
const text = (0, body_js_1.getBodyText)(body); | ||
return telegram.sendMessage(chatId, text, createTextOther(body, keyboard, other)); | ||
@@ -205,3 +203,3 @@ } | ||
const keyboard = await menu.renderKeyboard(context, path); | ||
if ((0, body_1.isMediaBody)(body)) { | ||
if ((0, body_js_1.isMediaBody)(body)) { | ||
return telegram.editMessageMedia(chatId, messageId, { | ||
@@ -214,13 +212,13 @@ type: body.type, | ||
} | ||
if ((0, body_1.isLocationBody)(body)) { | ||
if ((0, body_js_1.isLocationBody)(body)) { | ||
throw new Error('You can not edit into a location body. You have to send the menu as a new message.'); | ||
} | ||
if ((0, body_1.isVenueBody)(body)) { | ||
if ((0, body_js_1.isVenueBody)(body)) { | ||
throw new Error('You can not edit into a venue body. You have to send the menu as a new message.'); | ||
} | ||
if ((0, body_1.isInvoiceBody)(body)) { | ||
if ((0, body_js_1.isInvoiceBody)(body)) { | ||
throw new Error('You can not edit into an invoice body. You have to send the menu as a new message.'); | ||
} | ||
if ((0, body_1.isTextBody)(body)) { | ||
const text = (0, body_1.getBodyText)(body); | ||
if ((0, body_js_1.isTextBody)(body)) { | ||
const text = (0, body_js_1.getBodyText)(body); | ||
return telegram.editMessageText(chatId, messageId, text, createTextOther(body, keyboard, other)); | ||
@@ -242,2 +240,3 @@ } | ||
} | ||
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types | ||
function createSendMediaOther(body, keyboard, base) { | ||
@@ -262,3 +261,2 @@ return { | ||
} | ||
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types | ||
function createVenueOther(body, keyboard, base) { | ||
@@ -265,0 +263,0 @@ return { |
{ | ||
"name": "grammy-inline-menu", | ||
"version": "7.0.2", | ||
"version": "8.0.0", | ||
"description": "Inline Menus for Telegram made simple. Successor of telegraf-inline-menu.", | ||
@@ -37,3 +37,3 @@ "keywords": [ | ||
"engines": { | ||
"node": ">=12" | ||
"node": ">=14" | ||
}, | ||
@@ -47,5 +47,5 @@ "dependencies": { | ||
"devDependencies": { | ||
"@sindresorhus/tsconfig": "^2.0.0", | ||
"@types/node": "^12.20.19", | ||
"ava": "^3.6.0", | ||
"@sindresorhus/tsconfig": "^3.0.1", | ||
"@types/node": "^14.18.21", | ||
"ava": "^4.0.0", | ||
"del-cli": "^4.0.0", | ||
@@ -55,11 +55,8 @@ "grammy": "^1.3.0", | ||
"ts-node": "^10.0.0", | ||
"type-fest": "^2.11.2", | ||
"typescript": "^4.4.4", | ||
"xo": "^0.45.0" | ||
"xo": "^0.50.0" | ||
}, | ||
"files": [ | ||
"dist/source", | ||
"!*.test.*" | ||
], | ||
"main": "dist/source", | ||
"types": "dist/source", | ||
"main": "./dist/source/index.js", | ||
"types": "./dist/source/index.d.ts", | ||
"nyc": { | ||
@@ -81,6 +78,3 @@ "all": true, | ||
"@typescript-eslint/prefer-readonly-parameter-types": "error", | ||
"ava/no-ignored-test-files": "off", | ||
"ava/no-skip-test": "warn", | ||
"camelcase": "off", | ||
"import/extensions": "off" | ||
"ava/no-ignored-test-files": "off" | ||
}, | ||
@@ -93,2 +87,3 @@ "overrides": [ | ||
"rules": { | ||
"camelcase": "off", | ||
"dot-notation": "off" | ||
@@ -105,6 +100,8 @@ } | ||
"@typescript-eslint/ban-ts-comment": "off", | ||
"@typescript-eslint/no-empty-function": "off", | ||
"@typescript-eslint/no-unsafe-assignment": "off", | ||
"@typescript-eslint/no-unsafe-member-access": "off", | ||
"@typescript-eslint/no-unsafe-return": "off", | ||
"@typescript-eslint/prefer-readonly-parameter-types": "off", | ||
"unicorn/prefer-node-protocol": "off", | ||
"ava/no-skip-test": "warn", | ||
"max-params": "off" | ||
@@ -111,0 +108,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
174841
10
78
2283