|
|
|
@ -31,11 +31,14 @@ setInterval(() => {
|
|
|
|
|
store?.writeToFile('./baileys_store_multi.json')
|
|
|
|
|
}, 10_000)
|
|
|
|
|
|
|
|
|
|
waEmitter.on('message:updated', event => { console.info('msg:event', event)})
|
|
|
|
|
waEmitter.on('message:received', event => { console.info('msg:event', event)})
|
|
|
|
|
|
|
|
|
|
// start a connection
|
|
|
|
|
const createWhatsApp = async (phone) => {
|
|
|
|
|
const channelId = generateId()
|
|
|
|
|
const whatsAppNo = phone
|
|
|
|
|
const { state, saveCreds } = await useMultiFileAuthState('baileys_auth_info/' + phone + '_' + channelId)
|
|
|
|
|
const { state, saveCreds } = await useMultiFileAuthState('baileys_auth_info/' + phone)
|
|
|
|
|
// fetch latest version of WA Web
|
|
|
|
|
const { version, isLatest } = await fetchLatestBaileysVersion()
|
|
|
|
|
const waVersion = version.join('.') + ', ' + (isLatest ? 'latest' : 'out')
|
|
|
|
@ -181,7 +184,6 @@ const createWhatsApp = async (phone) => {
|
|
|
|
|
if (msg.key.fromMe) {
|
|
|
|
|
waEmitter.emit('message:updated', {
|
|
|
|
|
"id": msg.key.id,
|
|
|
|
|
"wamid": msg.key.id,
|
|
|
|
|
"status": formatStatus(msg.status),
|
|
|
|
|
"from": whatsAppNo,
|
|
|
|
|
"to": fromWhatsAppNo,
|
|
|
|
@ -193,16 +195,11 @@ const createWhatsApp = async (phone) => {
|
|
|
|
|
id: parsePhoneNumber(msg.key.participant),
|
|
|
|
|
name: msg.pushName
|
|
|
|
|
},
|
|
|
|
|
"createTime": formatTimestamp(msg.messageTimestamp),
|
|
|
|
|
"updateTime": formatTimestamp(new Date().getTime()),
|
|
|
|
|
"sendTime": formatTimestamp(msg.messageTimestamp),
|
|
|
|
|
"deliverTime": formatTimestamp(msg.messageTimestamp),
|
|
|
|
|
"readTime": formatTimestamp(msg.messageTimestamp),
|
|
|
|
|
"updateTime": formatTimestamp(msg.messageTimestamp),
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
waEmitter.emit('message:received', {
|
|
|
|
|
"id": msg.key.id,
|
|
|
|
|
"wamid": msg.key.id,
|
|
|
|
|
"status": "",
|
|
|
|
|
"from": fromWhatsAppNo,
|
|
|
|
|
"to": whatsAppNo,
|
|
|
|
@ -215,10 +212,6 @@ const createWhatsApp = async (phone) => {
|
|
|
|
|
name: msg.pushName
|
|
|
|
|
},
|
|
|
|
|
"createTime": formatTimestamp(msg.messageTimestamp),
|
|
|
|
|
"updateTime": formatTimestamp(new Date().getTime()),
|
|
|
|
|
"sendTime": formatTimestamp(msg.messageTimestamp),
|
|
|
|
|
"deliverTime": formatTimestamp(msg.messageTimestamp),
|
|
|
|
|
"readTime": formatTimestamp(msg.messageTimestamp),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -226,6 +219,24 @@ const createWhatsApp = async (phone) => {
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
waSocket.ev.on('messages.update', async (messageUpdate) => {
|
|
|
|
|
console.info('messages.update: ', messageUpdate)
|
|
|
|
|
|
|
|
|
|
for (const msg of messageUpdate) {
|
|
|
|
|
waEmitter.emit('message:updated', {
|
|
|
|
|
"id": msg.key.id,
|
|
|
|
|
"status": formatStatus(msg.update.status),
|
|
|
|
|
"from": msg.key.fromMe ? whatsAppNo : parsePhoneNumber(msg.key.remoteJid),
|
|
|
|
|
"to": msg.key.fromMe ? parsePhoneNumber(msg.key.remoteJid) : whatsAppNo,
|
|
|
|
|
participant: {
|
|
|
|
|
id: parsePhoneNumber(msg.key.participant),
|
|
|
|
|
name: msg.pushName
|
|
|
|
|
},
|
|
|
|
|
"updateTime": formatTimestamp(new Date().getTime() / 1000),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// 不绑定不会影响扫码登录
|
|
|
|
|
store?.bind(waSocket.ev)
|
|
|
|
|
|
|
|
|
|