-
Notifications
You must be signed in to change notification settings - Fork 4
Chat Manager
Abdi Urgessa edited this page Feb 18, 2024
·
4 revisions
The ChatManager
class offers a comprehensive suite of methods to manage various aspects of a chat within the Telegram bot framework. This class facilitates operations like member management, chat customization, and information retrieval.
Below are additional examples showcasing the use of various methods within the ChatManager
class.
Ban and Unban Chat Member:
// Ban a chat member
bot.on("message", (ctx) => {
ctx.banChatMember({chatId: ctx.chat().id, userId: userToBanId});
});
// Unban a chat member
bot.on("command", (ctx) => {
ctx.unbanChatMember({chatId: ctx.chat().id, userId: userToUnbanId});
});
Restrict and Promote Chat Member:
// Restrict a chat member
bot.on("message", (ctx) => {
ctx.restrictChatMember({
chatId: ctx.chat().id,
userId: userToRestrictId,
permissions: {
can_send_messages: false,
can_send_audios: false,
can_send_polls: false,
can_send_documents: false,
can_send_photos: false,
can_send_videos: false,
can_send_video_notes: false,
can_pin_messages: false
}
});
});
// Promote a chat member to admin
bot.on("message", (ctx) => {
ctx.promoteChatMember({
chatId: ctx.chat().id,
userId: userToPromoteId,
can_change_info: true,
can_post_messages: true,
can_edit_messages: true,
can_delete_messages: true,
can_invite_users: true,
can_restrict_members: true,
can_pin_messages: true,
can_promote_members: false,
can_manage_chat: true,
can_manage_video_chats: true
});
});
Set Chat Permissions:
// Set new permissions for the chat
bot.on("message", (ctx) => {
ctx.setChatPermissions({
chatId: ctx.chat().id,
permissions: {
can_send_messages: false,
can_send_audios: false,
can_send_polls: false,
can_send_documents: false,
can_send_photos: false,
can_send_videos: false,
can_send_video_notes: false,
can_pin_messages: false
}
});
});
Manage Chat Invite Links:
// Create a new chat invite link
bot.on("message", (ctx) => {
ctx.createChatInviteLink({
chatId: ctx.chat().id,
name: "Special Event",
expireDate: expirationTimestamp,
memberLimit: 100
});
});
// Revoke an existing chat invite link
bot.on("message", (ctx) => {
ctx.revokeChatInviteLink({
chatId: ctx.chat().id,
inviteLink: "https://t.me/joinchat/AAAAAExxxxxx"
});
});
Pin and Unpin Chat Messages:
// Pin a chat message
bot.on("message", (ctx) => {
ctx.pinChatMessage({
chatId: ctx.chat().id,
messageId: messageIdToPin
});
});
// Unpin all chat messages
bot.on("message", (ctx) => {
ctx.unpinAllChatMessages({chatId: ctx.chat().id});
});
- Telesun
- Getting Started - Apps script
- Getting Started with the Telesun Ready Template
- Import Telesun
- Telesun-Handlers
- Context Object
- Next Middleware
- Stages
- Manager Classes:
- Mail:
- Google Spreadsheet:
- Best Practice:
- Getting Updates:
- Example Types:
- Example Bots: