Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MultiSession Socket.io send notif to all session #1335

Closed
nimaam opened this issue Jun 28, 2023 · 4 comments
Closed

MultiSession Socket.io send notif to all session #1335

nimaam opened this issue Jun 28, 2023 · 4 comments
Labels
bug Something isn't working needs triage

Comments

@nimaam
Copy link

nimaam commented Jun 28, 2023

Description

When you have a different WhatsApp Nomber, and new message commes to session for Line1, the user on session of Line2 also get the notification.

Environment

  • **Wppconnect-server version(s): 2.2.4
  • **Browser: Chrome
  • **OS: Windows and Mac
  • Node version: [e.g. Node 8, Node 14]
  • WhatsApp version: [e.g. 2.2126.14]
  • MultiDevice (BETA): no
  • config.json:

export default {
secretKey: 'ljkljlkjlkjlkjlkjlkjlkj',
host: 'http://localhost',
port: '21465',
deviceName: 'AID Customer',
poweredBy: 'AIDCustomer-Server',
startAllSession: true,
tokenStoreType: 'file',
maxListeners: 300,
customUserDataDir: './userDataDir/',
webhook: {
url: null,
autoDownload: true,
uploadS3: false,
awsBucketName: null,
readMessage: true,
allUnreadOnStart: false,
listenAcks: true,
onPresenceChanged: true,
onParticipantsChanged: true,
onReactionMessage: true,
onPollResponse: true,
onRevokedMessage: true,
onLabelUpdated: true,
},
chatwoot: {
sendQrCode: true,
sendStatus: true,
},
archive: {
enable: true,
waitTime: 10,
daysToArchive: 45,
},
log: {
level: 'silly', // Before open a issue, change level to silly and retry a action
logger: ['console', 'file'],
},
createOptions: {
browserArgs: [
'--disable-web-security',
'--no-sandbox',
'--disable-web-security',
'--aggressive-cache-discard',
'--disable-cache',
'--disable-application-cache',
'--disable-offline-load-stale-cache',
'--disk-cache-size=0',
'--disable-background-networking',
'--disable-default-apps',
'--disable-extensions',
'--disable-sync',
'--disable-translate',
'--hide-scrollbars',
'--metrics-recording-only',
'--mute-audio',
'--no-first-run',
'--safebrowsing-disable-auto-update',
'--ignore-certificate-errors',
'--ignore-ssl-errors',
'--ignore-certificate-errors-spki-list',
],
},
mapper: {
enable: true,
prefix: 'tagone-',
},
db: {
mongodbDatabase: 'tokens',
mongodbCollection: '',
mongodbUser: '',
mongodbPassword: '',
mongodbHost: '',
mongoIsRemote: true,
mongoURLRemote: '',
mongodbPort: 27017,
redisHost: 'localhost',
redisPort: 6379,
redisPassword: '',
redisDb: 0,
redisPrefix: 'docker',
},
};

Steps to Reproduce

I used the wppconnect-server in docker with 5 instance, nginx to loadbalance to them base on persistant ip-hash, and front

@nimaam nimaam added bug Something isn't working needs triage labels Jun 28, 2023
@fabioselau077
Copy link
Contributor

I also noticed this when I started using it.
I was working on a PR to improve on this issue.
My idea is to work with "rooms"/"channels" in websocket.
Before listening to the events you need to join the client session channel.
#1337

@nimaam
Copy link
Author

nimaam commented Aug 27, 2023

I also noticed this when I started using it. I was working on a PR to improve on this issue. My idea is to work with "rooms"/"channels" in websocket. Before listening to the events you need to join the client session channel. #1337

I checked the code, this is not the solution, the problem is , when we have multiple Whatsapp number on one server, then the server send the recieved message for all the WP numbers to all the online clients and sessions, so it is a security issue.
What should be do is something like this.

// Modify the callSocket function to accept a socketId parameter
export function callSocket(socketId: string, event: any, data: any) {
return req.io.to(socketId).emit(event, data);
}

// Create a mapping to store WhatsApp numbers and their corresponding socket IDs
const whatsappToSocketMap: { [whatsappNumber: string]: string } = {};

// When a user logs in, store their socket ID in the mapping
io.on('connection', (socket) => {
socket.on('login', (whatsappNumber) => {
whatsappToSocketMap[whatsappNumber] = socket.id;
});
});

// In your message handling code
await client.onMessage(async (message) => {
const targetSocketId = whatsappToSocketMap[message.from];
if (targetSocketId) {
callSocket(targetSocketId, 'received-message', message);
}
if (req.serverOptions.webhook.onSelfMessage && message.fromMe) {
callWebHook(client, req, 'onselfmessage', message);
}
});

// Similarly, for other events, find the user's socket and emit the event to it

in case I am not NodeJS developers, so please help us to solve this isse.

@icleitoncosta
Copy link
Collaborator

Hi, please read and test the PR #1337

@renat473
Copy link
Contributor

renat473 commented Oct 8, 2023

situation being in PR #1337

@renat473 renat473 closed this as completed Oct 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

No branches or pull requests

4 participants