kufuli-whatsapp
Version:
Official Kufuli whatsapp API package
162 lines (122 loc) • 3.25 kB
Markdown
# Kufuli WhatsApp JS
Official JavaScript/TypeScript package for interacting with the Kufuli WhatsApp API. This package provides a simple and intuitive interface for sending messages, managing contacts, handling sessions, and working with stories on WhatsApp.
## Installation
```bash
npm install kufuli-whatsapp
# or
yarn add kufuli-whatsapp
```
## Quick Start
```typescript
import { KufuliWhatsappApi } from "kufuli-whatsapp";
// Initialize the API client
const whatsapp = new KufuliWhatsappApi(
"your-api-key",
"your-api-secret",
"production" // or 'test'
);
// Send a text message
await whatsapp.message.sendText({
to: "1234567890",
text: "Hello from Kufuli WhatsApp!",
});
// Send a media message
await whatsapp.message.sendMedia({
to: "1234567890",
mediaUrl: "https://example.com/image.jpg",
caption: "Check out this image!",
});
```
## Features
- 📱 Send text, media, and template messages
- 👥 Contact management
- 🔐 Session handling
- 📸 Story management
- 🎨 Rich text formatting with different font types
- 🔄 Environment switching (production/sandbox)
## API Reference
### Message API
```typescript
// Send text message
whatsapp.message.sendText({
to: string,
text: string,
fontType: FontType,
});
// Send media message
whatsapp.message.sendMedia({
to: string,
mediaUrl: string,
caption: string,
});
// Send template message
whatsapp.message.sendTemplate({
to: string,
templateName: string,
components: Array<{
type: string;
parameters: Array<{
type: string;
text: string;
}>;
}>,
});
```
### Contact API
```typescript
// Get contact information
whatsapp.contact.get(phoneNumber: string);
// Update contact information
whatsapp.contact.update(phoneNumber: string, data: ContactData);
```
### Session API
```typescript
// Get session status
whatsapp.session.getStatus();
// Create new session
whatsapp.session.create();
// Delete session
whatsapp.session.delete();
```
### Story API
```typescript
// Get stories
whatsapp.story.get();
// Create story
whatsapp.story.create(data: StoryData);
```
## Font Types
The package supports different font types for text messages:
```typescript
whatsapp.FontType = {
SANS_SERIF: "sans-serif",
SERIF: "serif",
MONOSPACE: "monospace",
};
```
## Environment Types
```typescript
type environmentType = "production" | "sandbox";
```
## Error Handling
The package uses Axios for HTTP requests and throws appropriate errors when API calls fail. Always wrap API calls in try-catch blocks:
```typescript
try {
await whatsapp.message.sendText({
to: "1234567890",
text: "Hello!",
});
} catch (error) {
console.error("Failed to send message:", error);
}
```
## Contributing
1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
## Author
aderibigbeganiu <aderibigbeganiu@gmail.com>