Skip to content

Commit

Permalink
Merge branch 'master' into master-oficial-save-16082024
Browse files Browse the repository at this point in the history
  • Loading branch information
wkarts authored Aug 16, 2024
2 parents 01e627e + 119856c commit 67f7c0c
Show file tree
Hide file tree
Showing 15 changed files with 20,627 additions and 6,517 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/pr-comment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
To test this PR you can run the following command below:
```
# NPM
npm install @whiskeysockets/baileys@${{ github.event.pull_request.head.repo.full_name }}#${{ github.event.pull_request.head.ref }}
npm install @wkarts/baileys@${{ github.event.pull_request.head.repo.full_name }}#${{ github.event.pull_request.head.ref }}
# YARN v2
yarn add @whiskeysockets/baileys@${{ github.event.pull_request.head.repo.full_name }}#${{ github.event.pull_request.head.ref }}
yarn add @wkarts/baileys@${{ github.event.pull_request.head.repo.full_name }}#${{ github.event.pull_request.head.ref }}
```
77 changes: 63 additions & 14 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ jobs:
uses: actions/setup-node@v3.6.0
with:
node-version: 20.x
registry-url: "https://registry.npmjs.org"
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Get yarn cache directory path
id: yarn-cache-dir-path
Expand All @@ -44,18 +41,68 @@ jobs:
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Publish in NPM (as `baileys`)
run: npm publish --access public
- name: Set Package Name to @wkarts/baileys
run: npx json -I -f package.json -e "this.name='@wkarts/baileys'"

- name: Create .npmrc with custom registry
run: |
echo "registry=https://registry.npmjs.org" > ~/.npmrc
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" >> ~/.npmrc
- name: Publish to Custom Registry
run: |
echo "Verificando conectividade com o registro..."
curl -I https://registry.npmjs.org
echo "Publicando pacote..."
npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Publish in NPM (whiskeysockets scope)

- name: Clean up .npmrc
run: rm ~/.npmrc

- name: Revert Package Name
run: npx json -I -f package.json -e "this.name='baileys'"

- name: Check if release exists
id: check_release
run: |
RELEASE_EXISTS=$(curl -s -H "Authorization: token ${{ secrets.PERSONAL_TOKEN }}" \
https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ github.ref_name }} \
| jq -r '.message')
if [ "$RELEASE_EXISTS" == "Not Found" ]; then
echo "Release does not exist"
echo "release_exists=false" >> $GITHUB_ENV
else
echo "Release exists"
echo "release_exists=true" >> $GITHUB_ENV
fi
env:
GITHUB_TOKEN: ${{ secrets.PERSONAL_TOKEN }}

- name: Save release notes if exists
if: env.release_exists == 'true'
id: save_release_notes
run: |
RELEASE_NOTES=$(curl -s -H "Authorization: token ${{ secrets.PERSONAL_TOKEN }}" \
https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ github.ref_name }} \
| jq -r '.body')
echo "release_notes<<EOF" >> $GITHUB_OUTPUT
echo "${RELEASE_NOTES}" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
env:
GITHUB_TOKEN: ${{ secrets.PERSONAL_TOKEN }}

- name: Delete existing release if exists
if: env.release_exists == 'true'
run: |
npx json -I -f package.json -e "this.name='@whiskeysockets/baileys'"
npm publish --access public --//registry.npmjs.org/:_authToken=$NPM_TOKEN
npx json -I -f package.json -e "this.name='baileys'"
RELEASE_ID=$(curl -s -H "Authorization: token ${{ secrets.PERSONAL_TOKEN }}" \
https://api.github.com/repos/${{ github.repository }}/releases/tags/${{ github.ref_name }} \
| jq -r '.id')
curl -X DELETE -H "Authorization: token ${{ secrets.PERSONAL_TOKEN }}" \
https://api.github.com/repos/${{ github.repository }}/releases/$RELEASE_ID
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
GITHUB_TOKEN: ${{ secrets.PERSONAL_TOKEN }}

