{"id":15093476,"url":"https://github.com/green-api/whatsapp-api-client-js","last_synced_at":"2025-04-04T15:08:57.860Z","repository":{"id":42139670,"uuid":"262542730","full_name":"green-api/whatsapp-api-client-js","owner":"green-api","description":"This library helps you easily create a javascript application with Whatsapp support","archived":false,"fork":false,"pushed_at":"2025-02-24T11:43:20.000Z","size":410,"stargazers_count":134,"open_issues_count":6,"forks_count":35,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-28T14:07:49.349Z","etag":null,"topics":["whatsapp","whatsapp-api","whatsapp-bot","whatsapp-chat","whatsapp-library","whatsapp-message-sender","whatsapp-send-message","whatsapp-sender"],"latest_commit_sha":null,"homepage":"https://green-api.com","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/green-api.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-05-09T10:08:12.000Z","updated_at":"2025-03-17T05:54:41.000Z","dependencies_parsed_at":"2024-03-17T07:39:49.498Z","dependency_job_id":"9679dc8f-cd75-413d-be04-abaf80a509cd","html_url":"https://github.com/green-api/whatsapp-api-client-js","commit_stats":{"total_commits":222,"total_committers":19,"mean_commits":11.68421052631579,"dds":0.7792792792792793,"last_synced_commit":"130b3e455468e1aeddc1e25b7ed02e4450f6a6d3"},"previous_names":["green-api/whatsapp-api-client"],"tags_count":28,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/green-api%2Fwhatsapp-api-client-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/green-api%2Fwhatsapp-api-client-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/green-api%2Fwhatsapp-api-client-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/green-api%2Fwhatsapp-api-client-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/green-api","download_url":"https://codeload.github.com/green-api/whatsapp-api-client-js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247198461,"owners_count":20900080,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["whatsapp","whatsapp-api","whatsapp-bot","whatsapp-chat","whatsapp-library","whatsapp-message-sender","whatsapp-send-message","whatsapp-sender"],"created_at":"2024-09-25T11:23:31.280Z","updated_at":"2025-04-04T15:08:57.830Z","avatar_url":"https://github.com/green-api.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# whatsapp-api-client library for javascript\n\n![](https://img.shields.io/badge/license-CC%20BY--ND%204.0-green)\n![](https://img.shields.io/npm/v/%40green-api%2Fwhatsapp-api-client)\n![](https://img.shields.io/github/actions/workflow/status/green-api/whatsapp-api-client-js/build.yml)\n![](https://img.shields.io/npm/dm/%40green-api%2Fwhatsapp-api-client)\n\n## Support links\n\n[![Support](https://img.shields.io/badge/support@green--api.com-D14836?style=for-the-badge\u0026logo=gmail\u0026logoColor=white)](mailto:support@greenapi.com)\n[![Support](https://img.shields.io/badge/Telegram-2CA5E0?style=for-the-badge\u0026logo=telegram\u0026logoColor=white)](https://t.me/greenapi_support_eng_bot)\n[![Support](https://img.shields.io/badge/WhatsApp-25D366?style=for-the-badge\u0026logo=whatsapp\u0026logoColor=white)](https://wa.me/77273122366)\n\n## Guides \u0026 News\n\n[![Guides](https://img.shields.io/badge/YouTube-%23FF0000.svg?style=for-the-badge\u0026logo=YouTube\u0026logoColor=white)](https://www.youtube.com/@greenapi-en)\n[![News](https://img.shields.io/badge/Telegram-2CA5E0?style=for-the-badge\u0026logo=telegram\u0026logoColor=white)](https://t.me/green_api)\n[![News](https://img.shields.io/badge/WhatsApp-25D366?style=for-the-badge\u0026logo=whatsapp\u0026logoColor=white)](https://whatsapp.com/channel/0029VaLj6J4LNSa2B5Jx6s3h)\n\n- [Документация на русском языке](https://github.com/green-api/whatsapp-api-client-js/blob/master/docs/README.md).\n\nThis library helps you easily create a javascript application to connect the WhatsApp API using\nservice [green-api.com](https://green-api.com/en). You need to get `ID_INSTANCE`and `API_TOKEN_INSTANCE` in\nthe [control panel](https://console.green-api.com) in order to use this library. It's free for developers.\n\n## API\n\nThe API corresponds with [REST API](https://green-api.com/en/docs/api/) from green-api since the library wraps own\nmethods as https calls to the service. Therefore, using these [docs](https://green-api.com/en/docs/) is highly\nencouraged.\n\n## Installing\n\nLibrary supports both browser environment without package managers and Node/Webpack apps with package manager that can\nhandle `require` or `import` module expressions.\nFor webpack and npm based apps:\n\n```\nnpm i @green-api/whatsapp-api-client\n```\n\nFor vanilla html-js website modify index.html:\n\n```html\n\n\u003cscript src=\"https://unpkg.com/@green-api/whatsapp-api-client/lib/whatsapp-api-client.min.js\"\u003e\u003c/script\u003e\n```\n\n## Importing\n\nThere are several ways to import the library in a project\n\nUsing common javascript\n\n```\nconst whatsAppClient = require(\"@green-api/whatsapp-api-client\");\n```\n\nUsing ES6 javascript\n\n```\nimport whatsAppClient from \"@green-api/whatsapp-api-client\";\n```\n\nUsing typescript\n\n```\nimport * as whatsAppClient from \"@green-api/whatsapp-api-client\";\n```\n\nUsing browser javascript\n\n```\n\u003cscript src=\"https://unpkg.com/@green-api/whatsapp-api-client/lib/whatsapp-api-client.min.js\"\u003e\u003c/script\u003e\n```\n\n## Authentication\n\nSending WhatsApp message like any other call to the API requires account registered\non [green-api.com](https://green-api.com/en) and authentication completed on mobile WhatsApp app. To register account\nyou have to proceed to the [control panel](https://console.green-api.com/). After registering you wll get own unique\npair of `ID_INSTANCE` and `API_TOKEN_INSTANCE` keys.\n\nWhatsApp mobile app authentication may be achieved by using [control panel](https://console.green-api.com/). You need to\nscan QR-code generated within the control panel.\n\n## Examples\n\nPlease do not use 'phoneNumber' parameter when calling methods. It is deprecated. Examples below are based on 'chatId'\nparameter\n\n### Send WhatsApp message\n\nUse common javascript\n\n```js\nconst whatsAppClient = require(\"@green-api/whatsapp-api-client\");\n\nconst restAPI = whatsAppClient.restAPI({\n    idInstance: \"YOUR_ID_INSTANCE\",\n    apiTokenInstance: \"YOUR_API_TOKEN_INSTANCE\",\n});\n\nrestAPI.message.sendMessage(\"79999999999@c.us\", null, \"hello world\").then((data) =\u003e {\n    console.log(data);\n});\n```\n\nor use browser js script\n\n```html\n\n\u003cscript src=\"https://unpkg.com/@green-api/whatsapp-api-client/lib/whatsapp-api-client.min.js\"\u003e\u003c/script\u003e\n\u003cscript\u003e\n    const restAPI = whatsAppClient.restAPI({\n        idInstance: \"YOUR_ID_INSTANCE\",\n        apiTokenInstance: \"YOUR_API_TOKEN_INSTANCE\",\n    });\n    restAPI.message\n            .sendMessage(\"79999999999@c.us\", null, \"hello world\")\n            .then((data) =\u003e {\n                console.log(data);\n            })\n            .catch((reason) =\u003e {\n                console.error(reason);\n            });\n\u003c/script\u003e\n```\n\nOr use ES6 syntax. For Node.js app, you probably have to add in `package.json` property `\"type\": \"module\"`. Notice that\nall examples below are ES6 based.\n\n```js\nimport whatsAppClient from \"@green-api/whatsapp-api-client\";\n\n(async () =\u003e {\n    const restAPI = whatsAppClient.restAPI({\n        idInstance: \"YOUR_ID_INSTANCE\",\n        apiTokenInstance: \"YOUR_API_TOKEN_INSTANCE\",\n    });\n    const response = await restAPI.message.sendMessage(\n        \"79999999999@c.us\",\n        null,\n        \"hello world\"\n    );\n})();\n```\n\n### Using credentials file for `ID_INSTANCE` and `API_TOKEN_INSTANCE` keys (Node.js only!)\n\nYou might want to store yours credentials separately from code. The library allow you to create a text file with\npreferred name and location with the format:\n\n```\nAPI_TOKEN_INSTANCE = \"MY_API_TOKEN_INSTANCE\"\nID_INSTANCE = \"MY_ID_INSTANCE\"\n```\n\nAnd then pass this file as described below:\n\n```js\nconst restAPI = whatsAppClient.restAPI({\n    credentialsPath: \"examples\\\\credentials\",\n});\n```\n\n### Receive notifications using webhook service REST API\n\n```js\nimport whatsAppClient from \"@green-api/whatsapp-api-client\";\n\n(async () =\u003e {\n    let restAPI = whatsAppClient.restAPI({\n        idInstance: \"YOUR_ID_INSTANCE\",\n        apiTokenInstance: \"YOUR_API_TOKEN_INSTANCE\",\n    });\n\n    try {\n        // Receive WhatsApp notifications.\n        console.log(\"Waiting incoming notifications...\");\n        await restAPI.webhookService.startReceivingNotifications();\n        restAPI.webhookService.onReceivingMessageText((body) =\u003e {\n            console.log(body);\n            restAPI.webhookService.stopReceivingNotifications();\n            //console.log(\"Notifications is about to stop in 20 sec if no messages will be queued...\")\n        });\n        restAPI.webhookService.onReceivingDeviceStatus((body) =\u003e {\n            console.log(body);\n        });\n        restAPI.webhookService.onReceivingAccountStatus((body) =\u003e {\n            console.log(body);\n        });\n    } catch (ex) {\n        console.error(ex.toString());\n    }\n})();\n```\n\n### Send WhatsApp file\n\n```js\nimport whatsAppClient from \"@green-api/whatsapp-api-client\";\n\n(async () =\u003e {\n    const restAPI = whatsAppClient.restAPI({\n        idInstance: \"YOUR_ID_INSTANCE\",\n        apiTokenInstance: \"YOUR_API_TOKEN_INSTANCE\",\n    });\n    const response = await restAPI.file.sendFileByUrl(\n        \"79999999999@c.us\",\n        null,\n        \"https://avatars.mds.yandex.net/get-pdb/477388/77f64197-87d2-42cf-9305-14f49c65f1da/s375\",\n        \"horse.png\",\n        \"horse\"\n    );\n})();\n```\n\n### Send WhatsApp message and receive webhook\n\nWebhooks are event-based callbacks invoked by green-api server as responses to client API calls. Webhooks support\nNode.js and express based apps only.\n\n```js\nimport whatsAppClient from \"@green-api/whatsapp-api-client\";\nimport express from \"express\";\nimport bodyParser from \"body-parser\";\n\n(async () =\u003e {\n    try {\n        // Set http url, where webhooks are hosted.\n        // Url must have public domain address.\n        await restAPI.settings.setSettings({\n            webhookUrl: \"MY_HTTP_SERVER:3000/webhooks\",\n        });\n\n        const app = express();\n        app.use(bodyParser.json());\n        const webHookAPI = whatsAppClient.webhookAPI(app, \"/webhooks\");\n\n        // Subscribe to webhook happened when WhatsApp delivered a message\n        webHookAPI.onIncomingMessageText(\n            (data, idInstance, idMessage, sender, typeMessage, textMessage) =\u003e {\n                console.log(`outgoingMessageStatus data ${data.toString()}`);\n            }\n        );\n\n        // Run web server with public domain address\n        app.listen(3000, async () =\u003e {\n            console.log(`Started. App listening on port 3000!`);\n\n            const restAPI = whatsAppClient.restAPI({\n                idInstance: MY_ID_INSTANCE,\n                apiTokenInstance: MY_API_TOKEN_INSTANCE,\n            });\n            // Send test message that triggers webhook\n            const response = await restAPI.message.sendMessage(\n                \"79999999999@c.us\",\n                null,\n                \"hello world\"\n            );\n        });\n    } catch (error) {\n        console.error(error);\n        process.exit(1);\n    }\n})();\n```\n\nThere's some cool [examples too](examples).\n\n## Deploying development environment\n\nAny help with development and bug fixing is appreciated. In order to deploy test-ready environment please make the\nsteps:\n\n1. Clone repo with `git clone`\n2. Install dependencies with `npm install`\n3. Install globally libraries `rollup` for bundled builds.\n4. Add webhooks as new dev express via npm `npm install express --save-dev`. Don't forget to delete it before making\n   pull request\n5. Create .env file in root folder and add environment variables using example file [env.example](env.example)\n6. Add `\"type\": \"module\"` to the package.json\n\n## Build\n\nCompile browser and node|webpack versions with single command:\n\n```\nnpm run build\n```\n\nPublish to npm if you have access\n\n```\nnpm publish\n```\n\n## Third-party libraries\n\n- [axios](https://github.com/axios/axios) - http requests\n- [express](https://www.npmjs.com/package/express) - app server for webhooks\n\n## License\n\nLicensed on MIT terms. For additional info have look at [LICENSE](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgreen-api%2Fwhatsapp-api-client-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgreen-api%2Fwhatsapp-api-client-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgreen-api%2Fwhatsapp-api-client-js/lists"}