Javascript / Typescript quick start

Getting started with MySocialApp is very easy. However, if you have any questions get in touch.

🚧

NodeJS requirements

MySocialApp SDK need a recent version of node to run (> 10)

For Typescript project you need to add in your tsconfig.json
lib: [
"esnext.asynciterable"
]

❗️

Usage with javascript /dist folder files

If you use file without npm (https://github.com/MySocialApp/mysocialapp-ts-client/tree/master/dist) you must prefix all Object with "msa."
Example :
new msa.MySocialApp()

Models must be prefixed by msa.Models.
Example :
new msa.Models.FeedPost();

Get your free app

To use your own application follow this startup guide , otherwise you can use our testing app made available to start very quickly.

Testing app

app id: u470584465854a728453
URL: https://u470584465854a728453-api.mysocialapp.io

❗️

Beware of using the testing app

Do not share sensitive information on this instance. In addition, the data is likely to be erased very regularly.

Install the library

Node package manager (NPM)

in your package.json file add MySocialApp package library

{

  "dependencies": {
    "mysocialapp-ts-client": "^0.3.0",
  }
}

Code examples

Create an account

let msa = new MySocialApp().setAppId("u470584465854a728453");
let session = await msa.createAccount("[email protected]", "mySecretPassw0rd", "John");
let account = await session.account.get();

console.info("Account id", account.id);
console.info("Account created at", account.created_date);
let msa = new MySocialApp().setAppId("u470584465854a728453");
let sessionPromise = msa.createAccount("[email protected]", "mySecretPassw0rd", "John");
sessionPromise.then(function(session){
  let accountPromise = session.account.get();
  accountPromise.then(function(account){
    console.info("Account id", account.id);
    console.info("Account created at", account.created_date);
  });
});

See more about configuring the Typescript library

👍

Gift for testing users

Use your real e-mail address to receive a gift when you register :) In addition, you will see that you can integrate your application with any online service (eg: Mailchimp, Amazon AWS, Google Cloud, Zapier .. ) to react to events (new user, new comment, new photo, new post..) on your app.

Listen for notification events

session.websocket.onMessage((notification: Notification) => {
  switch(notification.type){
    // handler notification type
  }
});
// session2.websocket.close();
session.websocket.onMessage(function(notification: Notification) {
  switch(notification.type){
    // handler notification type
  }
});
// session2.websocket.close();

See more about configuring notification events here

Create post (News Feed / Activity Stream)

A feed post can contain text, image, hashtags, web links, mentions of users. Web links are rewritten and tracked. Publications can be public or visible only from his contacts.

let message = "Hello, my name is [[user:" + account.id + "]] this is a post can be viewed by my friends with an image and #hashtag :)";

let feedPost = (new FeedPost())
    .setMessage(message)
    .setImage(new FileData().loadFromFileBrowser(myBlob)) // add blob
    .setVisibility(AccessControl.Friend);

let feed = await session.newsFeed.create(post);
let message = "Hello, my name is [[user:" + account.id + "]] this is a post can be viewed by my friends with an image and #hashtag :)";

let feedPost = (new FeedPost())
    .setMessage(message)
    .setImage(new FileData().loadFromFileBrowser(myBlob)) // add blob
    .setVisibility(AccessControl.Friend);

session.newsFeed.create(post).then(function(feed){
    console.info("feed id", feed.id);
})

Posts can be published on the public, user, group, event news feed. Dynamic type of feed can be added. (e.g: Product news feed)

Add comment to Post

Each post can receive comments (+ likes) and allow interactions between users. Notifications are sent to warn participants. As well as the feed post, comment can contain text, image, hashtags, web links, mentions of users.

let commentPost = (new CommentPost())
    .setMessage("Here a comment")
    .setImage(new FileData().loadFromFileBrowser(myBlob)); // blob
                                    
let comment = await feed.addComment(commentPost);
let commentPost = (new CommentPost())
    .setMessage("Here a comment")
    .setImage(new FileData().loadFromFileBrowser(myBlob)); // blob
                                    
feed.addComment(commentPost).then(function(comment){
    console.info("comment id", comment.id);
});

Create event

Invite users to participate in an event. E.g: notify the users of the final of the World Cup on Sunday, at 9:00pm. You can add a description as well as custom fields to fit your needs.

let location = new Location({location: {latitude: 48.866667, longitude: 2.333333}});
let startDate = moment().add(1, "days");
let endDate  moment().add(2, "days");
let description = "Adding social networking features to your app has never been so easy. Integrate MySocialApp with your app and engage users via realtime messaging. No more infrastructure hell, no hassle, just add it."

let eventPost = new Event().setName("Let's create an event")
        .setMaxSeats(10)
        .setDescription()
        .setStartDate(startDate)
        .setEndDate(endDate)
        .setAccessControl(EventMemberAccessControl.Public) // public event
        .setLocation(location);

let event = await session1.event.create(eventPost);
let location = new Location({location: {latitude: 48.866667, longitude: 2.333333}});
let startDate = moment().add(1, "days");
let endDate  moment().add(2, "days");
let description = "Adding social networking features to your app has never been so easy. Integrate MySocialApp with your app and engage users via realtime messaging. No more infrastructure hell, no hassle, just add it."

let eventPost = new Event().setName("Let's create an event")
        .setMaxSeats(10)
        .setDescription()
        .setStartDate(startDate)
        .setEndDate(endDate)
        .setAccessControl(EventMemberAccessControl.Public) // public event
        .setLocation(location);

session1.event.create(eventPost).then(function(event){
    console.info("event id", event.id);
});