How Facebook (probably) implements SMS threads

A lot of web applications provides you the ability to receive or post updates using SMS (text messages). Twitter is the posterboy of such applications.

But the feature that distinguishes Facebook SMS updates from any other service is that you can actually reply to individual messages and your message then becomes a part of the aforementioned thread. You don’t have to specify any special command to do so. Just hit the reply  button and you are done.

How do they know which message belongs to which thread? Its simple, each message comes from a different number. For example, say A writes something on your wall, then you will receive a message from +91922305501. Also B sends a message to you, a message comes from +91922305502 and when C comments on your note, you get a message from +91922305503. How many numbers do facebook own? Probably 100 in India, from +91922305500 to +9192230599.  A per user mapping of the number from which the message is sent and the object/thread id for that message is kept on the backend. So when the user replies to a particular number, say +91922305502 , it knows that is was a reply to the message sent by B and hence treats as a reply to that message. A rotation policy is used to decide from which number the message is to be sent. So after recieving a message from +9192230599, the next message will be from +91922305500  and now you cannot reply to the thread represented by the earlier message from the same number.

Discalimer: This is just a guess of how this functionality might have been implemented (or at least how I would implement it) and based strictly on SMSes received in India. Actual implementation might (probaly is) be entierly different from what is explained here.

Embedding flash object in Facebook Apps (FBML)

Yesterday I was trying to include a flash object in a facebook app using FBML fb:swf tag. The flash object needed to change the url of the page it was running on on a particular event. But since facebook prevents direct script access from flash, this could not be done.

Here is a simple workaround:

1. Create a simple html page containing only the flash object that you want to include.

<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
   </head>
   <body>
   	<object type="application/x-shockwave-flash" data="foo.swf" width="300" height="300">
   		<param name="movie" value="foo.swf">
         	<param name="quality" value="high">
         	<param name="scale" value="noscale">
         	<param name="salign" value="LT">
         	<param name="menu" value="false">
    	</object>
    </body>
</html>

2. Embed this html on the facebook page using the fb:iframe tag.

Now you can make all the Actionscript calls you want to. Only caveat to this approach is that you will no longer be able to make Facebook API calls directly from flash.