zaileys 1.1.29 → 1.1.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +300 -125
- package/dist/index.d.mts +1709 -510
- package/dist/index.d.ts +1709 -510
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/examples/citation.ts +25 -0
- package/examples/limiter.ts +23 -0
- package/examples/llms.ts +37 -0
- package/examples/simple.ts +16 -0
- package/examples/speech.ts +38 -0
- package/examples/webhooks.ts +37 -0
- package/package.json +5 -2
package/examples/llms.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import Groq from "groq-sdk";
|
|
2
|
+
|
|
3
|
+
import { Client } from "../src";
|
|
4
|
+
// import { Client } from "zaileys";
|
|
5
|
+
|
|
6
|
+
const groq = new Groq({ apiKey: "YOUR_GROQ_APIKEY" });
|
|
7
|
+
|
|
8
|
+
const wa = new Client({
|
|
9
|
+
authType: "qr", // has issue with pairing code, just use qr only
|
|
10
|
+
loadLLMSchemas: true, // this option must be activated!
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
wa.on("messages", async (ctx) => {
|
|
14
|
+
const { channelId, uniqueId, roomId, text } = ctx;
|
|
15
|
+
|
|
16
|
+
if (text == "clear") {
|
|
17
|
+
await wa.llms.clearCompletions(channelId);
|
|
18
|
+
await wa.text("History clear!", { roomId });
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const histories = await wa.llms.getCompletions(channelId);
|
|
23
|
+
const model = await groq.chat.completions.create({
|
|
24
|
+
messages: [
|
|
25
|
+
{ role: "system", content: "You are 'Zaileys AI' a helpful assistant speak indonesian." },
|
|
26
|
+
...(histories.map((x) => ({ role: x.role, content: x.content })) as never),
|
|
27
|
+
{ role: "user", content: text || "" },
|
|
28
|
+
],
|
|
29
|
+
model: "llama-3.3-70b-versatile",
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const output = model.choices[0]?.message?.content || "";
|
|
33
|
+
const ai = await wa.text(output, { roomId });
|
|
34
|
+
|
|
35
|
+
await wa.llms.addCompletion({ channelId, uniqueId, role: "user", content: text || "" });
|
|
36
|
+
await wa.llms.addCompletion({ channelId, uniqueId: ai?.uniqueId || "", role: "assistant", content: output });
|
|
37
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Client } from "../src";
|
|
2
|
+
// import { Client } from "zaileys";
|
|
3
|
+
|
|
4
|
+
const wa = new Client({
|
|
5
|
+
authType: "qr", // has issue with pairing code, just use qr only
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
wa.on("messages", (ctx) => {
|
|
9
|
+
wa.text("Hello!", { roomId: ctx.roomId });
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
wa.on("calls", (ctx) => {
|
|
13
|
+
if (ctx.status == "terminate") {
|
|
14
|
+
wa.text("Why call me!?", { roomId: ctx.roomId });
|
|
15
|
+
}
|
|
16
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { createPartFromUri, createUserContent, GoogleGenAI } from "@google/genai";
|
|
2
|
+
|
|
3
|
+
import { Client } from "../src";
|
|
4
|
+
// import { Client } from "zaileys";
|
|
5
|
+
|
|
6
|
+
const agent = new GoogleGenAI({ apiKey: "AIzaSyCE8ml8-tcfXVChsfYiqR-Z1W1ovHZSIh8" });
|
|
7
|
+
|
|
8
|
+
const wa = new Client({
|
|
9
|
+
authType: "qr", // has issue with pairing code, just use qr only
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
wa.on("messages", async (ctx) => {
|
|
13
|
+
if (ctx.chatType != "audio") return;
|
|
14
|
+
|
|
15
|
+
const buffer = await ctx.media?.buffer();
|
|
16
|
+
const stream = new File([buffer || ""], "voice.ogg", { type: "audio/ogg" });
|
|
17
|
+
|
|
18
|
+
const uploaded = await agent.files.upload({
|
|
19
|
+
file: stream,
|
|
20
|
+
config: { mimeType: "audio/ogg" },
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const speech = await agent.models
|
|
24
|
+
.generateContent({
|
|
25
|
+
model: "gemini-2.0-flash-001",
|
|
26
|
+
contents: createUserContent([{ text: "Please transcribe this audio:" }, createPartFromUri(uploaded.uri!, uploaded.mimeType!)]),
|
|
27
|
+
})
|
|
28
|
+
.then((x) => x.candidates?.[0].content?.parts?.[0].text || "");
|
|
29
|
+
|
|
30
|
+
const answer = await agent.models
|
|
31
|
+
.generateContent({
|
|
32
|
+
model: "gemini-2.0-flash-001",
|
|
33
|
+
contents: speech,
|
|
34
|
+
})
|
|
35
|
+
.then((x) => x.candidates?.[0].content?.parts?.[0].text || "");
|
|
36
|
+
|
|
37
|
+
await wa.text(answer, { roomId: ctx.roomId });
|
|
38
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Client } from "../src";
|
|
2
|
+
// import { Client } from "zaileys";
|
|
3
|
+
|
|
4
|
+
const wa = new Client({
|
|
5
|
+
authType: "qr", // has issue with pairing code, just use qr only
|
|
6
|
+
webhooks: {
|
|
7
|
+
url: "https://...", // An event triggers a call to the webhook url
|
|
8
|
+
},
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
/*
|
|
12
|
+
✔ Webhooks Access
|
|
13
|
+
- URL : http://xxx.xxx.x.xxx:4135/webhooks
|
|
14
|
+
- PORT : 4135
|
|
15
|
+
- METHOD: GET, POST
|
|
16
|
+
|
|
17
|
+
hit to "URL" with data to be captured by "webhooks" event
|
|
18
|
+
example:
|
|
19
|
+
|
|
20
|
+
await fetch("http://xxx.xxx.x.xxx:4135/webhooks?test1=hello&test2=world", {
|
|
21
|
+
method: "POST", // optional (GET & POST only)
|
|
22
|
+
body: JSON.stringify({ testingBody: "OK", yourData: "test1" })
|
|
23
|
+
})
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
wa.on("webhooks", (ctx) => {
|
|
27
|
+
// passing search params
|
|
28
|
+
console.log(ctx.data.query); // { test1: "hello", test2: "world" }
|
|
29
|
+
|
|
30
|
+
// passing body
|
|
31
|
+
console.log(ctx.data.json); // { testingBody: "OK", yourData: "test1" }
|
|
32
|
+
|
|
33
|
+
// lets explore
|
|
34
|
+
console.log(ctx)
|
|
35
|
+
console.log(ctx.data.form)
|
|
36
|
+
console.log(ctx.data.raw)
|
|
37
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zaileys",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.31",
|
|
4
4
|
"description": "Zaileys - Simplified WhatsApp Node.js API",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
},
|
|
15
15
|
"scripts": {
|
|
16
16
|
"build": "tsup",
|
|
17
|
-
"dev": "tsx watch
|
|
17
|
+
"dev": "tsx watch examples/speech.ts",
|
|
18
18
|
"clean": "rm -rf dist session"
|
|
19
19
|
},
|
|
20
20
|
"keywords": [
|
|
@@ -61,11 +61,14 @@
|
|
|
61
61
|
"zod": "^3.24.4"
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
|
+
"@hono/node-server": "^1.14.4",
|
|
64
65
|
"baileys": "^6.7.18",
|
|
65
66
|
"better-sqlite3": "^11.10.0",
|
|
67
|
+
"bottleneck": "^2.19.5",
|
|
66
68
|
"events": "^3.3.0",
|
|
67
69
|
"fast-levenshtein": "^3.0.0",
|
|
68
70
|
"figlet": "^1.8.1",
|
|
71
|
+
"hono": "^4.7.11",
|
|
69
72
|
"jimp": "^0.16.1",
|
|
70
73
|
"kysely": "^0.28.2",
|
|
71
74
|
"mysql2": "^3.14.1",
|