Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions whatsapp_addon/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Example devcontainer for add-on repositories",
"image": "ghcr.io/home-assistant/devcontainer:addons",
"image": "ghcr.io/home-assistant/devcontainer:2-addons",
"appPort": ["7123:8123", "7357:4357"],
"postStartCommand": "bash devcontainer_bootstrap",
"runArgs": ["-e", "GIT_EDITOR=code --wait", "--privileged"],
Expand All @@ -24,5 +24,8 @@
}
}
},
"mounts": ["type=volume,target=/var/lib/docker"]
"mounts": [
"type=volume,target=/var/lib/docker",
"type=volume,target=/mnt/supervisor"
]
}
2 changes: 1 addition & 1 deletion whatsapp_addon/Baileys/.eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ coverage
src/WABinary/index.ts
WAProto
WASignalGroup
Example/test.ts
Example/Example.ts
docs
12 changes: 3 additions & 9 deletions whatsapp_addon/Baileys/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "@adiwajshing",
"extends": "@whiskeysockets",
"parserOptions": {
"sourceType": "module",
"project": "./tsconfig.json"
Expand All @@ -21,15 +21,9 @@
"@typescript-eslint/no-unnecessary-type-assertion": [
"warn"
],
"no-restricted-syntax": [
"warn",
{
"selector": "TSEnumDeclaration",
"message": "Don't declare enums, use literals instead"
}
],
"no-restricted-syntax": "off",
"keyword-spacing": [
"warn"
]
}
}
}
2 changes: 1 addition & 1 deletion whatsapp_addon/Baileys/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ output.csv
Proxy
test.ts
TestData
wa-logs.txt
wa-logs.txt
1 change: 0 additions & 1 deletion whatsapp_addon/Baileys/.npmignore
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

2 changes: 1 addition & 1 deletion whatsapp_addon/Baileys/.prettierignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
*
*
3 changes: 2 additions & 1 deletion whatsapp_addon/Baileys/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
## 6.7.7 (2024-08-22)
## 6.7.12 (2025-01-31)



2 changes: 1 addition & 1 deletion whatsapp_addon/Baileys/Example/boot_analytics_test.json
Original file line number Diff line number Diff line change
Expand Up @@ -921,4 +921,4 @@
}
}
]
}
}
92 changes: 5 additions & 87 deletions whatsapp_addon/Baileys/Example/example.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Boom } from '@hapi/boom'
import NodeCache from 'node-cache'
import readline from 'readline'
import makeWASocket, { AnyMessageContent, BinaryInfo, delay, DisconnectReason, downloadAndProcessHistorySyncNotification, encodeWAM, fetchLatestBaileysVersion, getAggregateVotesInPollMessage, getHistoryMsg, isJidNewsletter, makeCacheableSignalKeyStore, makeInMemoryStore, PHONENUMBER_MCC, proto, useMultiFileAuthState, WAMessageContent, WAMessageKey } from '../src'
import makeWASocket, { AnyMessageContent, BinaryInfo, delay, DisconnectReason, downloadAndProcessHistorySyncNotification, encodeWAM, fetchLatestBaileysVersion, getAggregateVotesInPollMessage, getHistoryMsg, isJidNewsletter, makeCacheableSignalKeyStore, makeInMemoryStore, proto, useMultiFileAuthState, WAMessageContent, WAMessageKey } from '../src'
//import MAIN_LOGGER from '../src/Utils/logger'
import open from 'open'
import fs from 'fs'
Expand All @@ -13,7 +13,6 @@ logger.level = 'trace'
const useStore = !process.argv.includes('--no-store')
const doReplies = process.argv.includes('--do-reply')
const usePairingCode = process.argv.includes('--use-pairing-code')
const useMobile = process.argv.includes('--mobile')

