Using a PHP websocket server to keep track of sockets

85 views Asked by At

I have a problem concerning websockets. I have a webhook which is triggered whenever a WhatsApp message is sent to my number. Now I want to initialize a chat session in Amazon Connect when a new contact sends a message. However, Amazon Connect works with sockets. This means that after opening the socket, I have to keep polling in order to get new messages.

However, every time a new message is sent, the webhook is triggered again. This would mean that for every new message, a new instance of the webhook starts running and keeps polling. This results into many different instances running. I think that the solution for this problem is to use a websocket server, which is an independent script that keeps the sockets open and can relay new messages back to the end-user.

However, I cannot seem to implement this. I thought I'd use Ratchet for this purpose (PHP). I want to be able to associate a socket with a phone number, so when a new session is started, a socket is created and when a new message has to be sent, I can check which socket was related to the phone number the message should go to in order to send the message through this socket so that it will arrive in Amazon Connect.

Does anyone have any idea on how I should implement this? I really cannot seem to get it working.

Any help would be greatly appreciated.

I tried creating a websocket server using Ratchet which should manage the socket connections and relay a message to the right socket when it has to be sent.

0

There are 0 answers