mirror of
https://github.com/FranP-code/Baileys.git
synced 2025-10-13 00:32:22 +00:00
chore: update example
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { Boom } from '@hapi/boom'
|
||||
import NodeCache from 'node-cache'
|
||||
import makeWASocket, { AnyMessageContent, delay, DisconnectReason, fetchLatestBaileysVersion, makeCacheableSignalKeyStore, makeInMemoryStore, useMultiFileAuthState } from '../src'
|
||||
import makeWASocket, { AnyMessageContent, delay, DisconnectReason, fetchLatestBaileysVersion, getAggregateVotesInPollMessage, makeCacheableSignalKeyStore, makeInMemoryStore, proto, useMultiFileAuthState, WAMessageContent, WAMessageKey } from '../src'
|
||||
import MAIN_LOGGER from '../src/Utils/logger'
|
||||
|
||||
const logger = MAIN_LOGGER.child({ })
|
||||
@@ -43,18 +43,8 @@ const startSock = async() => {
|
||||
// ignore all broadcast messages -- to receive the same
|
||||
// comment the line below out
|
||||
// shouldIgnoreJid: jid => isJidBroadcast(jid),
|
||||
// implement to handle retries
|
||||
getMessage: async key => {
|
||||
if(store) {
|
||||
const msg = await store.loadMessage(key.remoteJid!, key.id!)
|
||||
return msg?.message || undefined
|
||||
}
|
||||
|
||||
// only if store is present
|
||||
return {
|
||||
conversation: 'hello'
|
||||
}
|
||||
}
|
||||
// implement to handle retries & poll updates
|
||||
getMessage,
|
||||
})
|
||||
|
||||
store?.bind(sock.ev)
|
||||
@@ -126,7 +116,24 @@ const startSock = async() => {
|
||||
|
||||
// messages updated like status delivered, message deleted etc.
|
||||
if(events['messages.update']) {
|
||||
console.log(events['messages.update'])
|
||||
console.log(
|
||||
JSON.stringify(events['messages.update'], undefined, 2)
|
||||
)
|
||||
|
||||
for(const { key, update } of events['messages.update']) {
|
||||
if(update.pollUpdates) {
|
||||
const pollCreation = await getMessage(key)
|
||||
if(pollCreation) {
|
||||
console.log(
|
||||
'got poll update, aggregation: ',
|
||||
getAggregateVotesInPollMessage({
|
||||
message: pollCreation,
|
||||
pollUpdates: update.pollUpdates,
|
||||
})
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(events['message-receipt.update']) {
|
||||
@@ -165,6 +172,16 @@ const startSock = async() => {
|
||||
)
|
||||
|
||||
return sock
|
||||
|
||||
async function getMessage(key: WAMessageKey): Promise<WAMessageContent | undefined> {
|
||||
if(store) {
|
||||
const msg = await store.loadMessage(key.remoteJid!, key.id!)
|
||||
return msg?.message || undefined
|
||||
}
|
||||
|
||||
// only if store is present
|
||||
return proto.Message.fromObject({})
|
||||
}
|
||||
}
|
||||
|
||||
startSock()
|
||||
Reference in New Issue
Block a user