mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-16 12:12:55 -06:00
feat: Route to update the privacy settings
This commit is contained in:
parent
55e36f24a5
commit
ab28b4c0c5
@ -6,6 +6,7 @@
|
|||||||
* Added conversion of audios for sending recorded audio, now it is possible to send mp3 audios and not just ogg
|
* Added conversion of audios for sending recorded audio, now it is possible to send mp3 audios and not just ogg
|
||||||
* Route to fetch all groups that the connection is part of
|
* Route to fetch all groups that the connection is part of
|
||||||
* Route to fetch all privacy settings
|
* Route to fetch all privacy settings
|
||||||
|
* Route to update the privacy settings
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
@ -408,6 +408,36 @@ export const readMessageSchema: JSONSchema7 = {
|
|||||||
required: ['readMessages'],
|
required: ['readMessages'],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const privacySettingsSchema: JSONSchema7 = {
|
||||||
|
$id: v4(),
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
privacySettings: {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
readreceipts: { type: 'string', enum: ['all', 'none'] },
|
||||||
|
profile: {
|
||||||
|
type: 'string',
|
||||||
|
enum: ['all', 'contacts', 'contact_blacklist', 'none'],
|
||||||
|
},
|
||||||
|
status: {
|
||||||
|
type: 'string',
|
||||||
|
enum: ['all', 'contacts', 'contact_blacklist', 'none'],
|
||||||
|
},
|
||||||
|
online: { type: 'string', enum: ['all', 'match_last_seen'] },
|
||||||
|
last: { type: 'string', enum: ['all', 'contacts', 'contact_blacklist', 'none'] },
|
||||||
|
groupadd: {
|
||||||
|
type: 'string',
|
||||||
|
enum: ['all', 'contacts', 'contact_blacklist', 'none'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
required: ['readreceipts', 'profile', 'status', 'online', 'last', 'groupadd'],
|
||||||
|
...isNotEmpty('readreceipts', 'profile', 'status', 'online', 'last', 'groupadd'),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
required: ['privacySettings'],
|
||||||
|
};
|
||||||
|
|
||||||
export const archiveChatSchema: JSONSchema7 = {
|
export const archiveChatSchema: JSONSchema7 = {
|
||||||
$id: v4(),
|
$id: v4(),
|
||||||
type: 'object',
|
type: 'object',
|
||||||
|
@ -3,6 +3,7 @@ import {
|
|||||||
ArchiveChatDto,
|
ArchiveChatDto,
|
||||||
DeleteMessage,
|
DeleteMessage,
|
||||||
NumberDto,
|
NumberDto,
|
||||||
|
PrivacySettingDto,
|
||||||
ProfileNameDto,
|
ProfileNameDto,
|
||||||
ProfilePictureDto,
|
ProfilePictureDto,
|
||||||
ProfileStatusDto,
|
ProfileStatusDto,
|
||||||
@ -67,6 +68,13 @@ export class ChatController {
|
|||||||
return await this.waMonitor.waInstances[instanceName].fetchPrivacySettings();
|
return await this.waMonitor.waInstances[instanceName].fetchPrivacySettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async updatePrivacySettings(
|
||||||
|
{ instanceName }: InstanceDto,
|
||||||
|
data: PrivacySettingDto,
|
||||||
|
) {
|
||||||
|
return await this.waMonitor.waInstances[instanceName].updatePrivacySettings(data);
|
||||||
|
}
|
||||||
|
|
||||||
public async getBusinessProfile(
|
public async getBusinessProfile(
|
||||||
{ instanceName }: InstanceDto,
|
{ instanceName }: InstanceDto,
|
||||||
data: ProfilePictureDto,
|
data: ProfilePictureDto,
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import { WAPrivacyOnlineValue, WAPrivacyValue, WAReadReceiptsValue } from "@evolution/base";
|
||||||
|
|
||||||
export class OnWhatsAppDto {
|
export class OnWhatsAppDto {
|
||||||
constructor(
|
constructor(
|
||||||
public readonly jid: string,
|
public readonly jid: string,
|
||||||
@ -47,6 +49,19 @@ export class ArchiveChatDto {
|
|||||||
archive: boolean;
|
archive: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class PrivacySetting {
|
||||||
|
readreceipts: WAReadReceiptsValue;
|
||||||
|
profile: WAPrivacyValue;
|
||||||
|
status: WAPrivacyValue;
|
||||||
|
online: WAPrivacyOnlineValue;
|
||||||
|
last: WAPrivacyValue;
|
||||||
|
groupadd: WAPrivacyValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class PrivacySettingDto {
|
||||||
|
privacySettings: PrivacySetting;
|
||||||
|
}
|
||||||
|
|
||||||
export class DeleteMessage {
|
export class DeleteMessage {
|
||||||
id: string;
|
id: string;
|
||||||
fromMe: boolean;
|
fromMe: boolean;
|
||||||
|
@ -5,6 +5,7 @@ import {
|
|||||||
deleteMessageSchema,
|
deleteMessageSchema,
|
||||||
messageUpSchema,
|
messageUpSchema,
|
||||||
messageValidateSchema,
|
messageValidateSchema,
|
||||||
|
privacySettingsSchema,
|
||||||
profileNameSchema,
|
profileNameSchema,
|
||||||
profilePictureSchema,
|
profilePictureSchema,
|
||||||
profileStatusSchema,
|
profileStatusSchema,
|
||||||
@ -15,6 +16,7 @@ import {
|
|||||||
ArchiveChatDto,
|
ArchiveChatDto,
|
||||||
DeleteMessage,
|
DeleteMessage,
|
||||||
NumberDto,
|
NumberDto,
|
||||||
|
PrivacySettingDto,
|
||||||
ProfileNameDto,
|
ProfileNameDto,
|
||||||
ProfilePictureDto,
|
ProfilePictureDto,
|
||||||
ProfileStatusDto,
|
ProfileStatusDto,
|
||||||
@ -150,6 +152,17 @@ export class ChatRouter extends RouterBroker {
|
|||||||
|
|
||||||
return res.status(HttpStatus.OK).json(response);
|
return res.status(HttpStatus.OK).json(response);
|
||||||
})
|
})
|
||||||
|
.put(this.routerPath('updatePrivacySettings'), ...guards, async (req, res) => {
|
||||||
|
const response = await this.dataValidate<PrivacySettingDto>({
|
||||||
|
request: req,
|
||||||
|
schema: privacySettingsSchema,
|
||||||
|
ClassRef: PrivacySettingDto,
|
||||||
|
execute: (instance, data) =>
|
||||||
|
chatController.updatePrivacySettings(instance, data),
|
||||||
|
});
|
||||||
|
|
||||||
|
return res.status(HttpStatus.CREATED).json(response);
|
||||||
|
})
|
||||||
.post(this.routerPath('getBusinessProfile'), ...guards, async (req, res) => {
|
.post(this.routerPath('getBusinessProfile'), ...guards, async (req, res) => {
|
||||||
const response = await this.dataValidate<ProfilePictureDto>({
|
const response = await this.dataValidate<ProfilePictureDto>({
|
||||||
request: req,
|
request: req,
|
||||||
|
@ -29,6 +29,9 @@ import makeWASocket, {
|
|||||||
WAMessage,
|
WAMessage,
|
||||||
WAMessageUpdate,
|
WAMessageUpdate,
|
||||||
WASocket,
|
WASocket,
|
||||||
|
WAReadReceiptsValue,
|
||||||
|
WAPrivacyValue,
|
||||||
|
WAPrivacyOnlineValue,
|
||||||
} from '@evolution/base';
|
} from '@evolution/base';
|
||||||
import {
|
import {
|
||||||
Auth,
|
Auth,
|
||||||
@ -81,6 +84,7 @@ import {
|
|||||||
ArchiveChatDto,
|
ArchiveChatDto,
|
||||||
DeleteMessage,
|
DeleteMessage,
|
||||||
OnWhatsAppDto,
|
OnWhatsAppDto,
|
||||||
|
PrivacySettingDto,
|
||||||
ReadMessageDto,
|
ReadMessageDto,
|
||||||
WhatsAppNumberDto,
|
WhatsAppNumberDto,
|
||||||
} from '../dto/chat.dto';
|
} from '../dto/chat.dto';
|
||||||
@ -1479,6 +1483,23 @@ export class WAStartupService {
|
|||||||
return await this.client.fetchPrivacySettings();
|
return await this.client.fetchPrivacySettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async updatePrivacySettings(settings: PrivacySettingDto) {
|
||||||
|
try {
|
||||||
|
await this.client.updateReadReceiptsPrivacy(settings.privacySettings.readreceipts);
|
||||||
|
await this.client.updateProfilePicturePrivacy(settings.privacySettings.profile);
|
||||||
|
await this.client.updateStatusPrivacy(settings.privacySettings.status);
|
||||||
|
await this.client.updateOnlinePrivacy(settings.privacySettings.online);
|
||||||
|
await this.client.updateLastSeenPrivacy(settings.privacySettings.last);
|
||||||
|
await this.client.updateGroupsAddPrivacy(settings.privacySettings.groupadd);
|
||||||
|
return { update: 'success', data: await this.client.fetchPrivacySettings() };
|
||||||
|
} catch (error) {
|
||||||
|
throw new InternalServerErrorException(
|
||||||
|
'Error updating privacy settings',
|
||||||
|
error.toString(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async getBusinessProfile(number: string) {
|
public async getBusinessProfile(number: string) {
|
||||||
try {
|
try {
|
||||||
let jid;
|
let jid;
|
||||||
|
Loading…
Reference in New Issue
Block a user