// 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
Expand Down Expand Up @@ -45,7 +44,6 @@ const startSock = async() => {
version,
logger,
printQRInTerminal: !usePairingCode,
mobile: useMobile,
auth: {
creds: state.creds,
/** caching makes the store faster to send/recv messages */
Expand All @@ -63,93 +61,13 @@ const startSock = async() => {
store?.bind(sock.ev)

// Pairing code for Web clients
if(usePairingCode && !sock.authState.creds.registered) {
if(useMobile) {
throw new Error('Cannot use pairing code with mobile api')
}

const phoneNumber = await question('Please enter your mobile phone number:\n')
if (usePairingCode && !sock.authState.creds.registered) {
// todo move to QR event
const phoneNumber = await question('Please enter your phone number:\n')
const code = await sock.requestPairingCode(phoneNumber)
console.log(`Pairing code: ${code}`)
}

// If mobile was chosen, ask for the code
if(useMobile && !sock.authState.creds.registered) {
const { registration } = sock.authState.creds || { registration: {} }

if(!registration.phoneNumber) {
registration.phoneNumber = await question('Please enter your mobile phone number:\n')
}

const libPhonenumber = await import("libphonenumber-js")
const phoneNumber = libPhonenumber.parsePhoneNumber(registration!.phoneNumber)
if(!phoneNumber?.isValid()) {
throw new Error('Invalid phone number: ' + registration!.phoneNumber)
}

registration.phoneNumber = phoneNumber.format('E.164')
registration.phoneNumberCountryCode = phoneNumber.countryCallingCode
registration.phoneNumberNationalNumber = phoneNumber.nationalNumber
const mcc = PHONENUMBER_MCC[phoneNumber.countryCallingCode]
if(!mcc) {
throw new Error('Could not find MCC for phone number: ' + registration!.phoneNumber + '\nPlease specify the MCC manually.')
}

registration.phoneNumberMobileCountryCode = mcc

async function enterCode() {
try {
const code = await question('Please enter the one time code:\n')
const response = await sock.register(code.replace(/["']/g, '').trim().toLowerCase())
console.log('Successfully registered your phone number.')
console.log(response)
rl.close()
} catch(error) {
console.error('Failed to register your phone number. Please try again.\n', error)
await askForOTP()
}
}

async function enterCaptcha() {
const response = await sock.requestRegistrationCode({ ...registration, method: 'captcha' })
const path = __dirname + '/captcha.png'
fs.writeFileSync(path, Buffer.from(response.image_blob!, 'base64'))

open(path)
const code = await question('Please enter the captcha code:\n')
fs.unlinkSync(path)
registration.captcha = code.replace(/["']/g, '').trim().toLowerCase()
}

async function askForOTP() {
if (!registration.method) {
await delay(2000)
let code = await question('How would you like to receive the one time code for registration? "sms" or "voice"\n')
code = code.replace(/["']/g, '').trim().toLowerCase()
if(code !== 'sms' && code !== 'voice') {
return await askForOTP()
}

registration.method = code
}

try {
await sock.requestRegistrationCode(registration)
await enterCode()
} catch(error) {
console.error('Failed to request registration code. Please try again.\n', error)

if(error?.reason === 'code_checkpoint') {
await enterCaptcha()
}

await askForOTP()
}
}

askForOTP()
}

const sendMessageWTyping = async(msg: AnyMessageContent, jid: string) => {
await sock.presenceSubscribe(jid)
await delay(500)
Expand Down Expand Up @@ -384,4 +302,4 @@ const startSock = async() => {
}
}

startSock()
startSock()
2 changes: 1 addition & 1 deletion whatsapp_addon/Baileys/Media/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
received_*
media_*
media_*
Binary file modified 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 modified 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 modified whatsapp_addon/Baileys/Media/ma_gif.mp4
Binary file not shown.
Binary file modified 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 modified whatsapp_addon/Baileys/Media/octopus.webp
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified whatsapp_addon/Baileys/Media/sonata.mp3
Binary file not shown.
Loading