Merge branch 'claude/feat-identity-change-handler-eQVNg'
This commit is contained in:
+26
-25
@@ -48,7 +48,7 @@ const startSock = async() => {
|
|||||||
}
|
}
|
||||||
// fetch latest version of WA Web
|
// fetch latest version of WA Web
|
||||||
const { version, isLatest } = await fetchLatestBaileysVersion()
|
const { version, isLatest } = await fetchLatestBaileysVersion()
|
||||||
console.log(`using WA v${version.join('.')}, isLatest: ${isLatest}`)
|
logger.debug({version: version.join('.'), isLatest}, `using latest WA version`)
|
||||||
|
|
||||||
const sock = makeWASocket({
|
const sock = makeWASocket({
|
||||||
version,
|
version,
|
||||||
@@ -83,7 +83,7 @@ const startSock = async() => {
|
|||||||
if((lastDisconnect?.error as Boom)?.output?.statusCode !== DisconnectReason.loggedOut) {
|
if((lastDisconnect?.error as Boom)?.output?.statusCode !== DisconnectReason.loggedOut) {
|
||||||
startSock()
|
startSock()
|
||||||
} else {
|
} else {
|
||||||
console.log('Connection closed. You are logged out.')
|
logger.fatal('Connection closed. You are logged out.')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,43 +96,44 @@ const startSock = async() => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('connection update', update)
|
logger.debug(update, 'connection update')
|
||||||
}
|
}
|
||||||
|
|
||||||
// credentials updated -- save them
|
// credentials updated -- save them
|
||||||
if(events['creds.update']) {
|
if(events['creds.update']) {
|
||||||
await saveCreds()
|
await saveCreds()
|
||||||
|
logger.debug({}, 'creds save triggered')
|
||||||
}
|
}
|
||||||
|
|
||||||
if(events['labels.association']) {
|
if(events['labels.association']) {
|
||||||
console.log(events['labels.association'])
|
logger.debug(events['labels.association'], 'labels.association event fired')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(events['labels.edit']) {
|
if(events['labels.edit']) {
|
||||||
console.log(events['labels.edit'])
|
logger.debug(events['labels.edit'], 'labels.edit event fired')
|
||||||
}
|
}
|
||||||
|
|
||||||
if(events.call) {
|
if(events['call']) {
|
||||||
console.log('recv call event', events.call)
|
logger.debug(events['call'], 'call event fired')
|
||||||
}
|
}
|
||||||
|
|
||||||
// history received
|
// history received
|
||||||
if(events['messaging-history.set']) {
|
if(events['messaging-history.set']) {
|
||||||
const { chats, contacts, messages, isLatest, progress, syncType } = events['messaging-history.set']
|
const { chats, contacts, messages, isLatest, progress, syncType } = events['messaging-history.set']
|
||||||
if (syncType === proto.HistorySync.HistorySyncType.ON_DEMAND) {
|
if (syncType === proto.HistorySync.HistorySyncType.ON_DEMAND) {
|
||||||
console.log('received on-demand history sync, messages=', messages)
|
logger.debug(messages, 'received on-demand history sync')
|
||||||
}
|
}
|
||||||
console.log(`recv ${chats.length} chats, ${contacts.length} contacts, ${messages.length} msgs (is latest: ${isLatest}, progress: ${progress}%), type: ${syncType}`)
|
logger.debug({contacts: contacts.length, chats: chats.length, messages: messages.length, isLatest, progress, syncType: syncType?.toString() }, 'messaging-history.set event fired')
|
||||||
}
|
}
|
||||||
|
|
||||||
// received a new message
|
// received a new message
|
||||||
if (events['messages.upsert']) {
|
if (events['messages.upsert']) {
|
||||||
const upsert = events['messages.upsert']
|
const upsert = events['messages.upsert']
|
||||||
logger.debug(upsert, 'recv messages')
|
logger.debug(upsert, 'messages.upsert fired')
|
||||||
|
|
||||||
if (!!upsert.requestId) {
|
if (!!upsert.requestId) {
|
||||||
console.log("placeholder message received for request of id=" + upsert.requestId, upsert)
|
logger.debug(upsert, 'placeholder request message received')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -143,13 +144,13 @@ const startSock = async() => {
|
|||||||
const text = msg.message?.conversation || msg.message?.extendedTextMessage?.text
|
const text = msg.message?.conversation || msg.message?.extendedTextMessage?.text
|
||||||
if (text == "requestPlaceholder" && !upsert.requestId) {
|
if (text == "requestPlaceholder" && !upsert.requestId) {
|
||||||
const messageId = await sock.requestPlaceholderResend(msg.key)
|
const messageId = await sock.requestPlaceholderResend(msg.key)
|
||||||
console.log('requested placeholder resync, id=', messageId)
|
logger.debug({ id: messageId }, 'requested placeholder resync')
|
||||||
}
|
}
|
||||||
|
|
||||||
// go to an old chat and send this
|
// go to an old chat and send this
|
||||||
if (text == "onDemandHistSync") {
|
if (text == "onDemandHistSync") {
|
||||||
const messageId = await sock.fetchMessageHistory(50, msg.key, msg.messageTimestamp!)
|
const messageId = await sock.fetchMessageHistory(50, msg.key, msg.messageTimestamp!)
|
||||||
console.log('requested on-demand sync, id=', messageId)
|
logger.debug({ id: messageId }, 'requested on-demand history resync')
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!msg.key.fromMe && doReplies && !isJidNewsletter(msg.key?.remoteJid!)) {
|
if (!msg.key.fromMe && doReplies && !isJidNewsletter(msg.key?.remoteJid!)) {
|
||||||
@@ -164,9 +165,7 @@ const startSock = async() => {
|
|||||||
|
|
||||||
// messages updated like status delivered, message deleted etc.
|
// messages updated like status delivered, message deleted etc.
|
||||||
if(events['messages.update']) {
|
if(events['messages.update']) {
|
||||||
console.log(
|
logger.debug(events['messages.update'], 'messages.update fired')
|
||||||
JSON.stringify(events['messages.update'], undefined, 2)
|
|
||||||
)
|
|
||||||
|
|
||||||
for(const { key, update } of events['messages.update']) {
|
for(const { key, update } of events['messages.update']) {
|
||||||
if(update.pollUpdates) {
|
if(update.pollUpdates) {
|
||||||
@@ -185,19 +184,23 @@ const startSock = async() => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(events['message-receipt.update']) {
|
if(events['message-receipt.update']) {
|
||||||
console.log(events['message-receipt.update'])
|
logger.debug(events['message-receipt.update'])
|
||||||
|
}
|
||||||
|
|
||||||
|
if (events['contacts.upsert']) {
|
||||||
|
logger.debug(events['message-receipt.update'])
|
||||||
}
|
}
|
||||||
|
|
||||||
if(events['messages.reaction']) {
|
if(events['messages.reaction']) {
|
||||||
console.log(events['messages.reaction'])
|
logger.debug(events['messages.reaction'])
|
||||||
}
|
}
|
||||||
|
|
||||||
if(events['presence.update']) {
|
if(events['presence.update']) {
|
||||||
console.log(events['presence.update'])
|
logger.debug(events['presence.update'])
|
||||||
}
|
}
|
||||||
|
|
||||||
if(events['chats.update']) {
|
if(events['chats.update']) {
|
||||||
console.log(events['chats.update'])
|
logger.debug(events['chats.update'])
|
||||||
}
|
}
|
||||||
|
|
||||||
if(events['contacts.update']) {
|
if(events['contacts.update']) {
|
||||||
@@ -206,19 +209,17 @@ const startSock = async() => {
|
|||||||
const newUrl = contact.imgUrl === null
|
const newUrl = contact.imgUrl === null
|
||||||
? null
|
? null
|
||||||
: await sock!.profilePictureUrl(contact.id!).catch(() => null)
|
: await sock!.profilePictureUrl(contact.id!).catch(() => null)
|
||||||
console.log(
|
logger.debug({id: contact.id, newUrl}, `contact has a new profile pic` )
|
||||||
`contact ${contact.id} has a new profile pic: ${newUrl}`,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(events['chats.delete']) {
|
if(events['chats.delete']) {
|
||||||
console.log('chats deleted ', events['chats.delete'])
|
logger.debug('chats deleted ', events['chats.delete'])
|
||||||
}
|
}
|
||||||
|
|
||||||
if(events['group.member-tag.update']) {
|
if(events['group.member-tag.update']) {
|
||||||
console.log('group member tag update', JSON.stringify(events['group.member-tag.update'], undefined, 2))
|
logger.debug('group member tag update', JSON.stringify(events['group.member-tag.update'], undefined, 2))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -39,13 +39,6 @@ const makeWASocket = (config: UserFacingSocketConfig) => {
|
|||||||
...config
|
...config
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the user hasn't provided their own history sync function,
|
|
||||||
// let's create a default one that respects the syncFullHistory flag.
|
|
||||||
// TODO: Change
|
|
||||||
if (config.shouldSyncHistoryMessage === undefined) {
|
|
||||||
newConfig.shouldSyncHistoryMessage = () => !!newConfig.syncFullHistory
|
|
||||||
}
|
|
||||||
|
|
||||||
return makeCommunitiesSocket(newConfig)
|
return makeCommunitiesSocket(newConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -930,7 +930,11 @@ export const processSyncAction = (
|
|||||||
ev.emit('contacts.upsert', [
|
ev.emit('contacts.upsert', [
|
||||||
{
|
{
|
||||||
id: id!,
|
id: id!,
|
||||||
name: action.lidContactAction.fullName || undefined,
|
name:
|
||||||
|
action.lidContactAction.fullName ||
|
||||||
|
action.lidContactAction.firstName ||
|
||||||
|
action.lidContactAction.username ||
|
||||||
|
undefined,
|
||||||
lid: id!,
|
lid: id!,
|
||||||
phoneNumber: undefined
|
phoneNumber: undefined
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ export const processContactAction = (
|
|||||||
data: [
|
data: [
|
||||||
{
|
{
|
||||||
id,
|
id,
|
||||||
name: action.fullName || undefined,
|
name: action.fullName || action.firstName || action.username || undefined,
|
||||||
lid: lidJid || undefined,
|
lid: lidJid || undefined,
|
||||||
phoneNumber
|
phoneNumber
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import { jest } from '@jest/globals'
|
|||||||
import type { ILogger } from '../../Utils/logger'
|
import type { ILogger } from '../../Utils/logger'
|
||||||
import { processContactAction } from '../../Utils/sync-action-utils'
|
import { processContactAction } from '../../Utils/sync-action-utils'
|
||||||
|
|
||||||
|
|
||||||
describe('processContactAction', () => {
|
describe('processContactAction', () => {
|
||||||
const mockLogger: ILogger = {
|
const mockLogger: ILogger = {
|
||||||
warn: jest.fn(),
|
warn: jest.fn(),
|
||||||
|
|||||||
Reference in New Issue
Block a user