-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
31435db
commit b0ba1c7
Showing
11 changed files
with
253 additions
and
312 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,13 @@ | ||
ARG BUILD_FROM | ||
FROM $BUILD_FROM | ||
|
||
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true | ||
|
||
RUN apt install curl \ | ||
&& curl -sL https://deb.nodesource.com/setup_18.x | bash - \ | ||
&& apt update \ | ||
&& apt install nodejs \ | ||
&& apt install -y chromium git build-essential libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev | ||
RUN apk add --no-cache git npm --repository=http://dl-cdn.alpinelinux.org/alpine/v3.10/main | ||
|
||
COPY . / | ||
RUN chmod a+x /run.sh | ||
RUN chmod a+x /finish.sh | ||
|
||
RUN cd / && npm install | ||
RUN npm install github:pedroslopez/whatsapp-web.js#fix-buttons-list | ||
|
||
EXPOSE 3000 | ||
CMD [ "/run.sh" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
const EventEmitter = require('events'); | ||
|
||
const makeWASocket = require('@adiwajshing/baileys').default | ||
const { | ||
DisconnectReason, | ||
useSingleFileAuthState, | ||
Browsers | ||
} = require('@adiwajshing/baileys') | ||
|
||
class WhatsappClient extends EventEmitter { | ||
#sock; | ||
|
||
constructor(sessionPath) { | ||
super(); | ||
var self = this; | ||
async function connectToWhatsApp() { | ||
const { state, saveState } = useSingleFileAuthState(sessionPath) | ||
|
||
self.#sock = makeWASocket({ | ||
auth: state, | ||
syncFullHistory: false, | ||
browser: Browsers.macOS('Desktop'), | ||
logger: require("pino")({ level: 'silent' }) | ||
}) | ||
|
||
self.#sock.ev.on('creds.update', saveState) | ||
|
||
self.#sock.ev.on('connection.update', (update) => { | ||
const { connection, lastDisconnect, qr } = update | ||
|
||
if (qr) { | ||
self.emit('qr', qr) | ||
} | ||
|
||
if (connection === 'close') { | ||
const shouldReconnect = lastDisconnect.error.output?.statusCode !== DisconnectReason.loggedOut | ||
if (shouldReconnect) { | ||
connectToWhatsApp() | ||
} else { | ||
self.emit('disconnected') | ||
} | ||
} else if (connection === 'open') { | ||
self.emit('ready') | ||
} | ||
}) | ||
|
||
self.#sock.ev.on('messages.upsert', (Message) => { | ||
let msg = Message.messages[0] | ||
if (!msg.key.fromMe) | ||
self.emit('message', msg) | ||
}) | ||
} | ||
|
||
connectToWhatsApp() | ||
} | ||
|
||
async sendMessage(chatId, msg, options) { | ||
return await this.#sock.sendMessage(chatId, msg, options); | ||
} | ||
|
||
async presenceSubscribe(chatId) { | ||
return await this.#sock.presenceSubscribe(chatId); | ||
} | ||
|
||
async updateProfileStatus(status) { | ||
return await this.#sock.updateProfileStatus(status) | ||
} | ||
|
||
async updateProfileName(name) { | ||
return await this.#sock.updateProfileName(name) | ||
} | ||
|
||
async isOnWhatsapp(id) { | ||
return await this.#sock.onWhatsApp(id) | ||
} | ||
|
||
async updateBlockStatus(id, status) { | ||
return await this.#sock.updateBlockStatus(id, status) | ||
} | ||
} | ||
|
||
module.exports = WhatsappClient |
Oops, something went wrong.