Several websites, including Twitter and Facebook in particular, provide the ability to post messages for other people to read. These messages may have associated content, such as a picture or an audio clip. The TouchDevelop API provides facilities for downloading such messages and for posting new messages.
The social resource provides the two methods listed in Table 8-1 for creating a new message and for retrieving messages from a website. A simple example of obtaining messages from the two supported social networks and displaying them might be as follows.
var
TD msgs := social → search(“twitter”, “#touchdevelop”)
var
more msgs := social → search(“facebook”, “TouchDevelop”)
// combine the two collections into one
TD msgs → add many(more msgs)
// reorder and display the messages
TD msgs → sort by date
TD msgs → post to wall
Table 8-1 Messaging methods of the social service
8.1.1 Working with messages
A Message value will usually have a text component, because that is the simplest form of message. However additional information is usually associated with that message. The TouchDevelop API supports many methods for accessing or setting extra content attached to a message. These are all methods of the Message datatype. The methods for accessing, or getting, content are listed in the first table of section C.25 in Appendix C, those for setting content in the second table, and some additional methods in the third table.
It should be remembered that the extra content of a message is not always present. After retrieving one of these optional values, such as media link, the script should perform the test is invalid to verify that the value was actually available.
The share method of a Message instance allows the message to be transmitted in one of a variety of ways. Whichever choice is provided for the where parameter, a dialog box is displayed. The message is not sent until a selection has been picked and/or a button to send the message has been tapped.
8.1.2 Message collections
The Message Collection type is a mutable collection of messages. An empty instance may be created with the following call:
var
msgs := collections → create message collection
This empty collection may then be populated using the standard methods for adding new elements to a collection.
Collections of messages may also be created by the social→search and web→feed methods. The web→feed method accesses an RSS stream or Atom feed on the internet and parses that stream into a sequence of messages. An example script which uses the method is rmc reader (/fiol).
The Message Collection type provides several methods which are common to all mutable collection types. However there are two additional methods which are particularly useful for managing a message collection. These are listed in Table 8-2.
Table 8-2 Extra methods of the Message Collection datatype