
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
callback-data
Advanced tools
Lightweight and simple library that helps manage callback data when using inline keyboards.
$ npm install callback-data
import { createCallbackData } from "https://deno.land/x/callback_data/mod.ts";
import { Bot, InlineKeyboard } from "grammy";
import { createCallbackData } from "callback-data";
const bot = new Bot(process.env.BOT_TOKEN);
const greetingData = createCallbackData("greeting", {
type: String,
});
const greetingKeyboard = new InlineKeyboard()
.text(
"oldschool",
greetingData.pack({
type: "oldschool",
}), // callback data is equal to "greeting:oldschool"
)
.text(
"modern",
greetingData.pack({
type: "modern",
}), // callback data is equal to "greeting:modern"
);
bot.command("start", (ctx) =>
ctx.reply("How to greet?", {
reply_markup: greetingKeyboard,
}));
bot.callbackQuery(
greetingData.filter({
type: "oldschool",
}),
(ctx) => ctx.answerCallbackQuery("Hello"),
);
bot.callbackQuery(
greetingData.filter({
type: "modern",
}),
(ctx) => ctx.answerCallbackQuery("Yo"),
);
bot.start();
There's more complex example counter-bot.
const callbackData = createCallbackData(
// unique prefix for callback data
"data",
// callback data fields
{
id: Number,
name: String,
isAdmin: Boolean,
// only Number, String, Boolean data types are supported
},
);
const packedData = callbackData.pack({
id: 1337,
name: "John",
isAdmin: true,
});
console.log(packedData); // data:1337:John:1
const unpackedData = callbackData.unpack(packedData);
console.log(unpackedData);
// {
// id: 1337,
// name: "John",
// isAdmin: true,
// }
const regex = callbackData.filter({
id: 1337,
});
console.log(regex); // /^data:1337:(.+)?:(.+)?$/
FAQs
Easy callback data management for Telegram bots
The npm package callback-data receives a total of 1,360 weekly downloads. As such, callback-data popularity was classified as popular.
We found that callback-data demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.