diff --git a/Example/example.ts b/Example/example.ts index 8e8aeb1..bbbcecc 100644 --- a/Example/example.ts +++ b/Example/example.ts @@ -1,5 +1,5 @@ import { Boom } from '@hapi/boom' -import makeWASocket, { AnyMessageContent, delay, DisconnectReason, fetchLatestBaileysVersion, makeInMemoryStore, useSingleFileAuthState } from '../src' +import makeWASocket, { AnyMessageContent, delay, DisconnectReason, fetchLatestBaileysVersion, makeInMemoryStore, MessageRetryMap, useSingleFileAuthState } from '../src' import MAIN_LOGGER from '../src/Utils/logger' const logger = MAIN_LOGGER.child({ }) @@ -8,6 +8,10 @@ logger.level = 'trace' const useStore = !process.argv.includes('--no-store') const doReplies = !process.argv.includes('--no-reply') +// external map to store retry counts of messages when decryption/encryption fails +// keep this out of the socket itself, so as to prevent a message decryption/encryption loop across socket restarts +const msgRetryCounterMap: MessageRetryMap = { } + // the store maintains the data of the WA connection in memory // can be written out to a file & read from it const store = useStore ? makeInMemoryStore({ logger }) : undefined @@ -30,6 +34,7 @@ const startSock = async() => { logger, printQRInTerminal: true, auth: state, + msgRetryCounterMap, // implement to handle retries getMessage: async key => { return { diff --git a/src/Types/index.ts b/src/Types/index.ts index c0cfe6b..9def6ea 100644 --- a/src/Types/index.ts +++ b/src/Types/index.ts @@ -14,11 +14,15 @@ import { proto } from '../../WAProto' import { AuthenticationState } from './Auth' import { CommonSocketConfig } from './Socket' +export type MessageRetryMap = { [msgId: string]: number } + export type SocketConfig = CommonSocketConfig & { /** provide a cache to store a user's device list */ userDevicesCache?: NodeCache - /** map to store the retry counts for failed messages */ - msgRetryCounterMap?: { [msgId: string]: number } + /** + * map to store the retry counts for failed messages; + * used to determine whether to retry a message or not */ + msgRetryCounterMap?: MessageRetryMap /** width for link preview images */ linkPreviewImageThumbnailWidth: number /**