fix: update library and inject FindOrCreateChat
This commit is contained in:
parent
18d4a5d43b
commit
a618c67038
3 changed files with 34 additions and 5 deletions
8
package-lock.json
generated
8
package-lock.json
generated
|
|
@ -17,7 +17,7 @@
|
|||
"qr-image": "^3.2.0",
|
||||
"qrcode-terminal": "^0.12.0",
|
||||
"swagger-ui-express": "^5.0.1",
|
||||
"whatsapp-web.js": "^1.33.0",
|
||||
"whatsapp-web.js": "^1.33.1",
|
||||
"ws": "^8.18.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
@ -8177,9 +8177,9 @@
|
|||
"license": "BSD-2-Clause"
|
||||
},
|
||||
"node_modules/whatsapp-web.js": {
|
||||
"version": "1.33.0",
|
||||
"resolved": "https://registry.npmjs.org/whatsapp-web.js/-/whatsapp-web.js-1.33.0.tgz",
|
||||
"integrity": "sha512-WyyOl0Xh2C1o7/pnZJ64evbkJL6t/BjN0adeIBP0QUiWS+nuv35iAg5tZWBPZEa1S1oFjX8ZXmSFBdUSjr5lQw==",
|
||||
"version": "1.33.1",
|
||||
"resolved": "https://registry.npmjs.org/whatsapp-web.js/-/whatsapp-web.js-1.33.1.tgz",
|
||||
"integrity": "sha512-Ty7YOdB6HL0ZjZGwAXu3smUA9HSYbEJN5GOP2TU9APAPJLanjrQ3G/axWm7RsVJF/XH2B7JoAMt+IgZ4izDYOg==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@pedroslopez/moduleraid": "^5.0.2",
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@
|
|||
"qr-image": "^3.2.0",
|
||||
"qrcode-terminal": "^0.12.0",
|
||||
"swagger-ui-express": "^5.0.1",
|
||||
"whatsapp-web.js": "^1.33.0",
|
||||
"whatsapp-web.js": "^1.33.1",
|
||||
"ws": "^8.18.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
|
|||
|
|
@ -178,6 +178,35 @@ const setupSession = async (sessionId) => {
|
|||
|
||||
try {
|
||||
await client.initialize()
|
||||
// hotfix for https://github.com/pedroslopez/whatsapp-web.js/pull/3703
|
||||
client.once('ready', () => {
|
||||
client.pupPage.evaluate(() => {
|
||||
window.Store.FindOrCreateChat = window.require('WAWebFindChatAction')
|
||||
window.WWebJS.getChat = async (chatId, { getAsModel = true } = {}) => {
|
||||
const isChannel = /@\w*newsletter\b/.test(chatId)
|
||||
const chatWid = window.Store.WidFactory.createWid(chatId)
|
||||
let chat
|
||||
|
||||
if (isChannel) {
|
||||
try {
|
||||
chat = window.Store.NewsletterCollection.get(chatId)
|
||||
if (!chat) {
|
||||
await window.Store.ChannelUtils.loadNewsletterPreviewChat(chatId)
|
||||
chat = await window.Store.NewsletterCollection.find(chatWid)
|
||||
}
|
||||
} catch (err) {
|
||||
chat = null
|
||||
}
|
||||
} else {
|
||||
chat = window.Store.Chat.get(chatWid) || (await window.Store.FindOrCreateChat.findOrCreateLatestChat(chatWid))?.chat
|
||||
}
|
||||
|
||||
return getAsModel && chat
|
||||
? await window.WWebJS.getChatModel(chat, { isChannel })
|
||||
: chat
|
||||
}
|
||||
})
|
||||
})
|
||||
} catch (error) {
|
||||
logger.error({ sessionId, err: error }, 'Initialize error')
|
||||
throw error
|
||||
|
|
|
|||
Loading…
Reference in a new issue