Security News
Opengrep Emerges as Open Source Alternative Amid Semgrep Licensing Controversy
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
@grammyjs/chat-members
Advanced tools
This plugin watches for chat_member
updates and stores a list of users, their statuses and permissions for each chat
in which they and the bot are a member.
You can use a valid grammY storage adapter or an
instance of any class that implements the StorageAdapter
interface.
import { Bot, Context, MemorySessionStorage } from "grammy";
import type { ChatMember } from "@grammyjs/types";
import { chatMembers, ChatMembersFlavor } from "@grammyjs/chat-members";
type MyContext = Context & ChatMembersFlavor;
const adapter = new MemorySessionStorage<ChatMember>();
const bot = new Bot<MyContext>("<your bot token>");
bot.use(chatMembers(adapter));
bot.start({
allowed_updates: ["chat_member", "message"],
onStart: ({ username }) => console.log(`Listening as ${username}`),
});
This plugin also adds a new ctx.chatMembers.getChatMember
function that will check the storage for information about a
chat member before querying telegram for it. If the chat member exists in the storage, it will be returned. Otherwise,
ctx.api.getChatMember
will be called and the result will be saved to the storage, making subsequent calls faster and
removing the need to call telegram again for that user and chat in the future.
Here's an example:
bot.on("message", async (ctx) => {
const chatMember = await ctx.chatMembers.getChatMember();
return ctx.reply(`Hello, ${chatMember.user.first_name}! I see you are a ${chatMember.status} of this chat!`);
});
The second parameter, which is the chat id, is optional; if you don't provide it, ctx.chat.id
will be used instead.
Please notice that, if you don't provide a chat id and there's no chat
property inside the context (for example: on
inline query updates), this will throw an error.
The enableAggressiveStorage
config option will install middleware to cache chat members without depending on the
chat_member
event. For every update, the middleware checks if ctx.chat
and ctx.from
exist. If they both do, it
then proceeds to call ctx.chatMembers.getChatMember
to add the chat member information to the storage in case it
doesn't exist.
Please note that this means the storage will be called for every update, which may be a lot, depending on how many updates your bot receives. This also has the potential to impact the performance of your bot drastically. Only use this if you really know what you're doing and are ok with the risks and consequences.
FAQs
Chat member plugin for grammY
The npm package @grammyjs/chat-members receives a total of 488 weekly downloads. As such, @grammyjs/chat-members popularity was classified as not popular.
We found that @grammyjs/chat-members demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers 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
Opengrep forks Semgrep to preserve open source SAST in response to controversial licensing changes.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.