From a44821e09deee7bc97bf14e23e7aea0150772e27 Mon Sep 17 00:00:00 2001 From: LiaoYijun Date: Thu, 19 Dec 2024 16:23:23 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E7=B2=BE=E7=AE=80=E4=B8=8D=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E7=9A=84=E4=BB=A3=E7=A0=81=EF=BC=8C=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=20WA=20=E7=89=88=E6=9C=AC=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- baileys-server/main.js | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-) diff --git a/baileys-server/main.js b/baileys-server/main.js index dbebaf6..f998a88 100644 --- a/baileys-server/main.js +++ b/baileys-server/main.js @@ -11,8 +11,6 @@ import { import NodeCache from 'node-cache' import P from 'pino' -import fs from "fs" - const logger = P({ timestamp: () => `,"time":"${new Date().toJSON()}"` }, P.destination('./wa-logs.txt')) logger.level = 'trace' @@ -35,16 +33,17 @@ const startSock = async () => { const channelId = '创建时赋值,唯一标识' const phone = '手机号' const createTimestamp = '创建时间戳' - const status = 'close, open, connecting' + const status = 'close, open, connecting, online' + const waVersion = 'v2.3000.1017531287, latest(out)' const sendTextMessage = (whatsAppNo, content) => { sock.sendMessage(whatsAppNo + '@s.whatsapp.net', { text: content }) } - const sendImageMessage = (whatsAppNo, content) => { + const sendImageMessage = (whatsAppNo, imageUrl) => { sock.sendMessage(whatsAppNo + '@s.whatsapp.net', { - image: { url: 'https://images.asiahighlights.com/allpicture/2022/07/8a7d9ced5936463bb904c82a_cut_750x850_349.webp'},//fs.readFileSync("d:\\Workspace\\1.jpg"), - }) + image: { url: imageUrl}, + }) } const { state, saveCreds } = await useMultiFileAuthState('baileys_auth_info') @@ -62,11 +61,6 @@ const startSock = async () => { }, msgRetryCounterCache, generateHighQualityLinkPreview: true, - // ignore all broadcast messages -- to receive the same - // comment the line below out - // shouldIgnoreJid: jid => isJidBroadcast(jid), - // implement to handle retries & poll updates - getMessage, }) sock.ev.on('connection.update', (update) => { @@ -89,7 +83,7 @@ const startSock = async () => { const text = msg.message?.conversation || msg.message?.extendedTextMessage?.text if (text.indexOf('图片') > -1){ - sendImageMessage('8617607730395', '文本消息' + new Date().toString()) + sendImageMessage('8617607730395', 'https://images.asiahighlights.com/allpicture/2022/07/8a7d9ced5936463bb904c82a_cut_750x850_349.webp') } else if (text.indexOf('文本') > -1){ sendTextMessage('8617607730395', '文本消息' + new Date().toString()) } @@ -99,7 +93,7 @@ const startSock = async () => { }) // 不绑定不会影响扫码登录 - // store?.bind(sock.ev) + store?.bind(sock.ev) // the process function lets you process all events that just occurred // efficiently in a batch @@ -167,16 +161,6 @@ const startSock = async () => { ) return sock - - async function getMessage(key) { - if (store) { - const msg = await store.loadMessage(key.remoteJid, key.id) - return msg?.message || undefined - } - - // only if store is present - return WAProto.Message.fromObject({}) - } } startSock()