added deleteChat

This commit is contained in:
Adhiraj
2020-07-14 20:30:50 +05:30
parent 8ce1e2da08
commit 6a69cbf8d5
2 changed files with 12 additions and 4 deletions

View File

@@ -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<WABroadcastListInfo> }
/** 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<WABroadcastListInfo> }
/** 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<void>
}
/** 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}>
}
}

View File

@@ -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 () => {