Skip to content

feat: 🎸 new api overview #1527

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions docusaurus/docs/api/hello-world.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
title: Hello World
sidebar_label: 'Hello World'
---

## Hello World

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'.

1. install dependencies with npm

```bash
npm install wechaty
```

2. create a bot instance

```ts
import { WechatyBuilder } from 'wechaty'

const bot = new WechatyBuilder.build()
```

3. listen to scan event

```ts
bot.on('scan', (qrcode, status) => console.log(`Scan QR Code to login: ${status}\nhttps://wechaty.js.org/qrcode/${encodeURIComponent(qrcode)}`))
```

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.

4. listen to message event

```ts
bot.on('message', message => if (message.text() === 'ding') {
message.say('dong')
})
```

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.
31 changes: 24 additions & 7 deletions docusaurus/docs/api/overview.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
slug: /api/
title: Wechaty API
title: Wechaty API
sidebar_label: 'API: Overview'
---

Expand All @@ -10,16 +10,33 @@ export const Toc = () => <TOCInline toc={toc} />
<!-- Curious Beginner: API reference - Details all elements in an API. -->
<!-- Active User: API Guide - Contains far greater detail (including edge cases) than a tutorial or Codelab. -->

## Wechaty API
## Intro

API- Application programming interface is a software interface that offers services to other software services. Wechaty API is a very tiny and easy to import API that allows users to use all the functionalities of Wechaty to its best. The API offers a variety of user classes, typedefs, functions, methods, and many more features. This section is an overview of the Wechaty API.
Wechaty is a Node.js library for building chatbots that work on WeChat, WhatsApp, and other messaging platforms. With Wechaty, you can build intelligent chatbots that automate tasks, engage with customers, and provide a personalized experience for your users.

## Importing the Wechaty API
With the help of wechaty, you can build chatbots with 6 lines of code.

You can import the Wechaty API as shown below:
### Install

## ES6/TypeScript
In most cases, you should install ```wechaty``` only. The package ```wechaty``` has ```wechaty-puppet```, ```wechaty-puppet-service``` in its dependencies, so you don't have install them by yourself. So all you have to is

```js
```bash
npm install wechaty
```

If you wish to use a particular version of ```wechaty-puppet``` or ```wechaty-puppet-service```, you can install such package manually.

### Run

```ts
import { WechatyBuilder } from 'wechaty'

async function main () {
const bot = new WechatyBuilder.build()
bot
.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}`))
await bot.start()
}
```
1 change: 1 addition & 0 deletions docusaurus/sidebars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const api: SubMenuData = {
label: 'API',
items: [
'api/overview',
'api/hello-world',
'api/wechaty',
'api/message',
'api/contact',
Expand Down