An open API service indexing awesome lists of open source software.

https://github.com/fitri-hy/fhytsbot

FhytsBot is a WhatsApp bot built on the FhyTS Framework, a modular framework for building a variety of applications quickly and in a structured manner.
https://github.com/fitri-hy/fhytsbot

fhyts wabot webhook webhook-api whatsapp whatsapp-bot

Last synced: 3 months ago
JSON representation

FhytsBot is a WhatsApp bot built on the FhyTS Framework, a modular framework for building a variety of applications quickly and in a structured manner.

Awesome Lists containing this project

README

          

# FhytsBot-MD Starter Kit

FhytsBot is a WhatsApp bot built on the [FhyTS Framework](https://fhyts.fhylabs.com/), a modular framework for building a variety of applications quickly and in a structured manner.

## Reference API

An explanation of the data structures and properties used to form WhatsApp messages.

| Properti | Tipe | Deskripsi |
| ----------------- | -------------------------------------------------------- | ------------------------------- |
| `text` | `string` | Body of text message |
| `image` | `string`, `Buffer` | Image path or buffer |
| `video` | `string`, `Buffer` | Video path or buffer |
| `audio` | `string`, `Buffer` | Document path or buffer |
| `caption` | `string` | Additional text on media |
| `quoted` | `IWebMessageInfo` | Message to be replied |
| `sticker` | `string`, `Buffer` | `.webp` image as sticker |
| `location` | `{ degreesLatitude, degreesLongitude, name?, address? }` | Location |
| `contact` | `{ displayName, vcard }` | Single vCard contact |
| `mode` | `false`, `ads` ,`forward` | Automatic contextInfo mode |
| `contextOverride` | `CtxInfo(...)` | Custom contextInfo manual |
| `extra` | `Partial` | Additional optional content |
| `ptt` | `boolean` | Is audio as voice note |
| `forwardingScore` | `number` | Forward score (mode: 'forward') |
| `mentions` | `string[]` | Array of JIDs to be mentioned/tagged

## Plugin Structure

Basic example of plugin handler structure in FhytsBot to respond to incoming messages.

```javascript
import { readFileSync } from 'fs';
import { join } from 'path';
import type { WASocket, proto } from 'baileys';
import { createMessenger, CtxInfo } from '../helpers/context';
type IWebMessageInfo = proto.IWebMessageInfo;

export async function handle(sock: WASocket, message: IWebMessageInfo, text: string) {
if (!text.startsWith('.text')) return;
const jid = message.key.remoteJid!;
const m = createMessenger(sock, jid, message);

// Message Handling

}

export const mode = 'both'; // Optional: 'self', 'others', or 'both'
export const device = 'all'; // Optional: `['device1', 'device1']` (connected device).
```

## Message Handling

A collection of examples of how to send various types of messages such as text, media, documents, locations, and more.

### Text

```javascript
await m.send({
text: 'This is a text message!',
});
```

### Image

```javascript
await m.send({
image: join(__dirname, '../assets/test.webp'),
caption: 'This is a image message!',
});
```

### Audio

```javascript
await m.send({
audio: join(__dirname, '../assets/test.mp3'),
ptt: false,
});
```

### Video

```javascript
await m.send({
video: join(__dirname, '../assets/test.mp4'),
caption: 'This is a video message!',
});
```

### Document

```javascript
await m.send({
document: join(__dirname, '../assets/test.pdf'),
extra: {
fileName: 'Example.pdf',
caption: 'This is a document message!',
},
});
```

### Location

```javascript
await m.send({
location: {
degreesLatitude: 40.7128,
degreesLongitude: -74.0060,
name: 'Statue of Liberty',
address: 'New York, NY 10004, USA',
},
});
```

### Sticker

```javascript
await m.send({
sticker: readFileSync(join(__dirname, '../assets/test.webp')),
});
```

### Mention

```javascript
await m.send({
text: 'Hello, you are mentioned!',
mentions: ['628123456789@s.whatsapp.net'],
});
```

### Reaction
```javascript
await m.react('🤖');
```

### vCard

```javascript
await m.send({
contact: {
displayName: 'Example Support',
vcard: `BEGIN:VCARD
VERSION:3.0
N:Doe;Jane;;;
FN:Jane Doe
ORG:Example Corp.
TITLE:Customer Support
TEL;TYPE=CELL;TYPE=VOICE;waid=12345678901:+1 234-567-8901
TEL;TYPE=WORK:+1 800-123-4567
EMAIL:jane.doe@example.com
URL:https://example.com
ADR:;;123 Main St;Springfield;IL;62704;USA
BDAY:1985-05-15
NOTE:Official support contact
END:VCARD`,
},
});
```

### Custom Context Info

```javascript
await m.send({
text: 'Custom context info with forwarding',
quoted: message,
contextOverride: CtxInfo({
mode: 'forward',
forwardingScore: 10,
title: 'FhytsBot',
body: 'This is a body CtxInfo!',
sourceUrl: 'https://fhylabs.com',
thumbnailPath: join(__dirname, '../assets/test.webp'),
renderLargerThumbnail: true, // true,false
mediaType: 1, // 1,2,3
}),
});
```

### Delete

```javascript
await m.delete();
// or
await m.delete({
fromMe: true
})
// or
await m.delete({
id: 'ABC123DEF456', // id of the message to be deleted
fromMe: false, // messages from other people (false) or from bots (true)
participant: '628123456789@s.whatsapp.net', // group only, send message sender
});
```

### Remove (Group)

```javascript
await m.group('remove', [
'628123456789@s.whatsapp.net'
]);
```

### Add (Group)

```javascript
await m.group('add', [
'628123456789@s.whatsapp.net'
]);
```

### Promote (Group)

```javascript
await m.group('promote', [
'628123456789@s.whatsapp.net'
]);
```

### Demote (Group)

```javascript
await m.group('demote', [
'628123456789@s.whatsapp.net'
]);
```

### Info (Group)

```javascript
await m.group('info', {
title: 'New group name',
description: 'New group description',
image: readFileSync(join(__dirname, '../assets/test.webp')), // Group profile picture
restrict: true // Only admins can discuss (`true`|`false`)
});
```

## Global Handling

FhytsBot has a global rules system that can be fully customized to suit your usage needs. These rules are comprehensive and will apply to all active sessions/devices in the system.

```json
{
"port": 3000,
"sessions": ["default"],
"globalReply": "self",
"globalLogging": false,
"globalGreeting": false
}
```

| Property | Type | Description |
| ---------------- | ------- | --------------------------------------------------------------------------- |
| `port` | Number | The port the server uses when running. |
| `sessions` | Array | List of session names (devices). `["device1", "device2", "other"]`. |
| `globalReply` | String | Determines how the bot replies to messages. `"self"`, `"others"`, `"both"`. |
| `globalLogging` | Boolean | Turn global logging on or off for all sessions. |
| `globalGreeting` | Boolean | Enable or disable automatic welcome messages.

## Webhook API

Endpoint HTTP (POST `/webhook`) yang memungkinkan pengiriman pesan WhatsApp secara eksternal, tanpa melalui plugin.
Mendukung format JSON dan form-data, cocok untuk integrasi dengan sistem lain seperti webhook, scheduler, atau layanan eksternal.

### Request Body Fields

| Field | Required | Format | Description |
| ---------- | -------- | ------------------- | ---------------------------------------------------------------------------------------------- |
| `sessionId`| ✅ | `string` | Active WhatsApp session ID |
| `jid` | ✅ | `string` | Target WhatsApp number, e.g. `6281234567890` (without `@s.whatsapp.net`) |
| `type` | ✅ | `string` | Message type: `text`, `image`, `audio`, `video`, `document`, `sticker`, `location` |
| `content` | ❌ | `string` / `object` | Message content: plain text, URL, or an object depending on the message `type` |
| `caption` | ❌ | `string` | Caption for media messages (`image`, `video`, `document`) |
| `fileName` | ❌ | `string` | File name for document messages (only used when `type=document`) |

### Endpoint

```bash
POST /webhook
Method: POST
Headers: Content-Type: application/json
```

### Text

Body Json:

```json
{
"sessionId": "default",
"jid": "6281234567890",
"type": "text",
"content": "Hello from Webhook!"
}
```

### Image

Body Json:

```json
{
"sessionId": "default",
"jid": "6281234567890",
"type": "image",
"content": "https://example.com/image.jpg",
"caption": "Image from URL"
}
```

### Audio

Body Json:

```json
{
"sessionId": "default",
"jid": "6281234567890",
"type": "audio",
"content": "https://example.com/audio.mp3"
}
```

### Video

Body Json:

```json
{
"sessionId": "default",
"jid": "6281234567890",
"type": "video",
"content": "https://example.com/video.mp4",
"caption": "Video from URL"
}
```

### Document

Body Json:

```json
{
"sessionId": "default",
"jid": "6281234567890",
"type": "document",
"content": "https://example.com/file.pdf",
"caption": "Document from URL",
"fileName": "example.pdf"
}
```

### Sticker

Body Json:

```json
{
"sessionId": "default",
"jid": "6281234567890",
"type": "sticker",
"content": "https://example.com/sticker.webp"
}
```

### Location

Body Json:

```json
{
"sessionId": "default",
"jid": "6281234567890",
"type": "location",
"content": {
"latitude": -6.200000,
"longitude": 106.816666,
"name": "Monas",
"address": "Jakarta, Indonesia"
}
}
```