How to install Wechaty
We have a Wechaty starter repository for beginners with the simplest setting. It will be just work out-of-the-box after you clone
, run npm install
in the terminal, followed by npm start
.
Requirements
- Node.js v16
sudo apt-get install build-essential && sudo snap install shellcheck
The World's Shortest ChatBot Code: 6 lines of JavaScript
import { Wechaty } from 'wechaty' // import { Wechaty } from 'wechaty'
Wechaty.instance() // Global Instance
.on('scan', (qrcode, status) => console.log(`Scan QR Code to login: ${status}\nhttps://wechaty.js.org/qrcode/${encodeURIComponent(qrcode)}`))
.on('login', user => console.log(`User ${user} logged in`))
.on('message', message => console.log(`Message: ${message}`))
.start()
Please save the above The World's Shortest ChatBot Code: 6 lines of JavaScript example to a file named bot.js
before you can use either NPM or Docker to run it.
1. Npm
npm init
npm install wechaty
# create your first bot.js file, you can copy/paste from the above "The World's Shortest ChatBot Code: 6 lines of JavaScript"
# then:
node bot.js
2. Docker
- Wechaty Starter Repository for Docker - https://github.com/wechaty/docker-wechaty-getting-started
Wechaty Docker supports both JavaScript and TypeScript. To use TypeScript just write in TypeScript and save with extension name
.ts
, no need to compile because we usets-node
to run it.
2.1. Run JavaScript
# for JavaScript
docker run -ti --rm --volume="$(pwd)":/bot wechaty/wechaty bot.js
2.2. Run TypeScript
# for TypeScript
docker run -ti --rm --volume="$(pwd)":/bot wechaty/wechaty bot.ts
Learn more about Wechaty Docker at Wiki:Docker.
TEST
Wechaty is fully automatically tested by unit and integration tests, with Continious Integration & Continious Deliver(CI/CD) support powered by CI like Travis, Shippable and Appveyor.
To test Wechaty, run:
npm test
Get to know more about the tests from Wiki:Tests