Node.js wrapper for the official Telegram Bot API with polling and webhook support, comprehensive message handling, media operations, and bot management features.
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Complete chat administration including member management, permissions, roles, and chat settings with support for groups, supergroups, and channels.
Methods for retrieving information about chats, members, and administrators.
/**
* Get chat information
* @param {number|string} chatId - Chat identifier
* @param {object} [options] - Additional options
* @returns {Promise<Chat>}
*/
getChat(chatId, options): Promise<Chat>;
/**
* Get list of chat administrators
* @param {number|string} chatId - Chat identifier
* @param {object} [options] - Additional options
* @returns {Promise<ChatMember[]>}
*/
getChatAdministrators(chatId, options): Promise<ChatMember[]>;
/**
* Get number of chat members
* @param {number|string} chatId - Chat identifier
* @param {object} [options] - Additional options
* @returns {Promise<number>}
*/
getChatMemberCount(chatId, options): Promise<number>;
/**
* Get chat member information
* @param {number|string} chatId - Chat identifier
* @param {number} userId - User identifier
* @param {object} [options] - Additional options
* @returns {Promise<ChatMember>}
*/
getChatMember(chatId, userId, options): Promise<ChatMember>;Usage Example:
// Get detailed chat information
const chat = await bot.getChat(chatId);
console.log(`Chat: ${chat.title || chat.first_name}`);
console.log(`Type: ${chat.type}`);
console.log(`Members: ${chat.member_count || 'N/A'}`);
if (chat.description) {
console.log(`Description: ${chat.description}`);
}
// Get chat administrators
const admins = await bot.getChatAdministrators(chatId);
console.log(`Chat has ${admins.length} administrators:`);
admins.forEach(admin => {
const user = admin.user;
const status = admin.status;
console.log(`- ${user.first_name} (${user.username || user.id}) - ${status}`);
if (admin.custom_title) {
console.log(` Custom title: ${admin.custom_title}`);
}
});
// Get member count
const memberCount = await bot.getChatMemberCount(chatId);
console.log(`Total members: ${memberCount}`);
// Check specific user status
const member = await bot.getChatMember(chatId, userId);
console.log(`User status: ${member.status}`);
if (member.status === 'restricted') {
console.log('User restrictions:', member.permissions);
}Methods for managing chat members including banning, unbanning, and permission management.
/**
* Ban user from chat
* @param {number|string} chatId - Chat identifier
* @param {number} userId - User identifier
* @param {object} [options] - Ban options
* @returns {Promise<boolean>}
*/
banChatMember(chatId, userId, options): Promise<boolean>;
/**
* Unban user from chat
* @param {number|string} chatId - Chat identifier
* @param {number} userId - User identifier
* @param {object} [options] - Unban options
* @returns {Promise<boolean>}
*/
unbanChatMember(chatId, userId, options): Promise<boolean>;
/**
* Restrict chat member permissions
* @param {number|string} chatId - Chat identifier
* @param {number} userId - User identifier
* @param {object} permissions - Chat permissions
* @param {object} [options] - Additional options
* @returns {Promise<boolean>}
*/
restrictChatMember(chatId, userId, permissions, options): Promise<boolean>;
/**
* Promote/demote chat member to administrator
* @param {number|string} chatId - Chat identifier
* @param {number} userId - User identifier
* @param {object} [options] - Promotion options
* @returns {Promise<boolean>}
*/
promoteChatMember(chatId, userId, options): Promise<boolean>;
/**
* Set custom title for administrator
* @param {number|string} chatId - Chat identifier
* @param {number} userId - User identifier
* @param {string} customTitle - Custom title (0-16 characters)
* @param {object} [options] - Additional options
* @returns {Promise<boolean>}
*/
setChatAdministratorCustomTitle(chatId, userId, customTitle, options): Promise<boolean>;Usage Example:
// Ban user with time limit
await bot.banChatMember(chatId, userId, {
until_date: Math.floor(Date.now() / 1000) + 3600, // 1 hour ban
revoke_messages: true // Delete messages from user
});
// Permanent ban
await bot.banChatMember(chatId, userId, {
revoke_messages: false
});
// Unban user
await bot.unbanChatMember(chatId, userId, {
only_if_banned: true
});
// Restrict user permissions
await bot.restrictChatMember(chatId, userId, {
can_send_messages: false,
can_send_audios: false,
can_send_documents: false,
can_send_photos: false,
can_send_videos: false,
can_send_video_notes: false,
can_send_voice_notes: false,
can_send_polls: false,
can_send_other_messages: false,
can_add_web_page_previews: false,
can_change_info: false,
can_invite_users: false,
can_pin_messages: false,
can_manage_topics: false
}, {
until_date: Math.floor(Date.now() / 1000) + 1800 // 30 minutes
});
// Promote user to administrator
await bot.promoteChatMember(chatId, userId, {
is_anonymous: false,
can_manage_chat: false,
can_delete_messages: true,
can_manage_video_chats: false,
can_restrict_members: true,
can_promote_members: false,
can_change_info: false,
can_invite_users: true,
can_post_messages: false, // for channels
can_edit_messages: false, // for channels
can_pin_messages: true,
can_manage_topics: false // for forum supergroups
});
// Set custom administrator title
await bot.setChatAdministratorCustomTitle(chatId, userId, '🛡️ Moderator');Methods for managing channel chats in supergroups.
/**
* Ban channel chat in supergroup
* @param {number|string} chatId - Chat identifier
* @param {number} senderChatId - Sender chat identifier
* @param {object} [options] - Additional options
* @returns {Promise<boolean>}
*/
banChatSenderChat(chatId, senderChatId, options): Promise<boolean>;
/**
* Unban channel chat in supergroup
* @param {number|string} chatId - Chat identifier
* @param {number} senderChatId - Sender chat identifier
* @param {object} [options] - Additional options
* @returns {Promise<boolean>}
*/
unbanChatSenderChat(chatId, senderChatId, options): Promise<boolean>;Usage Example:
// Ban a channel from posting in supergroup
await bot.banChatSenderChat(supergroupId, channelId);
// Unban a channel
await bot.unbanChatSenderChat(supergroupId, channelId);Methods for setting default chat permissions.
/**
* Set default chat permissions for all members
* @param {number|string} chatId - Chat identifier
* @param {object} chatPermissions - Default permissions
* @param {object} [options] - Additional options
* @returns {Promise<boolean>}
*/
setChatPermissions(chatId, chatPermissions, options): Promise<boolean>;Usage Example:
// Set restrictive default permissions
await bot.setChatPermissions(chatId, {
can_send_messages: true,
can_send_audios: false,
can_send_documents: false,
can_send_photos: true,
can_send_videos: true,
can_send_video_notes: false,
can_send_voice_notes: false,
can_send_polls: false,
can_send_other_messages: false,
can_add_web_page_previews: false,
can_change_info: false,
can_invite_users: false,
can_pin_messages: false,
can_manage_topics: false
}, {
use_independent_chat_permissions: true
});Methods for managing chat appearance and configuration.
/**
* Set chat photo
* @param {number|string} chatId - Chat identifier
* @param {string|Buffer|stream.Readable} photo - Photo to set
* @param {object} [options] - Additional options
* @param {object} [fileOptions] - File upload options
* @returns {Promise<boolean>}
*/
setChatPhoto(chatId, photo, options, fileOptions): Promise<boolean>;
/**
* Delete chat photo
* @param {number|string} chatId - Chat identifier
* @param {object} [options] - Additional options
* @returns {Promise<boolean>}
*/
deleteChatPhoto(chatId, options): Promise<boolean>;
/**
* Set chat title
* @param {number|string} chatId - Chat identifier
* @param {string} title - New chat title (1-128 characters)
* @param {object} [options] - Additional options
* @returns {Promise<boolean>}
*/
setChatTitle(chatId, title, options): Promise<boolean>;
/**
* Set chat description
* @param {number|string} chatId - Chat identifier
* @param {string} description - New description (0-255 characters)
* @param {object} [options] - Additional options
* @returns {Promise<boolean>}
*/
setChatDescription(chatId, description, options): Promise<boolean>;
/**
* Set chat sticker set
* @param {number|string} chatId - Chat identifier
* @param {string} stickerSetName - Sticker set name
* @param {object} [options] - Additional options
* @returns {Promise<boolean>}
*/
setChatStickerSet(chatId, stickerSetName, options): Promise<boolean>;
/**
* Delete chat sticker set
* @param {number|string} chatId - Chat identifier
* @param {object} [options] - Additional options
* @returns {Promise<boolean>}
*/
deleteChatStickerSet(chatId, options): Promise<boolean>;Usage Example:
// Set chat photo
await bot.setChatPhoto(chatId, './group-photo.jpg');
// Set chat title
await bot.setChatTitle(chatId, 'New Group Title');
// Set chat description
await bot.setChatDescription(chatId, 'This is the new group description with rules and information.');
// Set sticker set for supergroup
await bot.setChatStickerSet(chatId, 'animals_by_bot');
// Remove sticker set
await bot.deleteChatStickerSet(chatId);
// Delete chat photo
await bot.deleteChatPhoto(chatId);Methods for managing pinned messages in chats.
/**
* Pin chat message
* @param {number|string} chatId - Chat identifier
* @param {number} messageId - Message identifier
* @param {object} [options] - Pin options
* @returns {Promise<boolean>}
*/
pinChatMessage(chatId, messageId, options): Promise<boolean>;
/**
* Unpin specific chat message
* @param {number|string} chatId - Chat identifier
* @param {object} [options] - Unpin options
* @returns {Promise<boolean>}
*/
unpinChatMessage(chatId, options): Promise<boolean>;
/**
* Unpin all chat messages
* @param {number|string} chatId - Chat identifier
* @param {object} [options] - Additional options
* @returns {Promise<boolean>}
*/
unpinAllChatMessages(chatId, options): Promise<boolean>;Usage Example:
// Pin message without notification
await bot.pinChatMessage(chatId, messageId, {
disable_notification: true
});
// Pin message with notification
await bot.pinChatMessage(chatId, messageId, {
disable_notification: false
});
// Unpin specific message
await bot.unpinChatMessage(chatId, {
message_id: messageId
});
// Unpin all messages
await bot.unpinAllChatMessages(chatId);Methods for performing various chat-related actions.
/**
* Leave chat
* @param {number|string} chatId - Chat identifier
* @param {object} [options] - Additional options
* @returns {Promise<boolean>}
*/
leaveChat(chatId, options): Promise<boolean>;Usage Example:
// Leave a group or channel
const left = await bot.leaveChat(chatId);
if (left) {
console.log('Successfully left the chat');
}Methods for creating and managing chat invite links.
/**
* Generate new primary invite link
* @param {number|string} chatId - Chat identifier
* @param {object} [options] - Additional options
* @returns {Promise<string>}
*/
exportChatInviteLink(chatId, options): Promise<string>;
/**
* Create additional invite link
* @param {number|string} chatId - Chat identifier
* @param {object} [options] - Link options
* @returns {Promise<ChatInviteLink>}
*/
createChatInviteLink(chatId, options): Promise<ChatInviteLink>;
/**
* Edit invite link
* @param {number|string} chatId - Chat identifier
* @param {string} inviteLink - Invite link to edit
* @param {object} [options] - New link options
* @returns {Promise<ChatInviteLink>}
*/
editChatInviteLink(chatId, inviteLink, options): Promise<ChatInviteLink>;
/**
* Revoke invite link
* @param {number|string} chatId - Chat identifier
* @param {string} inviteLink - Invite link to revoke
* @param {object} [options] - Additional options
* @returns {Promise<ChatInviteLink>}
*/
revokeChatInviteLink(chatId, inviteLink, options): Promise<ChatInviteLink>;Usage Example:
// Generate new primary invite link
const primaryLink = await bot.exportChatInviteLink(chatId);
console.log(`Primary invite link: ${primaryLink}`);
// Create limited-use invite link
const limitedLink = await bot.createChatInviteLink(chatId, {
name: 'Limited Link',
expire_date: Math.floor(Date.now() / 1000) + 86400, // Expires in 24 hours
member_limit: 10, // Max 10 users can join
creates_join_request: false
});
console.log(`Limited link: ${limitedLink.invite_link}`);
// Create approval-required link
const approvalLink = await bot.createChatInviteLink(chatId, {
name: 'Approval Required',
creates_join_request: true
});
// Edit existing link
const editedLink = await bot.editChatInviteLink(chatId, limitedLink.invite_link, {
name: 'Updated Limited Link',
member_limit: 5
});
// Revoke link
const revokedLink = await bot.revokeChatInviteLink(chatId, limitedLink.invite_link);
console.log(`Link revoked: ${revokedLink.is_revoked}`);Methods for handling chat join requests.
/**
* Approve chat join request
* @param {number|string} chatId - Chat identifier
* @param {number} userId - User identifier
* @param {object} [options] - Additional options
* @returns {Promise<boolean>}
*/
approveChatJoinRequest(chatId, userId, options): Promise<boolean>;
/**
* Decline chat join request
* @param {number|string} chatId - Chat identifier
* @param {number} userId - User identifier
* @param {object} [options] - Additional options
* @returns {Promise<boolean>}
*/
declineChatJoinRequest(chatId, userId, options): Promise<boolean>;Usage Example:
// Handle join requests
bot.on('chat_join_request', async (joinRequest) => {
const { chat, from } = joinRequest;
console.log(`Join request from ${from.first_name} for chat ${chat.title}`);
// Auto-approve if user has specific criteria
if (from.username && from.username.includes('verified')) {
await bot.approveChatJoinRequest(chat.id, from.id);
console.log(`Approved join request for ${from.first_name}`);
} else {
// For this example, decline others
await bot.declineChatJoinRequest(chat.id, from.id);
console.log(`Declined join request for ${from.first_name}`);
}
});interface Chat {
id: number;
type: 'private' | 'group' | 'supergroup' | 'channel';
title?: string;
username?: string;
first_name?: string;
last_name?: string;
is_forum?: boolean;
photo?: ChatPhoto;
active_usernames?: string[];
available_reactions?: ReactionType[];
accent_color_id?: number;
background_custom_emoji_id?: string;
profile_accent_color_id?: number;
profile_background_custom_emoji_id?: string;
emoji_status_custom_emoji_id?: string;
emoji_status_expiration_date?: number;
bio?: string;
has_private_forwards?: boolean;
has_restricted_voice_and_video_messages?: boolean;
join_to_send_messages?: boolean;
join_by_request?: boolean;
description?: string;
invite_link?: string;
pinned_message?: Message;
permissions?: ChatPermissions;
slow_mode_delay?: number;
unrestrict_boost_count?: number;
message_auto_delete_time?: number;
has_aggressive_anti_spam_enabled?: boolean;
has_hidden_members?: boolean;
has_protected_content?: boolean;
has_visible_history?: boolean;
sticker_set_name?: string;
can_set_sticker_set?: boolean;
custom_emoji_sticker_set_name?: string;
linked_chat_id?: number;
location?: ChatLocation;
}
interface ChatMember {
status: 'creator' | 'administrator' | 'member' | 'restricted' | 'left' | 'kicked';
user: User;
is_anonymous?: boolean;
custom_title?: string;
until_date?: number;
}
interface ChatMemberOwner extends ChatMember {
status: 'creator';
is_anonymous: boolean;
custom_title?: string;
}
interface ChatMemberAdministrator extends ChatMember {
status: 'administrator';
can_be_edited: boolean;
can_manage_chat: boolean;
can_delete_messages: boolean;
can_manage_video_chats: boolean;
can_restrict_members: boolean;
can_promote_members: boolean;
can_change_info: boolean;
can_invite_users: boolean;
can_post_messages?: boolean;
can_edit_messages?: boolean;
can_pin_messages?: boolean;
can_post_stories?: boolean;
can_edit_stories?: boolean;
can_delete_stories?: boolean;
can_manage_topics?: boolean;
custom_title?: string;
is_anonymous: boolean;
}
interface ChatMemberMember extends ChatMember {
status: 'member';
}
interface ChatMemberRestricted extends ChatMember {
status: 'restricted';
is_member: boolean;
can_send_messages: boolean;
can_send_audios: boolean;
can_send_documents: boolean;
can_send_photos: boolean;
can_send_videos: boolean;
can_send_video_notes: boolean;
can_send_voice_notes: boolean;
can_send_polls: boolean;
can_send_other_messages: boolean;
can_add_web_page_previews: boolean;
can_change_info: boolean;
can_invite_users: boolean;
can_pin_messages: boolean;
can_manage_topics: boolean;
until_date: number;
}
interface ChatMemberLeft extends ChatMember {
status: 'left';
}
interface ChatMemberBanned extends ChatMember {
status: 'kicked';
until_date: number;
}
interface ChatPermissions {
can_send_messages?: boolean;
can_send_audios?: boolean;
can_send_documents?: boolean;
can_send_photos?: boolean;
can_send_videos?: boolean;
can_send_video_notes?: boolean;
can_send_voice_notes?: boolean;
can_send_polls?: boolean;
can_send_other_messages?: boolean;
can_add_web_page_previews?: boolean;
can_change_info?: boolean;
can_invite_users?: boolean;
can_pin_messages?: boolean;
can_manage_topics?: boolean;
}
interface ChatInviteLink {
invite_link: string;
creator: User;
creates_join_request: boolean;
is_primary: boolean;
is_revoked: boolean;
name?: string;
expire_date?: number;
member_limit?: number;
pending_join_request_count?: number;
}
interface ChatJoinRequest {
chat: Chat;
from: User;
user_chat_id: number;
date: number;
bio?: string;
invite_link?: ChatInviteLink;
}