Messagify is a way to instantly add messaging to your app so it can:
With Messagify, you spend less time fighting comment thread ids and SMTP servers, and more time building your application. As a plus, Messagify provides analytics about your users and their activity, so you get some insight into what people are talking about.
Using Messagify is as easy as adding a <script> tag to your HTML and a couple of simple server-side changes. Say you want to add commenting to your web app, this is all the code you need to add to the page where the comment widget should appear:
<script src="//api.messagify.com/js/comments.js"></script>
Because the API is available over http and https, a protocol-agnostic URL is used to prevent mixed-content warnings. The widget then figures out the URL of the current page and renders the comments appropriately. And best of all, you can use your site's CSS to style any Messagify widget so that it matches your app's design.
Messagify works by letting you manage users and overall authentication, but allowing you to offload comment storage, processing, and rendering (via widgets). Among the obvious benefits of not having to manage in-house comment systems or deal with real-time updates, Messagify provides an extremely lightweight and simple path to comment-enabling any site. It's so easy that you should be up and running within minutes, as opposed to taking weeks to build your own system.
Each user has the following metadata associated with it:
id: your internally unique id (often a primary key) for the userdisplay_name: the name to be displayed when showing this user's commentsemail: email address of this useremail is optional, but if provided, enables users to receive email notifications of comments and allows for comment replies to be sent via email.
User ids are used throughout the API, so we recommend that you use the same id that is in your database for the user as this value.
In order to keep the client-side JavaScript widgets simple and customizable, there are a couple of server-side changes that need to be made:
When a new user signs up for your site or an existing user changes their profile (such as display name or email address), comment widgets need to display the updated information. A simple PUT request is sufficient to keep the data in sync:
PUT /users/id
{
"display_name": "Amir",
"email": "amir@example.com"
}
If the user id already exists, it will be updated.
When user accounts are terminated, you have two options: mark them as deleted or permanently remove them. The former preserves comments the user may have made, whereas the latter will remove their comments from all topics. We recommend that you mark them as deleted, and after some time permanently remove them.
To mark a user as deleted:
PUT /users/id/status
{
"deleted": true
}
To reset a user's deleted status:
DELETE /users/id/status
To permanently remove a user:
DELETE /users/id
Communication between your server and the Messagify API is secured by API tokens. HTTP Basic authentication over HTTPS is used to keep the implementation simple. Because client-side JavaScript cannot contain private API keys, a different method is used to avoid exposing credentials.
Upon logging in a user into your web app, your app will need to securely communicate with the Messagify API to obtain a one-time token that can safely be passed to client-side JavaScript. This one-time token will be sent to the API and a session cookie associated with the current user, based on what your backend code passed to the API when requesting the token. Once this association has been made, no other server-side requests needs to be made from your app.
After you've successfully authenticated a user to your app, issue the following request to obtain a token for user id id:
POST /auth/jstoken
{
"user_id": id,
"session_expiry": time in seconds
}
If session_expiry is omitted or zero, then a session cookie will be set, which typically expires when the user's browser is closed. Be sure to set this to match your web app's cookie policy.
The API will return a token immediately:
{
"token": token
}
Note that this token will be valid only for a few minutes. Take the token and include it when you generate the following HTML:
<script src="//api.messagify.com/js/login.js?token=token"></script>
If you are not immediately rendering the HTML on your server, or if you have a single-page web app, you can pass the token as a cookie that can be read from JavaScript to add the the above to the page at the right time.
The above HTML only needs to sent to the browser after each login. The Messagify API will set a session cookie that expires according to what was passed in when requesting the token.
At this point, the user is free to move about your site and any widgets that are included in your pages will load automatically.
To explicitly log out a user (eg. from a logged out page), include the following code:
<script src="//api.messagify.com/js/logout.js"></script>
It's not necessary to pass a one-time token when logging out because the session cookie on the Messagify API domain identifies the currently logged in user.
The comment box renders a list of comments and a field for the current user to enter a new comment.
<script src="//api.messagify.com/js/comments.js"></script>
By default, the Comment Box will use the URL of the page to determine which comments to display. If the URL contains a hash (#) fragment, it will not be used as the basis for URL uniqueness.
The following CSS classes can be overridden by your app by including the relevant styles before including the Comment Box <script> tag:
messagify-comment-containermessagify-comment-postAn SDK for iOS is provided to make it easier to access Messagify functionality from native apps. With the SDK, you'll never need to deal with HTTP or JSON directly!
To get a list of comments for the specified topic id:
MSTopic *topic = [[[MSTopic alloc] initWitId:@"id"] autorelease];
NSArray *comments = [topic comments];
for(MSComment *comment in comments) {
NSLog(@"From %@: %@", comment.from.name, comment.text);
}
To post a new comment:
MSComment *comment = [topic commentWithText:@"who hearts apis?"]; [comment save];
To post a reply:
MSComment *reply = [comment replyWithText:@"THIS guy!"]; [reply saveInBackground];
A more complete SDK spec will be available at a later date, with support for asynchronous operations via blocks and callbacks.