diff --git a/src/WAClient/Base.ts b/src/WAClient/Base.ts index 9758b13..5a38979 100644 --- a/src/WAClient/Base.ts +++ b/src/WAClient/Base.ts @@ -6,6 +6,7 @@ import { WAMetric, WAFlag, MessageLogLevel, + WATag, } from '../WAConnection/Constants' export default class WhatsAppWebBase extends WAConnection { @@ -75,8 +76,6 @@ export default class WhatsAppWebBase extends WAConnection { const response = await this.queryExpecting200(['query', 'ProfilePicThumb', jid || this.userMetaData.id]) return response.eurl as string } - /** Query broadcast list info */ - async getBroadcastListInfo(jid: string) { return this.queryExpecting200(['query', 'contact', jid]) as Promise } /** Get your contacts */ async getContacts() { const json = ['query', { epoch: this.msgCount.toString(), type: 'contacts' }, null] @@ -103,6 +102,12 @@ export default class WhatsAppWebBase extends WAConnection { const json = ['query', { epoch: this.msgCount.toString(), type: 'chat' }, null] return this.query(json, [5, WAFlag.ignore]) // this has to be an encrypted query } + /** Query broadcast list info */ + async getBroadcastListInfo(jid: string) { return this.queryExpecting200(['query', 'contact', jid]) as Promise } + /** Delete the chat of a given ID */ + async deleteChat (jid: string) { + return this.setQuery ([ ['chat', {type: 'delete', jid: jid}, null] ], [12, WAFlag.ignore]) as Promise<{status: number}> + } /** * Check if your phone is connected * @param timeoutMs max time for the phone to respond @@ -181,8 +186,8 @@ export default class WhatsAppWebBase extends WAConnection { return loadMessage() as Promise } /** Generic function for action, set queries */ - async setQuery (nodes: WANode[]) { + async setQuery (nodes: WANode[], binaryTags: WATag = [WAMetric.group, WAFlag.ignore]) { const json = ['action', {epoch: this.msgCount.toString(), type: 'set'}, nodes] - return this.queryExpecting200(json, [WAMetric.group, WAFlag.ignore]) as Promise<{status: number}> + return this.queryExpecting200(json, binaryTags) as Promise<{status: number}> } } diff --git a/src/WAClient/Tests.ts b/src/WAClient/Tests.ts index 190abc4..e1ff933 100644 --- a/src/WAClient/Tests.ts +++ b/src/WAClient/Tests.ts @@ -187,6 +187,9 @@ WAClientTest('Groups', (client) => { it('should archive the group', async () => { await client.archiveChat(gid) }) + it('should delete the group', async () => { + await client.deleteChat(gid) + }) }) WAClientTest('Events', (client) => { it('should deliver a message', async () => {