Getting Started
Installing
Prerequisites:
Assuming you’ve already installed Node.js, create a directory to hold your application, and make that your working directory.
Use the npm init command to create a package.json file for your application. For more information on how package.json works, see Specifics of npm’s package.json handling.
Now install Zalojs in the myApp directory and save it in the dependencies list. For example:
Basic Usage
Configuration files :
Create a configuration file (
config.json
) with the following structure:Replace placeholders with your actual group ID, group name, and set
headless
totrue
for headless mode.For reference, an example configuration is provided:
Remember, the example configuration is for illustrative purposes only and should be replaced with your specific information. Creating the main file Open your code editor and create a new file. We suggest that you save the file as index.js, but you may name it whatever you wish. Here's the base code to get you started:
Running your application Open your terminal and run node index.js to start the process. Upon running the program, a server will automatically start at http://localhost:3000/. Next, use your mobile device to scan the QR code displayed there using the Mobile Zalo Application.
Command Handling
Unless your bot project is small, it's not a very good idea to have a single file with a giant if/else if chain for commands. If you want to implement features into your bot and make your development process a lot less painful, you'll want to implement a command handler. Let's get started on that! Loading command files Now that your command files have been created, your bot needs to load these files on startup.
In your index.js file, make these additions to the base template:
Next, using the modules imported above, dynamically retrieve your command files with a few more additions to the index.js file: Loading Commands:
Handling
Example Command File (commands/ping.js):
Last updated