2

I am trying to setup my server so that I can have someone contact me through a chatbox on our website. Since I won't be there at all times to monitor the chats, I am trying to setup a system where the chat is routed through a websocket to my server (using PHP-Websockets) which is then sent to my phone via sms. This is all working correctly. I am having trouble wrapping my head around how my response can get back to the client side. When I respond to a text, Twilio will access any page that I specify with the sms message as a post variable. How can I pass this post message to my websocket (which is already running) where it can then send the message back to the client? Thanks for your help guys

Charles
  • 50,943
  • 13
  • 104
  • 142
anonymousfox
  • 769
  • 2
  • 9
  • 19
  • Are you asking how to perform bi-directional communication on a websocket? – Charles Dec 19 '12 at 04:24
  • @Charles Actually, I think what I have to do is have two socket connections - one from the client side to the server, and one from the server to twilio – anonymousfox Dec 19 '12 at 06:32

1 Answers1

4

Twilio communicates with your application via a WebHook call (HTTP request) when it receives your SMS.

Since PHP-WebSockets is running as a standalone process, and not as part of an existing web stack (e.g. Apache) then you'll need to have a few components in your setup:

  1. PHP-WebSocket
  2. Web server - serving up your HTML, CSS etc and also interacted with by the Twilio WebHook
  3. A way for 1. and 2. to interact. This is usually achieved through some sort of message queue

Here's a sequence diagram that details the communication between the various components in your setup, as I see it:

Hopefully that clarifies the communication from Twilio, your web server, your WebSocket server and your client.

If this seems overly complicated then you could remove the requirement to have the WebSocket server and message queue by using a hosted service such as Pusher, who I work for. If that is the case then this using Pusher & Twilio tutorial should be useful. One of the main benefits here is that you can continue to think in terms of request and response, rather than having to think about cross component communications through message queues.

Community
  • 1
  • 1
leggetter
  • 15,248
  • 1
  • 55
  • 61