Merge branch 'fix-buttons-list' of https://github.com/pedroslopez/whatsapp-web.js into fix-buttons-list

This commit is contained in:
purpshell
2022-08-23 20:47:22 +03:00
8 changed files with 136 additions and 10 deletions

32
.github/workflows/release.yml vendored Normal file
View File

@@ -0,0 +1,32 @@
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
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
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 }}

View File

@@ -195,6 +195,7 @@ 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',
[

View File

@@ -1,6 +1,6 @@
{
"name": "whatsapp-web.js",
"version": "1.17.1",
"version": "1.18.0-alpha.1",
"description": "Library for interacting with the WhatsApp Web API ",
"main": "./index.js",
"typings": "./index.d.ts",

View File

@@ -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();
}

View File

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

View File

@@ -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)';
@@ -100,7 +100,7 @@ class Buttons {
index,
quickReplyButton: {
displayText: button.body,
id: button.id || index
id: button.id || `${index}`
}
};
}

View File

@@ -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,
}));

80
tools/publish Executable file
View File

@@ -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"
DIST_TAG="next"
elif [[ "$RELEASE_MODE" == "alpha-minor" ]]
then
PRERELEASE='true'
VERSION_ARGS="preminor --preid alpha"
DIST_TAG="next"
elif [[ "$RELEASE_MODE" == "alpha-major" ]]
then
PRERELEASE='true'
VERSION_ARGS="premajor --preid alpha"
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 || exit 1
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::$PRERELEASE"
exit 0