I have searched long and far. I am typically familiar with the LAMP stack so apologies - I am learning Node as I'm trying to build a chat feature - similar to how Intercom/drift would work.
I have been led to believe that Socket.io is a good way to go about this, and I am having a little bit of trouble. The basic overview is something like this:
- Users can use my service to have a live chat feature enabled on their websites (they each have a unique API key)
- They can add the chat to any number of web pages/domains (via a script tag)
- The chat should be private between any single end user of the website, and the admin of the script tag (owner of the API key used to include the script on the page)
I'm having trouble with this.
Should I create dynamic namespaces for each URL, or is it a room?
Lets say I create a dynamic room on the client side that is unique such as is used in https://stackoverflow.com/a/19150254/1173155
// client side code
var dynamicRoomName = API_KEY + "_" + fullURL + "_" + expressSessionId;
var socket = io.connect();
socket.emit('create room', dynamicRoomName);
// server side code
io.sockets.on('connection', function(socket) {
socket.on('create room', function(room) {
socket.join(room);
});
});
The only person who should be able to see this chat other than the end user is the admin of that API Key, which I'm not sure how to implement.
I realise I will likely need a DB of some sort to keep track of the chats/rooms ect. Is there any good resource on how to learn how to implement this kind of thing?
Help is much appreciated!
Just going to expand a small bit on this, perhaps for my own good while working on the problem.
- There can be many admins (unique APIs)
- Admins are responsible for only their own chats - they cannot see any chats that do not belong to their API key
- Many users can chat with one admin (in private)
- All chat is 1 to 1
- The end user and the admin user will thus use different clients
- Admin can be in numerous chats to individual users
- Users would typically be in one chat to one admin
- Admins can't create chats (only receive incoming) - but of course can reply