-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
36 lines (29 loc) · 884 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const Wechaty = require("wechaty");
const axios = require("axios");
require("dotenv").config();
const { PuppetXp } = require("wechaty-puppet-xp");
const puppet = new PuppetXp();
const { WechatyBuilder } = Wechaty;
const matchReg = new RegExp(process.env.MATCH_REG);
const bot = WechatyBuilder.build({
puppet: puppet,
name: "bot",
});
bot.on("message", async (msg) => {
if (msg.type != Wechaty.types.Message.Text) {
return;
}
let text = msg.text();
console.log(text);
if (process.env.REMOTE_API && matchReg.test(text)) {
try {
await axios.post(process.env.REMOTE_API, { text });
console.log("------sended");
let { message } = await res.json();
msg.say("线索已收录");
} catch (error) {
console.error(error);
}
}
});
bot.start().catch(console.error);