oex2003/evolution-api
0
1import { JSONSchema7 } from 'json-schema';2import { v4 } from 'uuid';3 4const isNotEmpty = (...propertyNames: string[]): JSONSchema7 => {5 const properties = {};6 propertyNames.forEach(7 (property) =>8 (properties[property] = {9 minLength: 1,10 description: `The "${property}" cannot be empty`,11 }),12 );13 return {14 if: {15 propertyNames: {16 enum: [...propertyNames],17 },18 },19 then: { properties },20 };21};22 23export const createGroupSchema: JSONSchema7 = {24 $id: v4(),25 type: 'object',26 properties: {27 subject: { type: 'string' },28 description: { type: 'string' },29 profilePicture: { type: 'string' },30 promoteParticipants: { type: 'boolean', enum: [true, false] },31 participants: {32 type: 'array',33 minItems: 1,34 uniqueItems: true,35 items: {36 type: 'string',37 minLength: 10,38 pattern: '\\d+',39 description: '"participants" must be an array of numeric strings',40 },41 },42 },43 required: ['subject', 'participants'],44 ...isNotEmpty('subject', 'description', 'profilePicture'),45};46 47export const groupJidSchema: JSONSchema7 = {48 $id: v4(),49 type: 'object',50 properties: {51 groupJid: { type: 'string', pattern: '^[\\d-]+@g.us$' },52 },53 required: ['groupJid'],54 ...isNotEmpty('groupJid'),55};56 57export const getParticipantsSchema: JSONSchema7 = {58 $id: v4(),59 type: 'object',60 properties: {61 getParticipants: { type: 'string', enum: ['true', 'false'] },62 },63 required: ['getParticipants'],64 ...isNotEmpty('getParticipants'),65};66 67export const groupSendInviteSchema: JSONSchema7 = {68 $id: v4(),69 type: 'object',70 properties: {71 groupJid: { type: 'string' },72 description: { type: 'string' },73 numbers: {74 type: 'array',75 minItems: 1,76 uniqueItems: true,77 items: {78 type: 'string',79 minLength: 10,80 pattern: '\\d+',81 description: '"numbers" must be an array of numeric strings',82 },83 },84 },85 required: ['groupJid', 'description', 'numbers'],86 ...isNotEmpty('groupJid', 'description', 'numbers'),87};88 89export const groupInviteSchema: JSONSchema7 = {90 $id: v4(),91 type: 'object',92 properties: {93 inviteCode: { type: 'string', pattern: '^[a-zA-Z0-9]{22}$' },94 },95 required: ['inviteCode'],96 ...isNotEmpty('inviteCode'),97};98 99export const AcceptGroupInviteSchema: JSONSchema7 = {100 $id: v4(),101 type: 'object',102 properties: {103 inviteCode: { type: 'string', pattern: '^[a-zA-Z0-9]{22}$' },104 },105 required: ['inviteCode'],106 ...isNotEmpty('inviteCode'),107};108 109export const updateParticipantsSchema: JSONSchema7 = {110 $id: v4(),111 type: 'object',112 properties: {113 groupJid: { type: 'string' },114 action: {115 type: 'string',116 enum: ['add', 'remove', 'promote', 'demote'],117 },118 participants: {119 type: 'array',120 minItems: 1,121 uniqueItems: true,122 items: {123 type: 'string',124 minLength: 10,125 pattern: '\\d+',126 description: '"participants" must be an array of numeric strings',127 },128 },129 },130 required: ['groupJid', 'action', 'participants'],131 ...isNotEmpty('groupJid', 'action'),132};133 134export const updateSettingsSchema: JSONSchema7 = {135 $id: v4(),136 type: 'object',137 properties: {138 groupJid: { type: 'string' },139 action: {140 type: 'string',141 enum: ['announcement', 'not_announcement', 'locked', 'unlocked'],142 },143 },144 required: ['groupJid', 'action'],145 ...isNotEmpty('groupJid', 'action'),146};147 148export const toggleEphemeralSchema: JSONSchema7 = {149 $id: v4(),150 type: 'object',151 properties: {152 groupJid: { type: 'string' },153 expiration: {154 type: 'number',155 enum: [0, 86400, 604800, 7776000],156 },157 },158 required: ['groupJid', 'expiration'],159 ...isNotEmpty('groupJid', 'expiration'),160};161 162export const updateGroupPictureSchema: JSONSchema7 = {163 $id: v4(),164 type: 'object',165 properties: {166 groupJid: { type: 'string' },167 image: { type: 'string' },168 },169 required: ['groupJid', 'image'],170 ...isNotEmpty('groupJid', 'image'),171};172 173export const updateGroupSubjectSchema: JSONSchema7 = {174 $id: v4(),175 type: 'object',176 properties: {177 groupJid: { type: 'string' },178 subject: { type: 'string' },179 },180 required: ['groupJid', 'subject'],181 ...isNotEmpty('groupJid', 'subject'),182};183 184export const updateGroupDescriptionSchema: JSONSchema7 = {185 $id: v4(),186 type: 'object',187 properties: {188 groupJid: { type: 'string' },189 description: { type: 'string' },190 },191 required: ['groupJid', 'description'],192 ...isNotEmpty('groupJid', 'description'),193};194 