mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
feat: add "--no-store" + "--no-reply" flags to example
This commit is contained in:
@@ -5,13 +5,16 @@ import MAIN_LOGGER from '../src/Utils/logger'
|
|||||||
const logger = MAIN_LOGGER.child({ })
|
const logger = MAIN_LOGGER.child({ })
|
||||||
logger.level = 'trace'
|
logger.level = 'trace'
|
||||||
|
|
||||||
|
const useStore = !process.argv.includes('--no-store')
|
||||||
|
const doReplies = !process.argv.includes('--no-reply')
|
||||||
|
|
||||||
// the store maintains the data of the WA connection in memory
|
// the store maintains the data of the WA connection in memory
|
||||||
// can be written out to a file & read from it
|
// can be written out to a file & read from it
|
||||||
const store = makeInMemoryStore({ logger })
|
const store = useStore ? makeInMemoryStore({ logger }) : undefined
|
||||||
store.readFromFile('./baileys_store_multi.json')
|
store?.readFromFile('./baileys_store_multi.json')
|
||||||
// save every 10s
|
// save every 10s
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
store.writeToFile('./baileys_store_multi.json')
|
store?.writeToFile('./baileys_store_multi.json')
|
||||||
}, 10_000)
|
}, 10_000)
|
||||||
|
|
||||||
const { state, saveState } = useSingleFileAuthState('./auth_info_multi.json')
|
const { state, saveState } = useSingleFileAuthState('./auth_info_multi.json')
|
||||||
@@ -35,7 +38,7 @@ const startSock = async() => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
store.bind(sock.ev)
|
store?.bind(sock.ev)
|
||||||
|
|
||||||
const sendMessageWTyping = async(msg: AnyMessageContent, jid: string) => {
|
const sendMessageWTyping = async(msg: AnyMessageContent, jid: string) => {
|
||||||
await sock.presenceSubscribe(jid)
|
await sock.presenceSubscribe(jid)
|
||||||
@@ -57,7 +60,7 @@ const startSock = async() => {
|
|||||||
console.log(JSON.stringify(m, undefined, 2))
|
console.log(JSON.stringify(m, undefined, 2))
|
||||||
|
|
||||||
const msg = m.messages[0]
|
const msg = m.messages[0]
|
||||||
if(!msg.key.fromMe && m.type === 'notify') {
|
if(!msg.key.fromMe && m.type === 'notify' && doReplies) {
|
||||||
console.log('replying to', m.messages[0].key.remoteJid)
|
console.log('replying to', m.messages[0].key.remoteJid)
|
||||||
await sock!.sendReadReceipt(msg.key.remoteJid, msg.key.participant, [msg.key.id])
|
await sock!.sendReadReceipt(msg.key.remoteJid, msg.key.participant, [msg.key.id])
|
||||||
await sendMessageWTyping({ text: 'Hello there!' }, msg.key.remoteJid)
|
await sendMessageWTyping({ text: 'Hello there!' }, msg.key.remoteJid)
|
||||||
|
|||||||
Reference in New Issue
Block a user