From c459eca799d93c604713e5d577c399744fa061b4 Mon Sep 17 00:00:00 2001 From: Pedro Lopez Date: Mon, 15 Aug 2022 02:52:17 -0400 Subject: [PATCH 01/11] add release action --- .github/workflows/release.yml | 28 ++++++++++++ tools/publish | 80 +++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 .github/workflows/release.yml create mode 100755 tools/publish diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..3c3d623 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,28 @@ +name: release + +on: + workflow_dispatch: + inputs: + release_type: + description: "`alpha`, `alpha-minor`, `alpha-major` release?" + required: true + default: "alpha" + +jobs: + release: + runs-on: ubuntu-latest + if: ${{ github.repository == 'pedroslopez/whatsapp-web.js' }} + steps: + - uses: actions/checkout@v2 + - name: Bump version and publish to NPM + id: publish + run: ./tools/publish ${{ github.event.inputs.release_type }} + env: + NPM_TOKEN: ${{ secrets.RELEASE_NPM_TOKEN }} + - name: Create GitHub Release + id: create_release + uses: ncipollo/release-action@v1 + with: + prerelease: ${{ steps.publish.outputs.PRERELEASE }} + generateReleaseNotes: true + tag: v${{ steps.publish.outputs.NEW_VERSION }} \ No newline at end of file diff --git a/tools/publish b/tools/publish new file mode 100755 index 0000000..80a2670 --- /dev/null +++ b/tools/publish @@ -0,0 +1,80 @@ +#!/bin/bash + +cd "$(dirname "$0")" +cd '..' + +BRANCH=`git rev-parse --abbrev-ref HEAD` +RELEASE_MODE=$1 + +echo "" +echo "-----> CHECK INPUTS" +echo "" + +if [[ "$RELEASE_MODE" == "alpha" ]] +then + PRERELEASE='true' + VERSION_ARGS='prerelease --preid alpha -m "chore: prerelease v%s"' + DIST_TAG="next" +elif [[ "$RELEASE_MODE" == "alpha-minor" ]] +then + PRERELEASE='true' + VERSION_ARGS='preminor --preid alpha -m "chore: prerelease v%s"' + DIST_TAG="next" +elif [[ "$RELEASE_MODE" == "alpha-major" ]] +then + PRERELEASE='true' + VERSION_ARGS='premajor --preid alpha -m "chore: prerelease v%s"' + DIST_TAG="next" +else + echo 'Release Mode required' + exit 1 +fi + +if [ -f ~/.npmrc ]; then + echo "Found existing .npmrc" +else + if [[ -z "$NPM_TOKEN" ]];then + echo "No NPM_TOKEN or ~/.npmrc, exiting.." + exit 1; + else + echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc + fi +fi +echo "Publishing as NPM user: `npm whoami`" + +if [[ $BRANCH != 'main' ]]; then + echo "Not on 'main' branch. Exiting" + exit 1 +fi + +if [[ -n $(git status -s) ]]; then + echo "There are uncommitted changes on this branch. Exiting" + exit 1 +fi + +echo "" +echo "-----> BUMP VERSION" +echo "" + +npm version $VERSION_ARGS || exit 1 +git push && git push --tags + +NEW_VERSION=`cat package.json | jq -r .version` +echo "New Version: $NEW_VERSION" + +echo "" +echo "-----> PUSH TO NPM" +echo "" + +npm publish --tag $DIST_TAG + + +echo "" +echo "-----> Done!" +echo "Version $NEW_VERSION published to $DIST_TAG tag" +echo "" + +echo "::set-output name=NEW_VERSION::$NEW_VERSION" +echo "::set-output name=PRERELEASE::$PRELEASE" + +exit 0 \ No newline at end of file From 694a52bf26525a2f31d8766bfbed23ca00644c67 Mon Sep 17 00:00:00 2001 From: Pedro Lopez Date: Mon, 15 Aug 2022 03:22:43 -0400 Subject: [PATCH 02/11] fix(publish): ouput, remove message --- tools/publish | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/publish b/tools/publish index 80a2670..2989faf 100755 --- a/tools/publish +++ b/tools/publish @@ -13,17 +13,17 @@ echo "" if [[ "$RELEASE_MODE" == "alpha" ]] then PRERELEASE='true' - VERSION_ARGS='prerelease --preid alpha -m "chore: prerelease v%s"' + VERSION_ARGS="prerelease --preid alpha" DIST_TAG="next" elif [[ "$RELEASE_MODE" == "alpha-minor" ]] then PRERELEASE='true' - VERSION_ARGS='preminor --preid alpha -m "chore: prerelease v%s"' + VERSION_ARGS="preminor --preid alpha" DIST_TAG="next" elif [[ "$RELEASE_MODE" == "alpha-major" ]] then PRERELEASE='true' - VERSION_ARGS='premajor --preid alpha -m "chore: prerelease v%s"' + VERSION_ARGS="premajor --preid alpha" DIST_TAG="next" else echo 'Release Mode required' @@ -48,7 +48,7 @@ if [[ $BRANCH != 'main' ]]; then fi if [[ -n $(git status -s) ]]; then - echo "There are uncommitted changes on this branch. Exiting" + echo "There are uncommitted changes on this branch. Exiting..." exit 1 fi @@ -75,6 +75,6 @@ echo "Version $NEW_VERSION published to $DIST_TAG tag" echo "" echo "::set-output name=NEW_VERSION::$NEW_VERSION" -echo "::set-output name=PRERELEASE::$PRELEASE" +echo "::set-output name=PRERELEASE::$PRERELEASE" exit 0 \ No newline at end of file From bb09bb74e7aaae72380014fe865b1210c48a2a4f Mon Sep 17 00:00:00 2001 From: "Pedro S. Lopez" Date: Mon, 15 Aug 2022 03:32:40 -0400 Subject: [PATCH 03/11] fix(publish): add git user --- .github/workflows/release.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3c3d623..89299c6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -14,6 +14,8 @@ jobs: if: ${{ github.repository == 'pedroslopez/whatsapp-web.js' }} steps: - uses: actions/checkout@v2 + - run: git config --global user.email "hello@wwebjs.dev" + - run: git config --global user.name "WWebJS Bot" - name: Bump version and publish to NPM id: publish run: ./tools/publish ${{ github.event.inputs.release_type }} @@ -25,4 +27,4 @@ jobs: with: prerelease: ${{ steps.publish.outputs.PRERELEASE }} generateReleaseNotes: true - tag: v${{ steps.publish.outputs.NEW_VERSION }} \ No newline at end of file + tag: v${{ steps.publish.outputs.NEW_VERSION }} From c09a22c53360aecf74d12eb5ab9c412739050534 Mon Sep 17 00:00:00 2001 From: "Pedro S. Lopez" Date: Mon, 15 Aug 2022 03:42:06 -0400 Subject: [PATCH 04/11] fix(publish): exit if pushing to github failed --- tools/publish | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/publish b/tools/publish index 2989faf..c3a6a97 100755 --- a/tools/publish +++ b/tools/publish @@ -57,7 +57,7 @@ echo "-----> BUMP VERSION" echo "" npm version $VERSION_ARGS || exit 1 -git push && git push --tags +git push && git push --tags || exit 1 NEW_VERSION=`cat package.json | jq -r .version` echo "New Version: $NEW_VERSION" @@ -77,4 +77,4 @@ echo "" echo "::set-output name=NEW_VERSION::$NEW_VERSION" echo "::set-output name=PRERELEASE::$PRERELEASE" -exit 0 \ No newline at end of file +exit 0 From 09a81d0e1e98abd1c62c3a03bd1e814cedf7924b Mon Sep 17 00:00:00 2001 From: Pedro Lopez Date: Mon, 15 Aug 2022 03:47:51 -0400 Subject: [PATCH 05/11] v1.18.0-alpha.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 13f41c0..2d15522 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "whatsapp-web.js", - "version": "1.17.1", + "version": "1.18.0-alpha.0", "description": "Library for interacting with the WhatsApp Web API ", "main": "./index.js", "typings": "./index.d.ts", From 7fe35747308fad980e6dc5b42149e1802d4ab991 Mon Sep 17 00:00:00 2001 From: "Pedro S. Lopez" Date: Mon, 15 Aug 2022 03:53:57 -0400 Subject: [PATCH 06/11] fix(release): try setting PAT to push to main --- .github/workflows/release.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 89299c6..a5e1d3d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -14,6 +14,8 @@ jobs: if: ${{ github.repository == 'pedroslopez/whatsapp-web.js' }} steps: - uses: actions/checkout@v2 + with: + token: ${{ secrets.RELEASE_GITHUB_TOKEN }} - run: git config --global user.email "hello@wwebjs.dev" - run: git config --global user.name "WWebJS Bot" - name: Bump version and publish to NPM From bd4df4cf75cbe0fdc91c28f8b85cc6be524826b6 Mon Sep 17 00:00:00 2001 From: WWebJS Bot Date: Mon, 15 Aug 2022 07:54:39 +0000 Subject: [PATCH 07/11] 1.18.0-alpha.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2d15522..46ce339 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "whatsapp-web.js", - "version": "1.18.0-alpha.0", + "version": "1.18.0-alpha.1", "description": "Library for interacting with the WhatsApp Web API ", "main": "./index.js", "typings": "./index.d.ts", From aba0f3c3c9f1497ce30a1bd6ef7922a0db2488d2 Mon Sep 17 00:00:00 2001 From: Shir Serlui <70711723+shirser121@users.noreply.github.com> Date: Mon, 15 Aug 2022 18:53:28 +0300 Subject: [PATCH 08/11] Fix buttons sending (#1655) * Fix buttons sending * Quick reply id must be a string * Update src/util/Injected.js * Update src/structures/Buttons.js Co-authored-by: Rajeh Taher --- src/structures/Buttons.js | 2 +- src/util/Injected.js | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/structures/Buttons.js b/src/structures/Buttons.js index e35e609..567240b 100644 --- a/src/structures/Buttons.js +++ b/src/structures/Buttons.js @@ -98,7 +98,7 @@ class Buttons { index, quickReplyButton: { displayText: button.body, - id: button.id || index + id: button.id || `${index}` } }; } diff --git a/src/util/Injected.js b/src/util/Injected.js index 2ce9fec..cc44f0b 100644 --- a/src/util/Injected.js +++ b/src/util/Injected.js @@ -222,6 +222,14 @@ exports.ExposeStore = (moduleRaidStr) => { }; delete proto.templateMessage; } + if (proto.buttonsMessage) { + proto.viewOnceMessage = { + message: { + buttonsMessage: proto.buttonsMessage, + }, + }; + delete proto.buttonsMessage; + } if (proto.listMessage) { proto.viewOnceMessage = { message: { @@ -348,7 +356,6 @@ exports.LoadUtils = () => { window.WWebJS.prepareMessageButtons = (buttonsOptions) => { const returnObject = {}; - if (!buttonsOptions.buttons) { return returnObject; } @@ -397,7 +404,7 @@ exports.LoadUtils = () => { returnObject.isDynamicReplyButtonsMsg = true; returnObject.dynamicReplyButtons = buttonsOptions.buttons.map((button, index) => ({ - buttonId: button.index || `${index}`, + buttonId: button.quickReplyButton.id.toString() || `${index}`, buttonText: {displayText: button.quickReplyButton?.displayText}, type: 1, })); From 617ea37b71491b759b062a8d6e6704306c6c121a Mon Sep 17 00:00:00 2001 From: Sergio Carvalho Date: Mon, 15 Aug 2022 15:04:12 -0300 Subject: [PATCH 09/11] Fix buttons list (#1656) * fix: change the individual buttons limti to 3, still 5 on total * docs: Change buttons example to include clipboard --- example.js | 6 ++++-- src/structures/Buttons.js | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/example.js b/example.js index ab8c740..ede0063 100644 --- a/example.js +++ b/example.js @@ -189,16 +189,18 @@ client.on('message', async msg => { client.interface.openChatWindowAt(quotedMsg.id._serialized); } } else if (msg.body === '!buttons') { + // Limited to 5 buttons per message and limited to 3 buttons for each kind, in this case the third quick reply button will be removed let button = new Buttons( 'Button body', [ { body: 'whatsapp-web.js', url: 'https://wwebjs.dev/' }, + { body: 'Copy', url: 'https://www.whatsapp.com/otp/copy/This text will be copied to your clipboard' }, { body: 'Call me', number: '+1 (805) 457-4992' }, - { body: 'third special button', number: '+1 (202) 968-6161' },// Limited to 2 especial buttons, this one will be ignored + // Limited to 3 template buttons, any more will be ignored { body: 'Some text' }, { body: 'Another text' }, { body: 'Another another text' }, - { body: 'Fourth button' }// Limited to 3 regular buttons, this one will be ignored + // Limited to 3 quick reply buttons, any more will be ignored ], 'title', 'footer' diff --git a/src/structures/Buttons.js b/src/structures/Buttons.js index 567240b..d727042 100644 --- a/src/structures/Buttons.js +++ b/src/structures/Buttons.js @@ -70,10 +70,10 @@ class Buttons { * @returns {FormattedButtonSpec[]} */ _format(buttons){ - // Limit the buttons (max 3 of regular and 2 of special buttons) - const templateButtons = buttons.filter(button => button.url || button.number).slice(0,2); + // Limit the buttons (max 3 of regular and 3 of special buttons) 5 buttons total at the same time + const templateButtons = buttons.filter(button => button.url || button.number).slice(0,3); const regularButtons = buttons.filter(button => !button.url && !button.number).slice(0,3); - buttons = templateButtons.concat(regularButtons); + buttons = templateButtons.concat(regularButtons).slice(0,5); return buttons.map((button, index) => { if (button.url && button.number && button.id) throw 'Only pick one of the following (url/number/id)'; From 705d4d31fdbfcfdc4a1f997c2864ce23176419ef Mon Sep 17 00:00:00 2001 From: Shir Serlui <70711723+shirser121@users.noreply.github.com> Date: Thu, 18 Aug 2022 19:20:30 +0300 Subject: [PATCH 10/11] Use getCommonGroups not contact (#1623) --- src/Client.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Client.js b/src/Client.js index b36eb96..d3c9bb4 100644 --- a/src/Client.js +++ b/src/Client.js @@ -989,7 +989,13 @@ class Client extends EventEmitter { */ async getCommonGroups(contactId) { const commonGroups = await this.pupPage.evaluate(async (contactId) => { - const contact = window.Store.Contact.get(contactId); + let contact = window.Store.Contact.get(contactId); + if (!contact) { + const wid = window.Store.WidFactory.createUserWid(contactId); + const chatConstructor = window.Store.Contact.getModelsArray().find(c=>!c.isGroup).constructor; + contact = new chatConstructor({id: wid}); + } + if (contact.commonGroups) { return contact.commonGroups.serialize(); } From 62623347e8bcb23ba62ea43d36048b77cee10821 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=BC=BA=20L=E1=B4=87G=CC=B8=E1=B4=87=C9=B4D=20=E0=BC=BB?= <39593002+jtourisNS@users.noreply.github.com> Date: Thu, 18 Aug 2022 14:26:46 -0300 Subject: [PATCH 11/11] [Update] - adding catch block on promise for windows error (#1659) --- src/authStrategies/RemoteAuth.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/authStrategies/RemoteAuth.js b/src/authStrategies/RemoteAuth.js index 5ae85cc..f84ba59 100644 --- a/src/authStrategies/RemoteAuth.js +++ b/src/authStrategies/RemoteAuth.js @@ -178,9 +178,9 @@ class RemoteAuth extends BaseAuthStrategy { await fs.promises.rm(dirElement, { recursive: true, force: true - }); + }).catch(() => {}); } else { - await fs.promises.unlink(dirElement); + await fs.promises.unlink(dirElement).catch(() => {}); } } }