![MegaAPI Logo](https://img.shields.io/badge/MegaAPI-WhatsApp%20Automation-25D366?style=for-the-badge&logo=whatsapp&logoColor=white)

# 🚀 N8N Community Nodes - MegaAPI

![Version](https://img.shields.io/badge/version-1.1.2-blue?style=for-the-badge)
![License](https://img.shields.io/badge/license-MIT-green?style=for-the-badge)
![N8N](https://img.shields.io/badge/n8n-1.54.4+-orange?style=for-the-badge)

**Complete WhatsApp Business automation solution for n8n workflows.**

This community node package integrates **MegaAPI** (WhatsApp service) with **Chatwoot** for seamless customer support automation, providing custom nodes for n8n workflows that enable WhatsApp message handling, media management, group operations, and customer service integration.

---

## 🌟 **Features**

### **WhatsApp Operations**
- ✅ **Text Messages**: Send and receive text messages
- ✅ **Media Messages**: Send images, videos, documents, and audio files
- ✅ **Location Sharing**: Send location coordinates and live location
- ✅ **Link Previews**: Send messages with rich link previews
- ✅ **List Messages**: Interactive list messages for better UX

### **Group Management**
- ✅ **Group Operations**: Create, manage, and configure groups
- ✅ **Participant Management**: Add, remove, and manage group members
- ✅ **Group Messaging**: Send messages to groups with media support

### **Instance Management**
- ✅ **QR Code Generation**: Generate QR codes for WhatsApp Web connection
- ✅ **Pairing Codes**: Generate pairing codes for device linking
- ✅ **Status Monitoring**: Real-time instance status and health checks
- ✅ **Webhook Configuration**: Configure and manage webhooks

### **Chatwoot Integration**
- ✅ **Contact Synchronization**: Sync WhatsApp contacts with Chatwoot
- ✅ **Conversation Management**: Create and manage customer conversations
- ✅ **Message Routing**: Automatic message routing to Chatwoot agents
- ✅ **Webhook Processing**: Complete MegaAPI → Chatwoot automation

### **Advanced Features**
- ✅ **Message Forwarding**: Forward messages between contacts and groups
- ✅ **Message Quoting**: Reply to specific messages with context
- ✅ **Presence Updates**: Manage online/offline status and typing indicators
- ✅ **Media Download**: Download and process received media files

---

## 📦 **Installation**

### **NPM Installation**
```bash
npm install n8n-nodes-megaapi
```

### **N8N Community Package Installation**
1. Open your n8n instance
2. Go to **Settings** → **Community Nodes**
3. Enter package name: `n8n-nodes-megaapi`
4. Click **Install**

### **Manual Installation**
```bash
# Navigate to your n8n installation directory
cd ~/.n8n/nodes

# Clone or download the package
git clone https://github.com/megaapi/n8n-nodes-megaapi.git

# Install dependencies
npm install

# Build the package
npm run build
```

---

## 🔧 **Configuration**

### **MegaAPI Credentials**
1. Create a **MegaAPI Credentials** in n8n
2. Add your MegaAPI base URL and authentication token
3. Test the connection

### **Chatwoot Integration**
1. Create **Chatwoot MegaAPI Credentials** for integrated workflows
2. Configure both MegaAPI and Chatwoot API details
3. Set up account ID and inbox ID

### **Required Information**
- **MegaAPI Base URL**: Your MegaAPI instance URL
- **MegaAPI Token**: Authentication token from MegaAPI
- **Chatwoot URL**: Your Chatwoot instance URL (for integration)
- **Chatwoot Token**: API access token from Chatwoot (for integration)

---

## 🎯 **Use Cases**

### **Customer Support Automation**
- Route WhatsApp messages to Chatwoot agents automatically
- Create conversations and contacts from new WhatsApp interactions
- Handle media attachments in customer support workflows
- Maintain conversation history and context

### **Business Communication**
- Send bulk WhatsApp messages for marketing campaigns
- Automate order confirmations and shipping notifications
- Handle customer inquiries with intelligent routing
- Manage group communications for teams

### **E-commerce Integration**
- Send order confirmations via WhatsApp
- Provide customer support through messaging
- Automate product inquiries and responses
- Handle refunds and support requests

### **Team Collaboration**
- Create WhatsApp groups for project teams
- Automate status updates and notifications
- Share files and media with team members
- Manage participant access and permissions

---

## 📋 **Available Nodes**

### **Message Operations**
- **Send Text Message**: Send text messages to contacts
- **Send Media URL**: Send media files via URL
- **Send Media Base64**: Send media files via base64 encoding
- **Send Location**: Share location coordinates
- **Send Link Preview**: Send messages with rich previews
- **Send List Message**: Send interactive list messages
- **Forward Message**: Forward existing messages
- **Quote Message**: Reply to messages with context
- **Send Text Direct from Chatwoot**: Direct text messaging from Chatwoot data
- **Send Media Direct from Chatwoot**: Direct media messaging from Chatwoot data

### **Group Operations**
- **Get Groups**: List all available groups
- **Group Details**: Get detailed group information
- **Create Group**: Create new WhatsApp groups
- **Send Group Message**: Send messages to groups
- **Send Group Media**: Send media to groups
- **Add Participants**: Add members to groups
- **Remove Participants**: Remove members from groups
- **Leave Group**: Leave from groups

### **Instance Management**
- **Generate QR Code**: Get QR code for WhatsApp Web
- **Generate Pairing Code**: Get pairing code for devices
- **Instance Status**: Check connection status
- **Logout Instance**: Disconnect WhatsApp session
- **Restart Instance**: Restart WhatsApp connection

### **Webhook & Media**
- **Download Media**: Download received media files
- **Check WhatsApp**: Verify if number is on WhatsApp
- **Get Webhook Config**: Retrieve webhook configuration
- **Configure Webhook**: Set up webhook endpoints

### **Chat Operations**
- **Update Presence**: Manage online/typing status
- **Delete Message**: Delete sent messages
- **Delete Message From Me**: Delete messages from sender

### **Chatwoot Integration**
- **Process Webhook to Chatwoot**: Complete automation pipeline
- **Send Message to Chatwoot**: Send messages to Chatwoot conversations
- **Sync Contact**: Synchronize contacts between platforms
- **Create Conversation**: Create new Chatwoot conversations

---

## 🛠️ **Development**

### **Requirements**
- Node.js 20.15 or higher
- n8n 1.54.4 or higher
- TypeScript 5.8.2 or higher

### **Build Commands**
```bash
# Install dependencies
npm install

# Build the project
npm run build

# Development mode with watch
npm run dev

# Run linting
npm run lint

# Fix linting issues
npm run lintfix

# Format code
npm run format

# Prepare for publishing
npm run prepublishOnly
```

### **Project Structure**
```
n8n-nodes-megaapi/
├── 📁 nodes/MegaAPI/          # Main node implementation
│   ├── 📄 MegaApi.node.ts     # Node definition and routing
│   ├── 📁 execute/            # Operation implementations
│   │   ├── 📁 message/        # Message operations
│   │   ├── 📁 group/          # Group operations
│   │   ├── 📁 instance/       # Instance management
│   │   ├── 📁 webhook/        # Webhook operations
│   │   ├── 📁 chat/           # Chat operations
│   │   └── 📁 chatwoot/       # Chatwoot integration
│   └── 📁 properties/         # Node property definitions
├── 📁 credentials/            # Authentication configurations
├── 📄 package.json            # Package configuration
├── 📄 tsconfig.json          # TypeScript configuration
└── 📄 gulpfile.js            # Build configuration
```

---

## 📝 **License**

This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details.

---

## 🤝 **Contributing**

We welcome contributions! Please feel free to submit issues, feature requests, or pull requests.

### **Development Setup**
1. Fork the repository
2. Clone your fork: `git clone https://github.com/your-username/n8n-nodes-megaapi.git`
3. Install dependencies: `npm install`
4. Make your changes
5. Run tests: `npm run lint && npm run build`
6. Submit a pull request

---

## 📞 **Support**

- **Issues**: [GitHub Issues](https://github.com/megaapi/n8n-nodes-megaapi/issues)
- **Discussions**: [GitHub Discussions](https://github.com/megaapi/n8n-nodes-megaapi/discussions)
- **Email**: megaapi@github.com

---

## 🎉 **Changelog**

### **v1.1.2** - Current
- ✅ Added `syncContact` operation for Chatwoot integration
- ✅ Added `createConversation` operation for Chatwoot workflows
- ✅ Improved error handling and validation
- ✅ Enhanced TypeScript type definitions
- ✅ Updated build and deployment pipeline

### **v1.1.0**
- ✅ Added `processWebhookToChatwoot` for complete automation
- ✅ Enhanced Chatwoot integration capabilities
- ✅ Improved webhook processing

### **v1.0.9**
- ✅ Added `sendMessageToChatwoot` operation
- ✅ Enhanced Chatwoot API integration

### **v1.0.8**
- ✅ Added `sendTextFromChatwootDirect` operation
- ✅ Improved direct messaging capabilities

### **v1.0.7**
- ✅ Added `sendMediaFromChatwootDirect` operation
- ✅ Enhanced media handling for Chatwoot integration

---

**Made with ❤️ for the n8n community**