# n8n-nodes-nowely-y-test

Integration node for [Green API](https://green-api.com/) in [n8n](https://n8n.io).  
This community node allows automation of WhatsApp, MAX, Telegram and WABA interactions using Green API — including messaging, file transfer, contacts, groups, statuses, and instance management.

---

## 📖 Overview

The **GREEN-API node** covers four messengers behind one credential — **WhatsApp**, **MAX**, **Telegram** and **WABA** — letting you send messages, manage chats and groups, and retrieve account information. Green API routes every messenger through the same REST contract, so the **Messenger** field only filters which categories and operations are offered.

---

## Installation
### Install community node
Go to `Settings` → `Community Nodes` → `Install`, then enter `n8n-nodes-nowely-y-test` — the npm package name this repository publishes.

## Authentication

To use this node, you need to have an instance and token from [Green-API](https://green-api.com/en) platform and WhatsApp account:

- Sign up at [Green-API](https://green-api.com/en)
- Create an instance
- Get the **Instance ID** (`idInstance`) and the **API Token Instance** (`apiTokenInstance`)
- Authorize the instance in the [Console](https://console.green-api.com/instanceList)

Enter these values in the **Green-API instance** credential when configuring the node.

The credential also has an optional **API URL** field. Leave the default `https://api.green-api.com` unless the console shows a dedicated host for your instance (for example `https://7105.api.greenapi.com`) — in that case paste that host instead.

## 🧩 Features

Pick the messenger in the **Messenger** field, then the **Resource**. Only the operations Green API documents for that messenger are offered.

The tables below list `operation` values — what goes into the node's `operation` parameter. The editor shows their Title Case labels (`sendFileByUrl` is **Send File by URL**).

### WhatsApp

| Resource | Operations |
|---|---|
| **Account** | getSettings, getStateInstance, getWaSettings, logout, reboot, setSettings |
| **Contact** | addContact, deleteContact, editContact |
| **Group** | addGroupParticipant, createGroup, getGroupData, leaveGroup, removeAdmin, removeGroupParticipant, setGroupAdmin, updateGroupName |
| **Journal** | getChatHistory, getMessage, lastIncomingCalls, lastIncomingMessages, lastOutgoingCalls, lastOutgoingMessages |
| **Queue** | clearMessagesQueue, clearWebhooksQueue, getMessagesCount, getWebhooksCount, showMessagesQueue |
| **Receiving** | downloadFile |
| **Sending** | forwardMessages, sendContact, sendFileByUrl, sendInteractiveButtons, sendInteractiveButtonsReply, sendLocation, sendMessage, sendPoll |
| **Service** | archiveChat, checkWhatsapp, deleteMessage, editMessage, getAvatar, getContactInfo, getContacts, readChat, setDisappearingChat, unarchiveChat |
| **Status** | deleteStatus, getIncomingStatuses, getOutgoingStatuses, getStatusStatistic, sendMediaStatus, sendTextStatus, sendVoiceStatus |

### MAX

| Resource | Operations |
|---|---|
| **Account** | getAccountSettings, getSettings, getStateInstance, logout, reboot, setSettings |
| **Cloud Password** | deleteAuthorizationPassword, editAuthorizationPassword, getAuthorizationPasswordStatus, setAuthorizationPassword |
| **Contact** | addContact, deleteContact, editContact |
| **Group** | addGroupParticipant, createGroup, getGroupData, leaveGroup, removeAdmin, removeGroupParticipant, setGroupAdmin, updateGroupName |
| **Journal** | getChatHistory, getMessage, lastIncomingMessages, lastOutgoingMessages |
| **Queue** | clearMessagesQueue, clearWebhooksQueue, getMessagesCount, getWebhooksCount, showMessagesQueue |
| **Receiving** | downloadFile |
| **Sending** | forwardMessages, sendContact, sendFileByUrl, sendLocation, sendMessage, sendPoll |
| **Service** | checkAccount, deleteMessage, editMessage, getAllowedReactions, getAvatar, getChats, getContactInfo, getContacts, readChat, sendReaction, sendTyping |

### Telegram

| Resource | Operations |
|---|---|
| **Account** | getAccountSettings, getSettings, getStateInstance, logout, reboot, setSettings |
| **Group** | addGroupParticipant, createGroup, getGroupData, leaveGroup, removeAdmin, removeGroupParticipant, setGroupAdmin, updateGroupName |
| **Journal** | getChatHistory, getMessage, lastIncomingMessages, lastOutgoingMessages |
| **Queue** | clearMessagesQueue, clearWebhooksQueue, getMessagesCount, getWebhooksCount, showMessagesQueue |
| **Receiving** | downloadFile |
| **Sending** | forwardMessages, sendContact, sendFileByUrl, sendLocation, sendMessage, sendPoll |
| **Service** | checkAccount, deleteMessage, editMessage, getAvatar, getChats, getContactInfo, getContacts, readChat, sendTyping |

### WABA

| Resource | Operations |
|---|---|
| **Account** | getSettings, getStateInstance, getWaSettings, setSettings |
| **Journal** | getChatHistory, getMessage, lastIncomingMessages, lastOutgoingMessages |
| **Queue** | clearMessagesQueue, clearWebhooksQueue, getMessagesCount, getWebhooksCount, showMessagesQueue |
| **Sending** | sendFileByUrl, sendMessage, sendTemplate |
| **Template** | getTemplateById, getTemplates |

> **Receiving** covers `downloadFile` and is offered on WhatsApp, MAX and Telegram only — Green API documents no DownloadFile method for WABA, whose notifications already carry a `downloadUrl`. Incoming events themselves are handled by the separate **GREEN-API Trigger** node described below.
> **Cloud Password** manages the MAX two-factor password and is documented for MAX only.
> Operations whose Green API response body is documented as empty — the deletes, archive/unarchive, typing, the queue clears, logout and reboot — emit `{ "success": true }`, so a downstream IF node always has one key to branch on.

---

## ⚙️ Usage Examples

### 💬 Send Message
```json
{
  "operation": "sendMessage",
  "chatId": "79001234567@c.us",
  "message": "Hello from n8n and Green API!"
}
```

### 📎 Send File by URL
```json
{
  "operation": "sendFileByUrl",
  "chatId": "79001234567@c.us",
  "urlFile": "https://example.com/image.jpg",
  "fileName": "photo.jpg"
}
```

### 📣 Send Text Status
```json
{
  "operation": "sendTextStatus",
  "message": "Working with Green-API and n8n!",
  "backgroundColor": "#228B22",
  "font": "SERIF",
  "participants": []
}
```

### 📤 Send Interactive Buttons Reply
```json
{
  "operation": "sendInteractiveButtonsReply",
  "chatId": "79001234567@c.us",
  "header": "",
  "body": "Do you confirm the appointment for tomorrow?",
  "footer": "",
  "buttons": [
        {
            "buttonId": "1",
            "buttonText": "Yes"
        },
        {
            "buttonId": "2",
            "buttonText": "No"
        }
    ]
}
```

### 👥 Create Group
```json
{
  "operation": "createGroup",
  "groupName": "My Team",
  "chatIds": ["79001234567@c.us", "79007654321@c.us"]
}
```

### 🧭 Send Location
```json
{
  "operation": "sendLocation",
  "chatId": "79001234567@c.us",
  "latitude": 40.7128,
  "longitude": -74.0060,
  "nameLocation": "New York",
  "address": "NY, USA"
}
```

### 🔄 Check WhatsApp
```json
{
  "operation": "checkWhatsapp",
  "phoneNumber": 79000000000
}
```

### 🔐 Set Cloud Password (MAX)
```json
{
  "operation": "setAuthorizationPassword",
  "password": "qwerty123",
  "hint": "The usual one"
}
```

> MAX refuses to set a cloud password during the first 24 hours after the account is authorized.

---

## 🔔 Trigger Node

The package also ships a **GREEN-API Trigger** node that starts a workflow on incoming Green API webhooks.

- **Trigger On** — choose which webhook types start the workflow: *Incoming Message*, *Outgoing Message Sent From Phone*, *Outgoing Message Sent From API*. If none are selected, all message webhooks are processed.
- **Restrictions on Receiving** — process messages from all chats, personal chats only, or group chats only. Group chats are recognised per messenger: WhatsApp group IDs end with `@g.us`, while MAX and Telegram group IDs are negative numbers such as `-10000000000000`. WhatsApp status updates, broadcast lists and Channel posts match neither restriction and arrive only under *Receive All*.
- **Restrict to Chat IDs** — process webhooks only from the listed chats.

When the trigger is activated it configures the instance's webhook settings and remembers the previous settings, restoring them when the trigger is deactivated. Green API applies the settings asynchronously: it usually takes under a minute but can take up to 5 minutes, and notifications do not reach n8n until then.

> The trigger starts the workflow for **messages only** (incoming, outgoing from the phone, outgoing from the API). Other notifications Green API sends — delivery and read statuses of sent messages, incoming and outgoing calls, account state changes (for example the instance being logged out), blocks and tariff-limit notices — are acknowledged with `200` and ignored. To react to them, point a plain n8n **Webhook** node at the instance instead and configure the instance's webhook settings yourself.

> Green API allows a single webhook URL per instance. Running two trigger workflows on the same instance is not supported — they would overwrite each other's webhook URL.

### Webhook authorization

If the instance has a **Webhook URL Token** configured, Green API sends it in an `Authorization` header, under either the `Bearer` or the `Basic` scheme. The trigger checks it and answers **HTTP 401** to a call whose token does not match, without starting the workflow. Green API removes a notification from its queue only on a `200` response and retries anything else every 60 seconds for 24 hours, so a rejected call is not lost.

The token is re-read from the instance on every activation and every n8n restart. If you rotate or clear it in the Green API console while the workflow is active, the trigger notices on the next call whose token does not match, re-reads the settings once, and then keeps accepting traffic with the new token. That re-read is throttled to at most once every 5 minutes per trigger, so a flood of calls carrying a wrong token cannot be turned into a flood of requests to Green API.

---

## 🧪 Example Workflow

Minimal "auto-reply" workflow: on every incoming message, send a reply back to the same chat.

```json
{
  "name": "Green API auto-reply",
  "nodes": [
    {
      "parameters": { "webhookType": ["incomingMessageReceived"], "chatType": "noReceiveRestriction" },
      "name": "GREEN-API Trigger",
      "type": "n8n-nodes-nowely-y-test.greenapiTrigger",
      "typeVersion": 1,
      "position": [420, 300]
    },
    {
      "parameters": {
        "superResource": "WhatsApp",
        "resource": "waSending",
        "operation": "sendMessage",
        "chatId": { "__rl": true, "mode": "id", "value": "={{ $json.senderData.chatId }}" },
        "message": "Thanks for your message!"
      },
      "name": "Send Message",
      "type": "n8n-nodes-nowely-y-test.greenapi",
      "typeVersion": 1,
      "position": [680, 300]
    }
  ],
  "connections": {
    "GREEN-API Trigger": { "main": [[{ "node": "Send Message", "type": "main", "index": 0 }]] }
  }
}
```

> The node `type` prefix (`n8n-nodes-nowely-y-test`) must match the installed package name.

> `resource` values are messenger-specific (`waSending`, `maxSending`, `tgSending`, `wabaSending`, and so on for every resource). Building the node from the editor fills this in for you; it only matters when writing workflow JSON by hand.

---

## ✅ Compatibility

- Built and tested against **n8n 2.x**: the package compiles and runs its test suite against `n8n-workflow` ^2.16.0, and n8n 2.40.5 ships `n8n-workflow` 2.40.1 — the same major.
- The `n8n-workflow` peer dependency is deliberately open (`*`), so npm will not block an install on a different major, but nothing here has been built or tested against the n8n 1.x line. Treat n8n 2.x as the supported target.
- Requires **Node.js >= 20.15** (`engines.node`). n8n 2.x asks for Node >= 24 itself, so on a real n8n 2.x host the higher floor applies.
- Tested against the Green API HTTP API as documented at [green-api.com/en/docs/api](https://green-api.com/en/docs/api/).

---

## 🔗 Resources

- 🌐 [Green API Documentation](https://green-api.com/en/docs/)
- 📘 [n8n Documentation](https://docs.n8n.io)
- 💬 [n8n Community Forum](https://community.n8n.io)

---

## 👤 Author

Developed by [Green API](https://green-api.com/)  
📧 support@green-api.com  
🌍 https://green-api.com/en/

---

## 🪪 License

[MIT License](LICENSE.md)