@warriorteam/zalo-personal
Version:
Unofficial Zalo Personal API for JavaScript - A powerful library for interacting with Zalo personal accounts with URL attachment support
471 lines (361 loc) โข 13.5 kB
Markdown
Thank you for your interest in contributing to zca-js! This project is maintained by the community and we welcome all contributions.
- [Code of Conduct](
- [Getting Started](
- [Development Setup](
- [How to Contribute](
- [Pull Request Process](
- [Code Style Guidelines](
- [Testing Guidelines](
- [Documentation Guidelines](
- [Security Guidelines](
- [Release Process](
- [Getting Help](
This project adheres to our [Code of Conduct](CODE_OF_CONDUCT.md). By participating, you agree to abide by these rules.
- Node.js >= 18.0.0
- Bun (recommended) or npm
- Git
1. Fork this repository
2. Clone your fork:
```bash
git clone https://github.com/YOUR_USERNAME/zca-js.git
cd zca-js
```
3. Add upstream remote:
```bash
git remote add upstream https://github.com/RFS-ADRENO/zca-js.git
```
```bash
bun install
npm install
```
```bash
bun run build
bun run build:esm
bun run build:cjs
```
```bash
bun run test:feat
bun run test/test.ts
```
```bash
bun run prettier
```
We welcome the following types of contributions:
- ๐ **Bug Reports**: Report bugs and issues
- โจ **Feature Requests**: Suggest new features
- ๐ง **Code Contributions**: Fix bugs and add features
- ๐ **Documentation**: Improve docs and examples
- ๐งช **Tests**: Add or improve tests
- ๐ **Security**: Report security vulnerabilities
- ๐ **Translations**: Translate docs to other languages
1. **Check existing issues**: Search for existing issues before creating new ones
2. **Discuss major changes**: Create an issue to discuss major changes
3. **Follow the roadmap**: Check the current roadmap and priorities
1. **Create a feature branch**:
```bash
git checkout -b feature/your-feature-name
git checkout -b fix/your-bug-fix
```
2. **Make your changes**:
- Follow code style guidelines
- Add tests for new functionality
- Update documentation if needed
3. **Test your changes**:
```bash
bun run build
bun run test:feat
```
4. **Commit your changes**:
```bash
git add .
git commit -m "feat: add new API method for group management"
```
5. **Push to your fork**:
```bash
git push origin feature/your-feature-name
```
6. **Create a Pull Request**:
- Use the provided PR template
- Link related issues
- Provide clear description of changes
1. **Automated checks** must pass
2. **Code review** by at least one maintainer
3. **Security review** for security-related changes
4. **Documentation review** for API changes
5. **Final approval** before merge
- Use TypeScript strict mode
- Prefer interfaces over types for object shapes
- Use meaningful variable and function names
- Add JSDoc comments for public APIs
- Use async/await over Promises when possible
The project follows a modular structure for better maintainability and organization:
```
zca-js/
โโโ src/
โ โโโ apis/
โ โ โโโ sendMessage.ts
โ โ โโโ login.ts
โ โ โโโ loginQR.ts
โ โ โโโ listen.ts
โ โ โโโ sendVideo.ts
โ โ โโโ sendVoice.ts
โ โ โโโ sendSticker.ts
โ โ โโโ createGroup.ts
โ โ โโโ addReaction.ts
โ โ โโโ uploadAttachment.ts
โ โ โโโ ...
โ โโโ models/
โ โ โโโ Message.ts
โ โ โโโ Attachment.ts
โ โ โโโ Reaction.ts
โ โ โโโ FriendEvent.ts
โ โ โโโ GroupEvent.ts
โ โ โโโ Typing.ts
โ โ โโโ SeenMessage.ts
โ โ โโโ DeliveredMessage.ts
โ โ โโโ Undo.ts
โ โ โโโ Enum.ts
โ โ โโโ index.ts
โ โโโ Errors/
โ โ โโโ ZaloApiError.ts
โ โ โโโ index.ts
โ โโโ context.ts
โ โโโ utils.ts
โ โโโ zalo.ts
โ โโโ update.ts
โ โโโ index.ts
โโโ examples/
โ โโโ echobot.ts
โโโ test/
โ โโโ feat.ts
โ โโโ feat.test.ts
โ โโโ test.ts
โ โโโ a.png
โโโ .github/
โ โโโ ISSUE_TEMPLATE/
โโโ .dev/
โโโ dist/
โโโ node_modules/
โโโ package.json
โโโ tsconfig.json
โโโ rollup.config.js
โโโ README.md
โโโ CONTRIBUTING.md
โโโ SECURITY.md
โโโ CODE_OF_CONDUCT.md
โโโ LICENSE
```
- **`src/apis/`**: Contains all API method implementations (~100 files)
- **`src/models/`**: TypeScript interfaces and type definitions
- Core data structures for messages, events, and API responses
- Ensures type safety across the application
- **`src/Errors/`**: Custom error handling
- `ZaloApiError.ts`: Handles API-specific errors
- Provides consistent error handling across the library
- **`examples/`**: Usage examples and demonstrations
- `echobot.ts`: Complete example of a Zalo bot implementation
- **`test/`**: Test suites and test assets
- Feature tests for core functionality
- Integration tests for API methods
### Naming Conventions
- **Files**: camelCase (e.g., `sendMessage.ts`)
- **Classes**: PascalCase (e.g., `ZaloApiError`)
- **Functions**: camelCase (e.g., `sendMessage`)
- **Constants**: UPPER_SNAKE_CASE (e.g., `API_BASE_URL`)
- **Interfaces**: PascalCase with `I` prefix (e.g., `IMessage`)
### Error Handling
```typescript
// Good
try {
const result = await api.sendMessage(message);
return result;
} catch (error) {
if (error instanceof ZaloApiError) {
throw error;
}
throw new ZaloApiError(`Failed to send message: ${error.message}`);
}
// Bad
try {
const result = await api.sendMessage(message);
return result;
} catch (error) {
console.error(error);
return null;
}
```
```typescript
describe('API Method', () => {
beforeEach(() => {
// Setup
});
afterEach(() => {
// Cleanup
});
it('should handle success case', async () => {
// Test implementation
});
it('should handle error case', async () => {
// Test error handling
});
});
```
- Test both success and failure scenarios
- Mock external dependencies
- Use descriptive test names
- Keep tests independent
- Test edge cases and error conditions
```bash
bun run test:feat
bun run test/test.ts
bun run test:coverage
```
- Document all public methods with JSDoc
- Include parameter types and descriptions
- Provide usage examples
- Document error conditions
```typescript
/**
* Sends a message to a specific thread
* @param message - The message object containing content and metadata
* @param threadId - The ID of the thread to send the message to
* @param threadType - The type of thread (User or Group)
* @returns Promise<Message> - The sent message object
* @throws {ZaloApiError} When the API request fails
* @example
* ```typescript
* const message = await api.sendMessage(
* { msg: "Hello, world!" },
* "123456789",
* ThreadType.User
* );
* ```
*/
async sendMessage(message: IMessage, threadId: string, threadType: ThreadType): Promise<Message>
```
### README Updates
- Update README.md for new features
- Add examples for new APIs
- Update installation instructions if needed
- Keep the table of contents updated
## Security Guidelines
### Security Best Practices
- Never commit sensitive data (tokens, passwords, etc.)
- Use environment variables for configuration
- Validate all user inputs
- Follow the principle of least privilege
- Report security issues privately
### Security Reporting
If you discover a security vulnerability:
1. **DO NOT** create a public issue
2. Use the [SECURITY.md](SECURITY.md) reporting process
3. Create a private issue with `[SECURITY]` label
4. Contact team members directly for urgent issues
### Code Security
```typescript
// Good - Validate inputs
function sendMessage(content: string, threadId: string) {
if (!content || typeof content !== 'string') {
throw new ZaloApiError('Content must be a non-empty string');
}
if (!threadId || typeof threadId !== 'string') {
throw new ZaloApiError('ThreadId must be a non-empty string');
}
// Implementation
}
// Bad - No validation
function sendMessage(content: any, threadId: any) {
// Implementation without validation
}
```
We follow [Semantic Versioning](https://semver.org/):
- **MAJOR**: Breaking changes
- **MINOR**: New features (backward compatible)
- **PATCH**: Bug fixes (backward compatible)
### Release Checklist
- [ ] All tests pass
- [ ] Documentation is updated
- [ ] Version is bumped in package.json
- [ ] Build is successful
- [ ] Release notes are prepared
### Publishing
```bash
# Build the project
bun run build
# Run tests
bun run test:feat
# Publish to npm
npm publish
```
## Getting Help
### Communication Channels
- **GitHub Issues**: For bug reports and feature requests
- **GitHub Discussions**: For questions and general discussion
- **Pull Requests**: For code contributions
- **Security Issues**: Use `[SECURITY]` label
### Team Members
- [@RFS-ADRENO](https://github.com/RFS-ADRENO)
- [@truong9c2208](https://github.com/truong9c2208)
- [@JustKemForFun](https://github.com/JustKemForFun)
### Resources
- [API Documentation](https://tdung.gitbook.io/zca-js)
- [Examples](examples/)
- [Security Policy](SECURITY.md)
- [Code of Conduct](CODE_OF_CONDUCT.md)
## Special Considerations for zca-js
### Unofficial API Library
> [!IMPORTANT]
> โ ๏ธ zca-js is an unofficial API library for Zalo. Please be aware of:
- **Account Risk**: Using this API may result in account suspension
- **Terms of Service**: Respect Zalo's ToS in your contributions
- **Rate Limiting**: Be mindful of API usage limits
- **Privacy**: Protect user privacy and data
### Responsible Development
- Test changes thoroughly before submitting
- Avoid introducing features that could harm users
- Consider the impact on Zalo's infrastructure
- Document any risks or limitations
---
**Thank you for contributing to zca-js!** ๐
Your contributions help make this library better for the entire community.