Skip to content

Getting Started with TypeScript Javascript

Leo_chen edited this page Aug 23, 2022 · 2 revisions

There are some ways to get started with Engine.

Quick Start with Demo

0. download dll

You need download dll to run this demo. How to Download Dll

1. Prepare Node Environment

Install Node, 16 LTS version is recommended.

$ node --version // >= v16.0.0

2. Clone the wechaty-puppet-engine-demo project.

$ git clone [email protected]:leochen-g/wechaty-puppet-engine-demo.git

Then install Node dependencies.

$ cd wechaty-puppet-engine-demo
$ npm install

3. Set you server info in main.ts

const puppet = new PuppetEngine({
    port: 8089,
    runLocal: false,
    httpServer: 'http://10.10.10.15:8055',
})

Then run it:

$ npm run demo

Getting Started from Scratch: step-by-step instructions

If you want to explore Engine step by step, following instructions may be helpful.

0. download dll

You need download dll to run Engine. How to Download Dll

1. Prepare Node environment

Install Node, 16 LTS version is recommended.

$ node --version // >= v16.0.0

2. Create and init your bot project

mkdir my-engine-bot && cd my-engine-bot
npm init -y
npm install ts-node typescript -g --registry=https://registry.npmmirror.com/
tsc --init --target ES6

3. Install Wechaty and Engine puppet

npm install wechaty@latest --registry=https://registry.npmmirror.com/
npm install wechaty-puppet-engine@latest --registry=https://registry.npmmirror.com/

4. Write bot demo code

// bot.ts

import {PuppetEngine} from "wechaty-puppet-engine";
import {WechatyBuilder} from "wechaty";
const puppet = new PuppetEngine({
    port: 8089,
    runLocal: false,
    httpServer: 'http://10.10.10.15:8055',
  }),

const bot = WechatyBuilder.build({
    name: "TestBot",
    puppet,
})

bot
.on("login", (user: Contact) => {
    console.log(`${user} login`);
})
.on("message", async (message: Message) => {
    console.log(`on message: ${message.toString()}`);
})

.start()

console.log("TestBot", "started");

Then run the bot:

$ ts-node bot.ts