- name: Generate Changelog
id: generate_changelog
Expand All @@ -74,13 +121,15 @@ jobs:
- name: Create Release
uses: meeDamian/github-release@2.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.PERSONAL_TOKEN }}
with:
token: ${{ secrets.GITHUB_TOKEN }}
token: ${{ secrets.PERSONAL_TOKEN }}
tag: ${{ github.ref }}
commitish: ${{ github.sha }}
name: ${{ github.ref_name }}
body: ${{ steps.generate_changelog.outputs.changelog }}
body: |
${{ steps.generate_changelog.outputs.changelog }}
${{ steps.save_release_notes.outputs.release_notes }}
draft: false
prerelease: false
files: >
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
steps:
- uses: actions/stale@v3
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
repo-token: ${{ secrets.PERSONAL_TOKEN }}
stale-issue-message: 'This issue is stale because it has been open 6 days with no activity. Remove the stale label or comment or this will be closed in 2 days'
stale-pr-message: 'This PR is stale because it has been open 6 days with no activity. Remove the stale label or comment or this will be closed in 2 days'
days-before-stale: 6
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/update-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ jobs:
with:
publish_branch: gh-pages
publish_dir: ./docs
cname: baileys.whiskeysockets.io
github_token: ${{ secrets.GITHUB_TOKEN }}
cname: baileys.wkarts.io
github_token: ${{ secrets.PERSONAL_TOKEN }}
6 changes: 3 additions & 3 deletions .github/workflows/update-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,16 @@ jobs:
- name: Update Nightly TAG
uses: richardsimko/update-tag@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.PERSONAL_TOKEN }}
with:
tag_name: nightly

- name: Update Nightly Release
uses: meeDamian/github-release@2.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.PERSONAL_TOKEN }}
with:
token: ${{ secrets.GITHUB_TOKEN }}
token: ${{ secrets.PERSONAL_TOKEN }}
tag: nightly
commitish: ${{ github.sha }}
name: Nightly Release
Expand Down
12 changes: 8 additions & 4 deletions .github/workflows/update-proto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ name: Update WAProto

on:
schedule:
- cron: "10 1 * * *"
workflow_dispatch:
- cron: "20 1 * * *" # Executa diariamente às 10:19 AM
workflow_dispatch: # Permite execução manual do workflow

permissions:
contents: write
Expand All @@ -20,7 +20,7 @@ jobs:
- name: Install Node
uses: actions/setup-node@v3
with:
node-version: 20.x
node-version: 20.x # Usar Node 20.x

- name: Install packages
run: |
Expand All @@ -37,7 +37,11 @@ jobs:
echo "wa_js_url=$WA_JS_URL" >> $GITHUB_OUTPUT
- name: GenerateStatics
run: yarn gen:protobuf
run: |
yarn global add protobufjs protobufjs-cli
export PATH="$(yarn global bin):$PATH"
pbjs -t static-module -w commonjs -o ./WAProto/index.js ./WAProto/WAProto.proto
pbts -o ./WAProto/index.d.ts ./WAProto/index.js
- name: Update baileys-version.json
run: |
Expand Down
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
This library was originally a project for **CS-2362 at Ashoka University** and is in no way affiliated with or endorsed by WhatsApp. Use at your own discretion. Do not spam people with this. We discourage any stalkerware, bulk or automated messaging usage.

