Skip to content

Commit

Permalink
Release 1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
giuseppecastaldo committed Jan 18, 2023
1 parent 5429368 commit b22cd1f
Show file tree
Hide file tree
Showing 110 changed files with 127,072 additions and 84 deletions.
Binary file modified .DS_Store
Binary file not shown.
Binary file modified whatsapp_addon/.DS_Store
Binary file not shown.
7 changes: 7 additions & 0 deletions whatsapp_addon/Baileys/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Ignore artifacts:
lib
coverage
*.lock
.eslintrc.json
src/WABinary/index.ts
WAProto
3 changes: 3 additions & 0 deletions whatsapp_addon/Baileys/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "@adiwajshing"
}
2 changes: 2 additions & 0 deletions whatsapp_addon/Baileys/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
17 changes: 17 additions & 0 deletions whatsapp_addon/Baileys/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
node_modules
auth_info*.json
baileys_auth_info*
baileys_store*.json
output.csv
*/.DS_Store
.DS_Store
.env
browser-messages.json
decoded-ws.json
lib
docs
browser-token.json
Proxy
messages*.json
test.ts
TestData
169 changes: 169 additions & 0 deletions whatsapp_addon/Baileys/Example/example.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
import { Boom } from '@hapi/boom'
import makeWASocket, { AnyMessageContent, delay, DisconnectReason, fetchLatestBaileysVersion, isJidBroadcast, makeCacheableSignalKeyStore, makeInMemoryStore, MessageRetryMap, useMultiFileAuthState } from '../src'
import MAIN_LOGGER from '../src/Utils/logger'

const logger = MAIN_LOGGER.child({ })
logger.level = 'trace'

const useStore = !process.argv.includes('--no-store')
const doReplies = !process.argv.includes('--no-reply')

// external map to store retry counts of messages when decryption/encryption fails
// keep this out of the socket itself, so as to prevent a message decryption/encryption loop across socket restarts
const msgRetryCounterMap: MessageRetryMap = { }

// the store maintains the data of the WA connection in memory
// can be written out to a file & read from it
const store = useStore ? makeInMemoryStore({ logger }) : undefined
store?.readFromFile('./baileys_store_multi.json')
// save every 10s
setInterval(() => {
store?.writeToFile('./baileys_store_multi.json')
}, 10_000)

// start a connection
const startSock = async() => {
const { state, saveCreds } = await useMultiFileAuthState('baileys_auth_info')
// fetch latest version of WA Web
const { version, isLatest } = await fetchLatestBaileysVersion()
console.log(`using WA v${version.join('.')}, isLatest: ${isLatest}`)

const sock = makeWASocket({
version,
logger,
printQRInTerminal: true,
auth: {
creds: state.creds,
/** caching makes the store faster to send/recv messages */
keys: makeCacheableSignalKeyStore(state.keys, logger),
},
msgRetryCounterMap,
generateHighQualityLinkPreview: true,
// ignore all broadcast messages -- to receive the same
// comment the line below out
shouldIgnoreJid: jid => isJidBroadcast(jid),
// implement to handle retries
getMessage: async key => {
if(store) {
const msg = await store.loadMessage(key.remoteJid!, key.id!)
return msg?.message || undefined
}

// only if store is present
return {
conversation: 'hello'
}
}
})

store?.bind(sock.ev)

const sendMessageWTyping = async(msg: AnyMessageContent, jid: string) => {
await sock.presenceSubscribe(jid)
await delay(500)

await sock.sendPresenceUpdate('composing', jid)
await delay(2000)

await sock.sendPresenceUpdate('paused', jid)

await sock.sendMessage(jid, msg)
}

// the process function lets you process all events that just occurred
// efficiently in a batch
sock.ev.process(
// events is a map for event name => event data
async(events) => {
// something about the connection changed
// maybe it closed, or we received all offline message or connection opened
if(events['connection.update']) {
const update = events['connection.update']
const { connection, lastDisconnect } = update
if(connection === 'close') {
// reconnect if not logged out
if((lastDisconnect?.error as Boom)?.output?.statusCode !== DisconnectReason.loggedOut) {
startSock()
} else {
console.log('Connection closed. You are logged out.')
}
}

console.log('connection update', update)
}

// credentials updated -- save them
if(events['creds.update']) {
await saveCreds()
}

if(events.call) {
console.log('recv call event', events.call)
}

// history received
if(events['messaging-history.set']) {
const { chats, contacts, messages, isLatest } = events['messaging-history.set']
console.log(`recv ${chats.length} chats, ${contacts.length} contacts, ${messages.length} msgs (is latest: ${isLatest})`)
}

// received a new message
if(events['messages.upsert']) {
const upsert = events['messages.upsert']
console.log('recv messages ', JSON.stringify(upsert, undefined, 2))

if(upsert.type === 'notify') {
for(const msg of upsert.messages) {
if(!msg.key.fromMe && doReplies) {
console.log('replying to', msg.key.remoteJid)
await sock!.readMessages([msg.key])
await sendMessageWTyping({ text: 'Hello there!' }, msg.key.remoteJid!)
}
}
}
}

// messages updated like status delivered, message deleted etc.
if(events['messages.update']) {
console.log(events['messages.update'])
}

if(events['message-receipt.update']) {
console.log(events['message-receipt.update'])
}

if(events['messages.reaction']) {
console.log(events['messages.reaction'])
}

if(events['presence.update']) {
console.log(events['presence.update'])
}

if(events['chats.update']) {
console.log(events['chats.update'])
}

if(events['contacts.update']) {
for(const contact of events['contacts.update']) {
if(typeof contact.imgUrl !== 'undefined') {
const newUrl = contact.imgUrl === null
? null
: await sock!.profilePictureUrl(contact.id!).catch(() => null)
console.log(
`contact ${contact.id} has a new profile pic: ${newUrl}`,
)
}
}
}

if(events['chats.delete']) {
console.log('chats deleted ', events['chats.delete'])
}
}
)

return sock
}

startSock()
2 changes: 2 additions & 0 deletions whatsapp_addon/Baileys/Media/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
received_*
media_*
Binary file added whatsapp_addon/Baileys/Media/cat.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added whatsapp_addon/Baileys/Media/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added whatsapp_addon/Baileys/Media/ma_gif.mp4
Binary file not shown.
Binary file added whatsapp_addon/Baileys/Media/meme.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added whatsapp_addon/Baileys/Media/octopus.webp
Binary file not shown.
Binary file added whatsapp_addon/Baileys/Media/sonata.mp3
Binary file not shown.
Loading

0 comments on commit b22cd1f

Please sign in to comment.