[core] Add /messages-admin-only

fix #274
This commit is contained in:
allburov committed 2024-03-17 19:17:14 +07:00
1 parent 5a344cd8ad
commit 832ad26151
7 files changed
+117 -28

No files matched your search

@@ -156,24 +156,26 @@ please [create an issue](https://github.com/devlikeapro/whatsapp-http-api/issues
| `POST /api/contacts/block` | ✔️ | ➖ | ➖ |
| `POST /api/contacts/unblock` | ✔️ | ➖ | ➖ |
| **Groups** | WEBJS | NOWEB | VENOM |
|--------------------------------------------------------------------|:-----:|:-----:|:-----:|
| `POST /api/{session}/groups` | ✔️ | ✔️ | ➖ |
| `GET /api/{session}/groups` | ✔️ | ✔️ | ➖ |
| `GET /api/{session}/groups/{id}` | ✔️ | ✔️ | ➖ |
| `DELETE /api/{session}/groups/{id}` | ✔️ | ➖ | ➖ |
| `GET /api/{session}/groups/{id}/settings/security/info-admin-only` | ✔️ | ➖ | ➖ |
| `PUT /api/{session}/groups/{id}/settings/security/info-admin-only` | ✔️ | ➖ | ➖ |
| `POST /api/{session}/groups/{id}/leave` | ✔️ | ✔️ | ➖ |
| `PUT /api/{session}/groups/{id}/description` | ✔️ | ✔️ | ➖ |
| `PUT /api/{session}/groups/{id}/subject` | ✔️ | ✔️ | ➖ |
| `GET /api/{session}/groups/{id}/invite-code` | ✔️ | ✔️ | ➖ |
| `POST /api/{session}/groups/{id}/invite-code/revoke` | ✔️ | ✔️ | ➖ |
| `GET /api/{session}/groups/{id}/participants` | ✔️ | ✔️ | ➖ |
| `POST /api/{session}/groups/{id}/participants/add` | ✔️ | ✔️ | ➖ |
| `POST /api/{session}/groups/{id}/participants/remove` | ✔️ | ✔️ | ➖ |
| `POST /api/{session}/groups/{id}/admin/promote` | ✔️ | ✔️ | ➖ |
| `POST /api/{session}/groups/{id}/admin/demote` | ✔️ | ✔️ | ➖ |
| **Groups** | WEBJS | NOWEB | VENOM |
|------------------------------------------------------------------------|:-----:|:-----:|:-----:|
| `POST /api/{session}/groups` | ✔️ | ✔️ | ➖ |
| `GET /api/{session}/groups` | ✔️ | ✔️ | ➖ |
| `GET /api/{session}/groups/{id}` | ✔️ | ✔️ | ➖ |
| `DELETE /api/{session}/groups/{id}` | ✔️ | ➖ | ➖ |
| `GET /api/{session}/groups/{id}/settings/security/info-admin-only` | ✔️ | ➖ | ➖ |
| `PUT /api/{session}/groups/{id}/settings/security/info-admin-only` | ✔️ | ➖ | ➖ |
| `GET /api/{session}/groups/{id}/settings/security/messages-admin-only` | ✔️ | ➖ | ➖ |
| `PUT /api/{session}/groups/{id}/settings/security/messages-admin-only` | ✔️ | ➖ | ➖ |
| `POST /api/{session}/groups/{id}/leave` | ✔️ | ✔️ | ➖ |
| `PUT /api/{session}/groups/{id}/description` | ✔️ | ✔️ | ➖ |
| `PUT /api/{session}/groups/{id}/subject` | ✔️ | ✔️ | ➖ |
| `GET /api/{session}/groups/{id}/invite-code` | ✔️ | ✔️ | ➖ |
| `POST /api/{session}/groups/{id}/invite-code/revoke` | ✔️ | ✔️ | ➖ |
| `GET /api/{session}/groups/{id}/participants` | ✔️ | ✔️ | ➖ |
| `POST /api/{session}/groups/{id}/participants/add` | ✔️ | ✔️ | ➖ |
| `POST /api/{session}/groups/{id}/participants/remove` | ✔️ | ✔️ | ➖ |
| `POST /api/{session}/groups/{id}/admin/promote` | ✔️ | ✔️ | ➖ |
| `POST /api/{session}/groups/{id}/admin/demote` | ✔️ | ✔️ | ➖ |
| | WEBJS | NOWEB | VENOM |
|---------------------------------------------------|:-----:|:-----:|:-----:|
@@ -87,22 +87,47 @@ Request:
}
```
### Settings
#### Security for group info
### Security - update group info
Updates the group settings to only allow admins to edit group info (title, description, photo).
`PUT /api/{session}/groups/{groupId}/settings/security/info-admin-only`
```json
{
"adminsOnly": true
}
```
Get the group settings to only allow admins to edit group info (title, description, photo).
`GET /api/{session}/groups/{groupId}/settings/security/info-admin-only`
```json
{
"adminsOnly": true
}
```
`PUT /api/{session}/groups/{groupId}/settings/security/info-admin-only`
The request doesn't require any request's body and
**can't be used to disable the security setting (allow ANY to edit group info)**.
If you wish to have that ability - please [create an issue](https://github.com/devlikeapro/whatsapp-http-api/issues)
Returns `true` if the setting was properly updated. This can return false if the user does not have the necessary permissions.
### Security - who can send messages
Updates the group settings to only allow admins to send messages.
`PUT /api/{session}/groups/{groupId}/settings/security/messages-admin-only`
```json
{
"adminsOnly": true
}
```
Returns `true` if the setting was properly updated. This can return false if the user does not have the necessary permissions.
Get the group settings to only allow admins to send messages.
`GET /api/{session}/groups/{groupId}/settings/security/messages-admin-only`
```json
{
"adminsOnly": true
}
```
### Participants
#### Get participants
@@ -21,7 +21,17 @@ You even can **subscribe to get new updates** there!
## 2024.3
- Add [message.reaction]({{< relref "/docs/how-to/webhooks#messagereaction" >}}) webhook in **WEBJS** and **NOWEB** engines ([#275](https://github.com/devlikeapro/whatsapp-http-api/issues/275)).
- 👉 **NOWEB** engine note - reactions were sent in `'message'` and `'message.any'` events, not it's available **only** in `'message.reaction'`!
- **NOWEB** engine note - reactions were sent in `'message'` and `'message.any'` events, not it's available **only** in `'message.reaction'`!
- Add security settings [Security - who can send messages]({{< relref "/docs/how-to/groups##security---who-can-send-messages" >}}) `PUT /api/{session}/groups/{groupId}/settings/security/messages-admin-only` ([#274](https://github.com/devlikeapro/whatsapp-http-api/issues/274))
### 👉 Breaking changes
- **NOWEB** - reactions were sent in `'message'` and `'message.any'` events, not it's available **only** in `'message.reaction'`!
- Add **required body** in `PUT /api/{session}/groups/{groupId}/settings/security/info-admin-only` endpoint.
```json
{
"adminsOnly": false
}
```
## 2024.2
- Add support for [MongoDB as storage for Session data]({{< relref "/docs/how-to/storages" >}})
+30 -2
View File
@@ -11,6 +11,7 @@ import { ApiOperation, ApiSecurity, ApiTags } from '@nestjs/swagger';
import { SessionManager } from '../core/abc/manager.abc';
import { WhatsappSession } from '../core/abc/session.abc';
import { MessageContactVcardRequest } from '../structures/chatting.dto';
import {
CreateGroupRequest,
DescriptionRequest,
@@ -56,11 +57,12 @@ export class GroupsController {
summary:
'Updates the group settings to only allow admins to edit group info (title, description, photo).',
})
setGroupAdminOnly(
setInfoAdminOnly(
@SessionParam session: WhatsappSession,
@Param('id') id: string,
@Body() request: SettingsSecurityChangeInfo,
) {
return session.setInfoAdminsOnly(id, true);
return session.setInfoAdminsOnly(id, request.adminsOnly);
}
@Get(':id/settings/security/info-admin-only')
@@ -76,6 +78,32 @@ export class GroupsController {
return session.getInfoAdminsOnly(id);
}
@Put(':id/settings/security/messages-admin-only')
@SessionApiParam
@ApiOperation({
summary:
'Updates the group settings to only allow admins to send messages.',
})
setMessagesAdminOnly(
@SessionParam session: WhatsappSession,
@Param('id') id: string,
@Body() request: SettingsSecurityChangeInfo,
) {
return session.setMessagesAdminsOnly(id, request.adminsOnly);
}
@Get(':id/settings/security/messages-admin-only')
@SessionApiParam
@ApiOperation({
summary: 'Gets the group settings to only allow admins to send messages.',
})
getMessagesAdminOnly(
@SessionParam session: WhatsappSession,
@Param('id') id: string,
): Promise<SettingsSecurityChangeInfo> {
return session.getMessagesAdminsOnly(id);
}
@Delete(':id')
@SessionApiParam
@ApiOperation({ summary: 'Delete the group.' })
+8
View File
@@ -338,6 +338,14 @@ export abstract class WhatsappSession {
throw new NotImplementedByEngineError();
}
public getMessagesAdminsOnly(id): Promise<SettingsSecurityChangeInfo> {
throw new NotImplementedByEngineError();
}
public setMessagesAdminsOnly(id, value) {
throw new NotImplementedByEngineError();
}
public deleteGroup(id) {
throw new NotImplementedByEngineError();
}
@@ -381,6 +381,7 @@ export class WhatsappSessionWebJSCore extends WhatsappSession {
public async getInfoAdminsOnly(id): Promise<SettingsSecurityChangeInfo> {
const groupChat = (await this.whatsapp.getChatById(id)) as GroupChat;
return {
// Undocumented property, can be changed in the future
// @ts-ignore
adminsOnly: groupChat.groupMetadata.restrict,
};
@@ -391,6 +392,21 @@ export class WhatsappSessionWebJSCore extends WhatsappSession {
return groupChat.setInfoAdminsOnly(value);
}
public async getMessagesAdminsOnly(id): Promise<SettingsSecurityChangeInfo> {
const groupChat = (await this.whatsapp.getChatById(id)) as GroupChat;
// @ts-ignore
return {
// Undocumented property, can be changed in the future
// @ts-ignore
adminsOnly: groupChat.groupMetadata.announce,
};
}
public async setMessagesAdminsOnly(id, value) {
const groupChat = (await this.whatsapp.getChatById(id)) as GroupChat;
return groupChat.setMessagesAdminsOnly(value);
}
public getGroups() {
return this.whatsapp
.getChats()
+1 -1
View File
@@ -9,7 +9,7 @@ export class Participant {
}
export class SettingsSecurityChangeInfo {
adminsOnly: boolean;
adminsOnly: boolean = true;
}
/**