Skip to content

Commit 7eb0ac5

Browse files
committed
feat: 🎸 hello world section
1 parent 67312dc commit 7eb0ac5

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

docusaurus/docs/api/hello-world.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
title: Hello World
3+
sidebar_label: 'Hello World'
4+
---
5+
6+
## Hello World
7+
8+
In this section, we'll create a simple bot: Ding-Dong bot. When it receives a text message 'ding', it will reply with text 'dong'.
9+
10+
1. install dependencies with npm
11+
12+
```bash
13+
npm install wechaty
14+
```
15+
16+
2. create a bot instance
17+
18+
```ts
19+
import { WechatyBuilder } from 'wechaty'
20+
21+
const bot = new WechatyBuilder.build()
22+
```
23+
24+
3. listen to scan event
25+
26+
```ts
27+
bot.on('scan', (qrcode, status) => console.log(`Scan QR Code to login: ${status}\nhttps://wechaty.js.org/qrcode/${encodeURIComponent(qrcode)}`))
28+
```
29+
30+
As we know, each QRcode represents a particular string. Here the call back of scan event will pass a qrcode string. We generate the qrcode with wechaty website api and scan to login.
31+
32+
4. listen to message event
33+
34+
```ts
35+
bot.on('message', message => if (message.text() === 'ding') {
36+
message.say('dong')
37+
})
38+
```
39+
40+
The message event will pass a ```MessageInterface``` instance to the callback. We can get the text content by calling ```message.text()```. If the message is 'ding', we reply with ```message.say()```. This is a shortcut for sending messages to the sender of the message. You can find detail info about it in [User-Module: Message](api/message.md) section.

docusaurus/sidebars.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const api: SubMenuData = {
2222
label: 'API',
2323
items: [
2424
'api/overview',
25+
'api/hello-world',
2526
'api/wechaty',
2627
'api/message',
2728
'api/contact',

0 commit comments

Comments
 (0)