Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rfs-adreno/zca-js
Unofficial Zalo API for JavaScript
https://github.com/rfs-adreno/zca-js
api bun javascript nodejs typescript zalo
Last synced: 1 day ago
JSON representation
Unofficial Zalo API for JavaScript
- Host: GitHub
- URL: https://github.com/rfs-adreno/zca-js
- Owner: RFS-ADRENO
- License: mit
- Created: 2024-07-15T11:12:07.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2025-01-24T11:31:54.000Z (9 days ago)
- Last Synced: 2025-01-25T06:04:46.173Z (8 days ago)
- Topics: api, bun, javascript, nodejs, typescript, zalo
- Language: TypeScript
- Homepage: https://zca.tdung.co
- Size: 575 KB
- Stars: 81
- Watchers: 5
- Forks: 45
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ZCA-JS
This is an unofficial Zalo API for personal account. It work by simulating the browser to interact with Zalo Web.
**Warning**: Using this API could get your account locked or banned. We are not responsible for any issues that may happen. Use it at your own risk.
## Installation
```bash
bun install zca-js # or npm install zca-js
```## Documentation
See [API Documentation](https://zca.tdung.co/) for more details.
## Basic Usages
### Login
```javascript
import { Zalo } from "zca-js";const zalo = new Zalo();
const api = await zalo.loginQR();
```### Listen for new messages
```javascript
import { Zalo, ThreadType } from "zca-js";const zalo = new Zalo();
const api = await zalo.loginQR();api.listener.on("message", (message) => {
const isPlainText = typeof message.data.content === "string";switch (message.type) {
case ThreadType.User: {
if (isPlainText) {
// received plain text direct message
}
break;
}
case ThreadType.Group: {
if (isPlainText) {
// received plain text group message
}
break;
}
}
});api.listener.start();
```**Note**: Only one web listener can run per account at a time. If you open Zalo in the browser while the listener is active, the listener will be automatically stopped.
### Send a message
```javascript
import { Zalo, ThreadType } from "zca-js";const zalo = new Zalo();
const api = await zalo.loginQR();// Echo bot
api.listener.on("message", (message) => {
const isPlainText = typeof message.data.content === "string";
if (message.isSelf || !isPlainText) return;switch (message.type) {
case ThreadType.User: {
api.sendMessage(
{
msg: "echo: " + message.data.content,
quote: message, // the message object to reply to (optional)
},
message.threadId,
message.type, // ThreadType.User
);
break;
}
case ThreadType.Group: {
api.sendMessage(
{
msg: "echo: " + message.data.content,
quote: message, // the message object to reply to (optional)
},
message.threadId,
message.type, // ThreadType.Group
);
break;
}
}
});api.listener.start();
```### Get/Send a sticker
```javascript
api.getStickers("hello").then(async (stickerIds) => {
// Get the first sticker
const stickerObject = await api.getStickersDetail(stickerIds[0]);
api.sendMessageSticker(
stickerObject,
message.threadId,
message.type, // ThreadType.User or ThreadType.Group
);
});
```## Example
See [examples](examples) folder for more details.
## Contributing
We welcome contributions from the community.
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.