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",
|
"qr-image": "^3.2.0",
|
||||||
"qrcode-terminal": "^0.12.0",
|
"qrcode-terminal": "^0.12.0",
|
||||||
"swagger-ui-express": "^5.0.1",
|
"swagger-ui-express": "^5.0.1",
|
||||||
"whatsapp-web.js": "^1.33.0",
|
"whatsapp-web.js": "^1.33.1",
|
||||||
"ws": "^8.18.2"
|
"ws": "^8.18.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|
@ -8177,9 +8177,9 @@
|
||||||
"license": "BSD-2-Clause"
|
"license": "BSD-2-Clause"
|
||||||
},
|
},
|
||||||
"node_modules/whatsapp-web.js": {
|
"node_modules/whatsapp-web.js": {
|
||||||
"version": "1.33.0",
|
"version": "1.33.1",
|
||||||
"resolved": "https://registry.npmjs.org/whatsapp-web.js/-/whatsapp-web.js-1.33.0.tgz",
|
"resolved": "https://registry.npmjs.org/whatsapp-web.js/-/whatsapp-web.js-1.33.1.tgz",
|
||||||
"integrity": "sha512-WyyOl0Xh2C1o7/pnZJ64evbkJL6t/BjN0adeIBP0QUiWS+nuv35iAg5tZWBPZEa1S1oFjX8ZXmSFBdUSjr5lQw==",
|
"integrity": "sha512-Ty7YOdB6HL0ZjZGwAXu3smUA9HSYbEJN5GOP2TU9APAPJLanjrQ3G/axWm7RsVJF/XH2B7JoAMt+IgZ4izDYOg==",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pedroslopez/moduleraid": "^5.0.2",
|
"@pedroslopez/moduleraid": "^5.0.2",
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
"qr-image": "^3.2.0",
|
"qr-image": "^3.2.0",
|
||||||
"qrcode-terminal": "^0.12.0",
|
"qrcode-terminal": "^0.12.0",
|
||||||
"swagger-ui-express": "^5.0.1",
|
"swagger-ui-express": "^5.0.1",
|
||||||
"whatsapp-web.js": "^1.33.0",
|
"whatsapp-web.js": "^1.33.1",
|
||||||
"ws": "^8.18.2"
|
"ws": "^8.18.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|
|
||||||
|
|
@ -178,6 +178,35 @@ const setupSession = async (sessionId) => {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await client.initialize()
|
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) {
|
} catch (error) {
|
||||||
logger.error({ sessionId, err: error }, 'Initialize error')
|
logger.error({ sessionId, err: error }, 'Initialize error')
|
||||||
throw error
|
throw error
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue