Skip to content

Commit

Permalink
feat: changes and new functions
Browse files Browse the repository at this point in the history
  • Loading branch information
jonalan7 committed Dec 11, 2024
1 parent 4a4e637 commit 2aea280
Show file tree
Hide file tree
Showing 33 changed files with 922 additions and 475 deletions.
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const fs = require('fs');

(async () => {
let client;
let checkConnect = false;
// start bot service
const ev = await hydraBot.initServer();

Expand All @@ -104,7 +105,8 @@ const fs = require('fs');
}

// Was connected to whatsapp chat
if (conn.connect) {
if (conn.connect && !checkConnect) {
checkConnect = true;
client = conn.client; // class client from hydra-bot
const getMe = await client.getHost();
const hostNumber = getMe.id._serialized; // number host
Expand Down Expand Up @@ -539,13 +541,29 @@ const contacts = await client.getAllContacts();

// return whatsapp version
const version = await client.getWAVersion();

// Load all messages in chat by date
const listMsg = await client.loadAndGetAllMessagesInChat(
'<phone Number>@c.us',
'YYYY-MM-DD'
);
```

## Group Management

Group number example `<phone Number>-<groupId>@g.us` or `<phone Number><groupId>@g.us`

```javascript
// get all participants in the group
await client
.getGroupParticipant('[email protected]')
.then((result) => {
console.log('Participants: ', result);
})
.catch((error) => {
console.log('Error Participants: ', error);
});

// Get all Group
const allGroups = await client.getAllChatsGroups();

Expand Down
34 changes: 34 additions & 0 deletions docs/getting-started/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@
To use these functions, it is necessary to initialize the bot.
[**Click here to learn more.**](../Getting%20Started/start_bot.html)

## Events:
The **Hydra-Bot** uses asynchronous events to provide clearer understanding and streamline workflows.
You can listen for information on each aspect separately.
For example:
- Receive information about the **QR code**;
- Monitor the browser interface to determine if the bot is on the chat page, syncing, or facing conflicts, among other states;
- Obtain data about the connection status, such as whether it's **connected** or **disconnected**;
and much more!

## Summary
- [interfaceChange](#interfaceChange)
- [qrcode](#qrcode)
Expand All @@ -19,6 +28,18 @@ To use these functions, it is necessary to initialize the bot.
Event triggered when there's a change in the WhatsApp interface

```javascript
// The "interfaceChange" event can return the following interface states:
// QR - QR code page.
// MAIN - Chat page.
// CONNECTION - Connection.
// SYNCING - Loading page, waiting for data from the smartphone.
// OFFLINE - Offline page, when there is no internet connection.
// CONFLICT - Conflict page, when another WhatsApp Web session is open.
// PROXYBLOCK - Blocked page due to proxy restrictions.
// TOS_BLOCK - Blocked page (Terms of Service violation).
// SMB_TOS_BLOCK - Blocked page (Terms of Service violation for SMB users).
// DEPRECATED_VERSION - Deprecated version page.

// The change information can include elements like screen changes or navigation.
ev.on("interfaceChange", (change: any) => {
// Processes the interface change, like navigation between screens
Expand Down Expand Up @@ -102,6 +123,19 @@ Event triggered to return the status of each message (e.g., read, delivered, etc
```javascript
// This can include data such as delivery and read status, allowing message state tracking.
ev.on("newOnAck", async (event) => {
// To monitor the status of each message, the following parameters can be returned:
// SENDER_BACKFILL_SENT: -7 // Message sent after a backfill by the sender.
// INACTIVE_RECEIVED: -6 // Message received but not active.
// CONTENT_UNUPLOADABLE: -5 // Message content could not be uploaded.
// CONTENT_TOO_BIG: -4 // Message content exceeds the size limit.
// CONTENT_GONE: -3 // Message content is no longer available.
// EXPIRED: -2 // Message expired and cannot be delivered.
// FAILED: -1 // Message delivery failed.
// CLOCK: 0 // Message is pending (waiting to be sent).
// SENT: 1 // Message has been sent.
// RECEIVED: 2 // Message has been received.
// READ: 3 // Message has been read.
// PLAYED: 4 // Media message has been played.
// Processes the acknowledgment status of the message
console.log("Message ack status:", event);
});
Expand Down
15 changes: 15 additions & 0 deletions docs/getting-started/group_functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ To use these functions, it is necessary to initialize the bot.
- [addParticipant](#addparticipant)
- [setGroupDescription](#setgroupdescription)
- [setGroupImage](#setgroupimage)
- [getGroupParticipant](#getGroupParticipant)

### Retrieve all groups

Expand Down Expand Up @@ -77,4 +78,18 @@ await client.setGroupImage('[email protected]', './file.jpg')
});
```

### getGroupParticipant

Get all participants in the group

```javascript
await client
.getGroupParticipant('[email protected]')
.then((result) => {
console.log('Participants: ', result);
})
.catch((error) => {
console.log('Error Participants: ', error);
});
```

9 changes: 9 additions & 0 deletions docs/getting-started/retrieving_data.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ To use these functions, it is necessary to initialize the bot.
## Summary
- [getAllContacts](#getallcontacts)
- [checkNumber](#checknumber)
- [loadAndGetAllMessagesInChat](#loadAndGetAllMessagesInChat)

### getAllContacts

Expand All @@ -18,7 +19,15 @@ const contacts = await client.getAllContacts();
```

### checkNumber

Check if the number exists
```javascript
const result = await client.checkNumber("<phone Number>@c.us");
```

### loadAndGetAllMessagesInChat

Load all messages in chat by date
```javascript
const result = await client.loadAndGetAllMessagesInChat("<phone Number>@c.us", "YYYY-MM-DD");
```
4 changes: 3 additions & 1 deletion docs/getting-started/start_bot.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const hydraBot = require('hydra-bot');

(async () => {
let client;
let checkConnect = false;
// start bot service
const ev = await hydraBot.initServer();

Expand All @@ -29,7 +30,8 @@ const hydraBot = require('hydra-bot');
}

// Was connected to whatsapp chat
if (conn.connect) {
if (conn.connect && !checkConnect) {
checkConnect = true;
client = conn.client; // class client from hydra-bot
const getMe = await client.getHost();
const hostNumber = getMe.id._serialized; // number host
Expand Down
35 changes: 11 additions & 24 deletions src/webpack/@types/API.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// Importações organizadas por categoria

// Interfaces
import {
InterfaceHost,
Expand All @@ -9,80 +7,66 @@ import {
ReactionIntro,
} from '../model/interface';

// Funcionalidades específicas
import { interfaceChange } from '../model/interface/interface-change';
import { FunctionsLayer, FunctionParameters } from '../model/enum';

// Declaração da interface API organizada por categoria
interface API {
// Mensagens
/**
* Send a message to a contact or group
*/
sendMessage: (to: string, body: string, options: object) => Promise<any>;

/**
* Serialize a message object
*/
serializeMessageObj: (msg: object) => Promise<void>;

// Contatos
/**
* Returns a list of all contacts
*/
getAllContacts: () => Promise<contact>;

// Grupos
/**
* Get all chat groups
*/
getAllChatsGroups: () => Promise<any>;

/**
* Get group participants
*/
getGroupParticipant: (groupId: string) => Promise<any>;
/**
* Creates a new chat group
*/
createGroup: (
groupName: string,
contacts: string | string[]
) => Promise<InterfaceScope>;

/**
* Add participants to a group
*/
addParticipant: (
groupId: string,
contacts: string | string[]
) => Promise<InterfaceScope>;

/**
* Set the group description
*/
setGroupDescription: (
groupId: string,
description: string
) => Promise<InterfaceScope>;

/**
* Set the group image
*/
setGroupImage: (path: object, to: string) => Promise<InterfaceScope>;

// Host e números
/**
* Get information about the connected number
*/
getHost: () => Promise<InterfaceHost>;

/**
* Check if a number exists
*/
checkNumberStatus: (number: string) => Promise<checkNumber>;

// Versão e reações
/**
* Get the current WhatsApp version
*/
getWAVersion: () => Promise<string>;

/**
* Serialize reactions
*/
Expand All @@ -91,14 +75,19 @@ interface API {
collections: object,
type: object
) => Promise<object[]>;

/**
* Serialize intro reactions
*/
serializeIntroReactions: (
emoji: object,
type: object
) => Promise<ReactionIntro | []>;
/**
* Load and get all messages in a chat
*/
loadAndGetAllMessagesInChat: (chatId: string, date: string) => Promise<any>;

[key: string]: (...args: any[]) => any;
}

// Declaração global organizada
Expand All @@ -119,5 +108,3 @@ declare global {

const API: API;
}

export {};
Loading

0 comments on commit 2aea280

Please sign in to comment.