#### Liability and License Notice
Baileys and its maintainers cannot be held liable for misuse of this application, as stated in the [MIT license](https://github.com/WhiskeySockets/Baileys/blob/master/LICENSE).
Baileys and its maintainers cannot be held liable for misuse of this application, as stated in the [MIT license](https://github.com/wkarts/baileys/blob/master/LICENSE).
The maintainers of Baileys do not in any way condone the use of this application in practices that violate the Terms of Service of WhatsApp. The maintainers of this application call upon the personal responsibility of its users to use this application in a fair way, as it is intended to be used.
##

Expand Down Expand Up @@ -33,17 +33,17 @@ To run the example script, download or clone the repo and then type the followin

Use the stable version:
```
yarn add @whiskeysockets/baileys
yarn add @wkarts/baileys
```

Use the edge version (no guarantee of stability, but latest fixes + features)
```
yarn add github:WhiskeySockets/Baileys
yarn add github:wkarts/baileys
```

Then import your code using:
``` ts
import makeWASocket from '@whiskeysockets/baileys'
import makeWASocket from '@wkarts/baileys'
```

## Unit Tests
Expand All @@ -55,7 +55,7 @@ TODO
WhatsApp provides a multi-device API that allows Baileys to be authenticated as a second WhatsApp client by scanning a QR code with WhatsApp on your phone.

``` ts
import makeWASocket, { DisconnectReason } from '@whiskeysockets/baileys'
import makeWASocket, { DisconnectReason } from '@wkarts/baileys'
import { Boom } from '@hapi/boom'

async function connectToWhatsApp () {
Expand Down Expand Up @@ -193,7 +193,7 @@ You obviously don't want to keep scanning the QR code every time you want to con

So, you can load the credentials to log back in:
``` ts
import makeWASocket, { BufferJSON, useMultiFileAuthState } from '@whiskeysockets/baileys'
import makeWASocket, { BufferJSON, useMultiFileAuthState } from '@wkarts/baileys'
import * as fs from 'fs'
// utility function to help save the auth state in a single folder
Expand Down Expand Up @@ -308,7 +308,7 @@ Baileys does not come with a defacto storage for chats, contacts, or messages. H
It can be used as follows:

``` ts
import makeWASocket, { makeInMemoryStore } from '@whiskeysockets/baileys'
import makeWASocket, { makeInMemoryStore } from '@wkarts/baileys'
// the store maintains the data of the WA connection in memory
// can be written out to a file & read from it
const store = makeInMemoryStore({ })
Expand Down Expand Up @@ -347,7 +347,7 @@ The store also provides some simple functions such as `loadMessages` that utiliz
### Non-Media Messages

``` ts
import { MessageType, MessageOptions, Mimetype } from '@whiskeysockets/baileys'
import { MessageType, MessageOptions, Mimetype } from '@wkarts/baileys'
const id = 'abcd@s.whatsapp.net' // the WhatsApp ID
// send a simple text!
Expand Down Expand Up @@ -406,7 +406,7 @@ Sending media (video, stickers, images) is easier & more efficient than ever.
- When specifying a media url, Baileys never loads the entire buffer into memory; it even encrypts the media as a readable stream.

``` ts
import { MessageType, MessageOptions, Mimetype } from '@whiskeysockets/baileys'
import { MessageType, MessageOptions, Mimetype } from '@wkarts/baileys'
// Sending gifs
await sock.sendMessage(
id,
Expand Down Expand Up @@ -456,7 +456,7 @@ await sock.sendMessage(
Do not enter this field if you want to automatically generate a thumb
*/
mimetype: Mimetype.pdf, /* (for media messages) specify the type of media (optional for all media types except documents),
import {Mimetype} from '@whiskeysockets/baileys'
import {Mimetype} from '@wkarts/baileys'
*/
fileName: 'somefile.pdf', // (for media messages) file name for the media
/* will send audio messages as voice notes, if set to true */
Expand Down Expand Up @@ -515,7 +515,7 @@ The presence expires after about 10 seconds.
If you want to save the media you received
``` ts
import { writeFile } from 'fs/promises'
import { downloadMediaMessage } from '@whiskeysockets/baileys'
import { downloadMediaMessage } from '@wkarts/baileys'
sock.ev.on('messages.upsert', async ({ messages }) => {
const m = messages[0]
Expand Down
13 changes: 10 additions & 3 deletions WAProto/GenerateStatics.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
yarn pbjs -t static-module -w commonjs -o ./WAProto/index.js ./WAProto/WAProto.proto;
yarn pbts -o ./WAProto/index.d.ts ./WAProto/index.js;
# Instalar protobufjs e protobufjs-cli globalmente
yarn global add protobufjs protobufjs-cli

#protoc --plugin=./node_modules/.bin/protoc-gen-ts_proto --ts_proto_opt=env=node,useOptionals=true,forceLong=long --ts_proto_out=. ./src/Binary/WAMessage.proto;
# Adicionar a localização dos binários globalmente instalados ao PATH
export PATH="$(yarn global bin):$PATH"

# Gerar os arquivos estáticos do protobuf
pbjs -t static-module -w commonjs -o ./WAProto/index.js ./WAProto/WAProto.proto
pbts -o ./WAProto/index.d.ts ./WAProto/index.js

#protoc --plugin=./node_modules/.bin/protoc-gen-ts_proto --ts_proto_opt=env=node,useOptionals=true,forceLong=long --ts_proto_out=. ./src/Binary/WAMessage.proto;
Loading

0 comments on commit 67f7c0c

Please sign in to comment.