generated from wechaty/puppet-mock
-
Notifications
You must be signed in to change notification settings - Fork 88
Getting Started with TypeScript Javascript
padlocal edited this page May 7, 2021
·
4 revisions
There are some ways to get started with PadLocal.
You need PadLocal token to run this demo. How to Apply Token
Install Node, 12/14 LTS version is recommended.
$ node --version // >= v12.0.0
2. Clone the wechaty-puppet-padlocal-demo project.
$ git clone [email protected]:padlocal/wechaty-puppet-padlocal-demo.git
Then install Node dependencies.
$ cd wechaty-puppet-padlocal-demo
$ npm install
3. Set you PadLocal Token in main.ts
const puppet = new PuppetPadlocal({
token: "YOUR_PADLOCAL_TOKEN"
})
Then run it:
$ npm run demo
If you want to explore PadLocal step by step, following instructions may be helpful.
You need PadLocal token to run PadLocal. How to Apply Token
Install Node, 12/14 LTS version is recommended.
$ node --version // >= v12.0.0
mkdir my-padlocal-bot && cd my-padlocal-bot
npm init -y
npm install ts-node typescript -g --registry=https://r.npm.taobao.org
tsc --init --target ES6
npm install wechaty@latest --registry=https://r.npm.taobao.org
npm install wechaty-puppet-padlocal@latest --registry=https://r.npm.taobao.org
// bot.ts
import {PuppetPadlocal} from "wechaty-puppet-padlocal";
import {Contact, Message, ScanStatus, Wechaty} from "wechaty";
const token: string = "" // padlocal token
const puppet = new PuppetPadlocal({ token })
const bot = new Wechaty({
name: "TestBot",
puppet,
})
bot
.on("scan", (qrcode: string, status: ScanStatus) => {
if (status === ScanStatus.Waiting && qrcode) {
const qrcodeImageUrl = ["https://api.qrserver.com/v1/create-qr-code/?data=", encodeURIComponent(qrcode)].join("");
console.log(`onScan: ${ScanStatus[status]}(${status}) - ${qrcodeImageUrl}`);
} else {
console.log(`onScan: ${ScanStatus[status]}(${status})`);
}
})
.on("login", (user: Contact) => {
console.log(`${user} login`);
})
.on("logout", (user: Contact) => {
console.log(`${user} logout`);
})
.on("message", async (message: Message) => {
console.log(`on message: ${message.toString()}`);
})
.start()
console.log("TestBot", "started");
Then run the bot:
$ ts-node bot.ts
Don't be evil
GETTING STARTED
- How to Apply Token
- Getting Started with TypeScript/JavaScript(RECOMMENDED)
- Getting Started with Python/Java/Go
REFERENCE
ADVANCED GUIDES