From 08bdb426c9f1aac517c938f328f279701f635dea Mon Sep 17 00:00:00 2001 From: Ibnu syawal <46734417+ibnusyawall@users.noreply.github.com> Date: Wed, 24 Mar 2021 17:49:00 +0000 Subject: [PATCH] Added method to join group (#417) * Added method to join group * Added method to join group in README --- README.md | 6 ++++++ src/Tests/Tests.Groups.ts | 5 +++++ src/WAConnection/8.Groups.ts | 7 ++++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 73d7ed9..890362d 100644 --- a/README.md +++ b/README.md @@ -527,6 +527,12 @@ Of course, replace ``` xyz ``` with an actual ID. // Or if you've left the group -- call this const metadata2 = await conn.groupMetadataMinimal ("abcd-xyz@g.us") ``` +- To join the group using the invitation code + ``` ts + const response = await conn.acceptInvite ("xxx") + console.log("joined to: " + response.gid) + ``` +Of course, replace ``` xxx ``` with invitation code. ## Broadcast Lists & Stories diff --git a/src/Tests/Tests.Groups.ts b/src/Tests/Tests.Groups.ts index 98e75ba..6e2339a 100644 --- a/src/Tests/Tests.Groups.ts +++ b/src/Tests/Tests.Groups.ts @@ -20,6 +20,11 @@ WAConnectionTest('Groups', (conn) => { assert.ok(code) assert.strictEqual(typeof code, 'string') }) + it('should joined group via invite code', async () => { + const response = await conn.acceptInvite(gid) + assert.ok(response.status) + assert.strictEqual(response.status, response.gid) + }) it('should retrieve group metadata', async () => { const metadata = await conn.groupMetadata(gid) assert.strictEqual(metadata.id, gid) diff --git a/src/WAConnection/8.Groups.ts b/src/WAConnection/8.Groups.ts index 324a3c6..05b7e28 100644 --- a/src/WAConnection/8.Groups.ts +++ b/src/WAConnection/8.Groups.ts @@ -177,4 +177,9 @@ export class WAConnection extends Base { const response = await this.query({json, expect200: true, requiresPhoneConnection: false}) return response.code as string } -} \ No newline at end of file + /** Join group via invite code */ + async acceptInvite(jid) { + const response = await this.query({ json: ['action', 'invite', jid], expect200: true }) + return response + } +}