hiwlerby
v1.0.0
Published
Hiwlerby is a robust and easy-to-use TypeScript library designed to simplify WhatsApp group administration tasks using the Baileys library. It provides a high-level API that abstracts away the complexities of Baileys, offering comprehensive commands for m
Readme
Hiwlerby: Advanced Baileys Wrapper for WhatsApp Group Administration
Introduction
Hiwlerby is a robust and easy-to-use TypeScript library designed to simplify WhatsApp group administration tasks using the Baileys library. It provides a high-level API that abstracts away the complexities of Baileys, offering comprehensive commands for managing groups and participants with enhanced type safety and developer experience.
Features
- Simplified Baileys Integration: Connects to WhatsApp via Baileys with minimal setup.
- Comprehensive Group Management: Full suite of commands for creating, modifying, and querying groups.
- Participant Administration: Easily add, remove, promote, and demote group participants.
- Type-Safe Development: Built with TypeScript for improved code quality and maintainability.
- Robust Error Handling: Provides clear and actionable error messages for failed operations.
Installation
To install Hiwlerby in your project, use npm:
npm install hiwlerbyPrerequisites:
- Node.js version 17 or higher.
Usage
1. Initialize the Hiwler Client
First, import HiwlerClient and create an instance. You need to provide a sessionName which will be used to store authentication credentials.
import { HiwlerClient } from 'hiwlerby';
async function main() {
const client = new HiwlerClient({
sessionName: 'my-whatsapp-session' // A unique name for your session
});
await client.connect();
console.log('Hiwler client connected to WhatsApp!');
// Your group administration logic goes here
// Disconnect when done (optional, client will try to reconnect on its own)
// await client.disconnect();
}
main().catch(err => console.error('Error:', err));2. Group Administration Commands
The HiwlerClient exposes a groupManager property, which contains all the group administration functionalities.
createGroup(name: string, participants: string[]): Promise<GroupAdminCommandResult>
Creates a new WhatsApp group with the specified name and initial participants.
// Example: Create a new group
const newGroup = await client.groupManager?.createGroup('My Awesome Group', ['[email protected]', '[email protected]']);
if (newGroup?.success) {
console.log('Group created:', newGroup.data);
} else {
console.error('Failed to create group:', newGroup?.message);
}addParticipants(groupId: string, participants: string[]): Promise<GroupAdminCommandResult>
Adds participants to an existing group.
// Example: Add participants to a group
const addResult = await client.groupManager?.addParticipants('[email protected]', ['[email protected]']);
if (addResult?.success) {
console.log('Participants added:', addResult.data);
} else {
console.error('Failed to add participants:', addResult?.message);
}removeParticipants(groupId: string, participants: string[]): Promise<GroupAdminCommandResult>
Removes participants from an existing group.
// Example: Remove participants from a group
const removeResult = await client.groupManager?.removeParticipants('[email protected]', ['[email protected]']);
if (removeResult?.success) {
console.log('Participants removed:', removeResult.data);
} else {
console.error('Failed to remove participants:', removeResult?.message);
}promoteParticipants(groupId: string, participants: string[]): Promise<GroupAdminCommandResult>
Promotes participants to group administrators.
// Example: Promote participants to admin
const promoteResult = await client.groupManager?.promoteParticipants('[email protected]', ['[email protected]']);
if (promoteResult?.success) {
console.log('Participants promoted:', promoteResult.data);
} else {
console.error('Failed to promote participants:', promoteResult?.message);
}demoteParticipants(groupId: string, participants: string[]): Promise<GroupAdminCommandResult>
Demotes participants from group administrators to regular members.
// Example: Demote participants from admin
const demoteResult = await client.groupManager?.demoteParticipants('[email protected]', ['[email protected]']);
if (demoteResult?.success) {
console.log('Participants demoted:', demoteResult.data);
} else {
console.error('Failed to demote participants:', demoteResult?.message);
}updateGroupSubject(groupId: string, subject: string): Promise<GroupAdminCommandResult>
Changes the subject (name) of a group.
// Example: Update group subject
const subjectUpdateResult = await client.groupManager?.updateGroupSubject('[email protected]', 'New Group Subject');
if (subjectUpdateResult?.success) {
console.log('Group subject updated.');
} else {
console.error('Failed to update group subject:', subjectUpdateResult?.message);
}updateGroupDescription(groupId: string, description: string): Promise<GroupAdminCommandResult>
Changes the description of a group.
// Example: Update group description
const descUpdateResult = await client.groupManager?.updateGroupDescription('[email protected]', 'This is the new description for the group.');
if (descUpdateResult?.success) {
console.log('Group description updated.');
} else {
console.error('Failed to update group description:', descUpdateResult?.message);
}getGroupMetadata(groupId: string): Promise<GroupAdminCommandResult>
Retrieves the metadata for a specific group.
// Example: Get group metadata
const metadataResult = await client.groupManager?.getGroupMetadata('[email protected]');
if (metadataResult?.success) {
console.log('Group metadata:', metadataResult.data);
} else {
console.error('Failed to get group metadata:', metadataResult?.message);
}getGroupParticipants(groupId: string): Promise<GroupAdminCommandResult>
Retrieves the list of participants for a specific group.
// Example: Get group participants
const participantsResult = await client.groupManager?.getGroupParticipants('[email protected]');
if (participantsResult?.success) {
console.log('Group participants:', participantsResult.data);
} else {
console.error('Failed to get group participants:', participantsResult?.message);
}getGroupInviteCode(groupId: string): Promise<GroupAdminCommandResult>
Retrieves the invite code for a specific group.
// Example: Get group invite code
const inviteCodeResult = await client.groupManager?.getGroupInviteCode('[email protected]');
if (inviteCodeResult?.success) {
console.log('Group invite code:', inviteCodeResult.data);
} else {
console.error('Failed to get group invite code:', inviteCodeResult?.message);
}revokeGroupInviteCode(groupId: string): Promise<GroupAdminCommandResult>
Revokes the current invite code for a group and generates a new one.
// Example: Revoke group invite code
const revokeInviteResult = await client.groupManager?.revokeGroupInviteCode('[email protected]');
if (revokeInviteResult?.success) {
console.log('New group invite code:', revokeInviteResult.data);
} else {
console.error('Failed to revoke group invite code:', revokeInviteResult?.message);
}Contributing
Contributions are welcome! Please feel free to open issues or submit pull requests.
License
This project is licensed under the ISC License. See the LICENSE file for details.
