w-api-beauty-ia
v1.0.0
Published
WhatsApp API Client for W-API.app
Downloads
7
Maintainers
Readme
W-API Beauty IA
A comprehensive client library for the W-API WhatsApp API service.
Features
- Full support for all W-API endpoints
- Simplified client interface with short method names
- Built-in API server for local use
- Direct connection to W-API servers
- TypeScript support
Installation
npm install w-api-beauty-iaQuick Start
const wapi = require('w-api-beauty-ia');
// Create a client
const client = wapi.createClient({
instanceId: 'YOUR_INSTANCE_ID',
apiToken: 'YOUR_API_TOKEN',
directMode: true // send requests directly to W-API servers
});
// Using the client
async function sendMessage() {
try {
// Check if connected
const status = await client.status();
console.log('Connection status:', status);
// Send a message
const result = await client.sendText('5512345678901', 'Hello from W-API Client!');
console.log('Message sent:', result);
} catch (error) {
console.error('Error:', error);
}
}
sendMessage();Using Short Variable Names
You can use the wa object for shorter syntax:
const { wa, createClient } = require('w-api-beauty-ia');
const client = createClient({
instanceId: 'YOUR_INSTANCE_ID',
apiToken: 'YOUR_API_TOKEN',
directMode: true
});
// Send a text message
wa.text(client, '5512345678901', 'Hello!');
// Send an image
wa.image(client, '5512345678901', 'https://example.com/image.jpg', 'Check this out!');
// Create a group
wa.createGroup(client, 'My Group', ['5512345678901', '5598765432101']);Starting the API Server
You can start the built-in API server to use in your local network:
const { startServer } = require('w-api-beauty-ia');
// Start the server
startServer({
port: 3000,
instanceId: 'YOUR_INSTANCE_ID',
apiToken: 'YOUR_API_TOKEN'
}).then(() => {
console.log('Server started successfully');
}).catch(error => {
console.error('Failed to start server:', error);
});Then you can create a client that uses the local server:
const { createClient } = require('w-api-beauty-ia');
const client = createClient({
baseUrl: 'http://localhost:3000',
directMode: false // use local server
});
// Now you can use the client methods
client.sendText('5512345678901', 'Hello!');Available Methods
Instance Methods
status()- Get connection statusqr()- Get QR code for connectionconnect()- Connect to WhatsAppdisconnect()- Disconnect from WhatsApprestart()- Restart the instancelogout()- Logout from WhatsApp
Message Methods
sendText(phone, message, options)- Send text messagesendImage(phone, image, caption, options)- Send imagesendDoc(phone, document, filename, caption, options)- Send documentsendAudio(phone, audio, options)- Send audiosendVideo(phone, video, caption, options)- Send videosendLocation(phone, latitude, longitude, name, address, options)- Send locationsendContact(phone, contact, options)- Send contactsendButtons(phone, message, buttons, options)- Send button messagesendList(phone, message, list, options)- Send list messagereply(messageId, message, options)- Reply to a message
Contacts Methods
getContact(phone)- Get contact infogetContacts()- Get all contactscheckContact(phone)- Check if number exists on WhatsAppsaveContact(phone, name)- Save a contactgetAbout(phone)- Get contact about/status
Chats Methods
getChat(phone)- Get chat infogetChats()- Get all chatsarchiveChat(phone)- Archive a chatunarchiveChat(phone)- Unarchive a chatclearChat(phone)- Clear chat historydeleteChat(phone)- Delete a chatpinChat(phone)- Pin a chatunpinChat(phone)- Unpin a chat
Groups Methods
createGroup(name, participants)- Create a groupgetGroup(groupId)- Get group infoupdateGroupParticipants(groupId, participants, action)- Update group participantsupdateGroupSettings(groupId, settings)- Update group settingsleaveGroup(groupId)- Leave a groupgetGroupInviteCode(groupId)- Get group invite code
License
MIT
