Communicate JS APIs

The fliplet-communicate package contains the namespace Fliplet.Communicate and a set of helper methods for sending communications from the app.

Send an email

Available options:

var options = {
  to: [
    { email: "john@example.org", name: "John", type: "to" }
  ],
  html: "<p>Some HTML content</p>",
  subject: "My subject",
  from_name: "Example Name",
  headers: {
    "Reply-To": "message.reply@example.com"
  },
  attachments: [
    {
      type: "text/plain",
      name: "myfile.txt",
      content: "Hello World"
    }
  ],
  images: [
    {
      type: "image/png",
      name: "test.png",
      content: "insert_base64_content_here"
    }
  ]
};

// Returns a promise
Fliplet.Communicate.sendEmail(options);

More options can be found on the official documentation for Mandrill, the email provider Fliplet relies on.

You can also {{ variables }} expressions in your options if you want the template to be compiled with other data:

var options = {
  to: [ { email: "{{ emailTo }}", type: "to" } ],
  html: "<p>Hi {{ userName }}</p>"
};

// This will compile any string template in your options
// with the input data passed as second parameter of the function.
Fliplet.Communicate.sendEmail(options, {
  emailTo: 'john@example.com',
  userName: 'John Doe'
});

Note: input options will get their value altered by the function as a result of the compilation process. If you want to preserve the input object original value, please make a copy as follows:

// Here we're using lodash "extend" method to make a copy of our options
// before they're sent to the "sendEmail" function.
Fliplet.Communicate.sendEmail(_.extend({}, options));

Send an SMS

Default provider

const options = {
  data: {
    to: "+123456789",
    body: "Hey!"
  }
};

Fliplet.Communicate.sendSMS(options);

Twilio

const options = {
  provider: "twilio"
  data: {
    from: "+123456789"
    to: "+123456789",
    body: "Hey!"
  },
  options: {
    twilio_sid: 'AC81caaa94b3b84bb7ba9c3cd96bcb152a', // Your Account SID from www.twilio.com/console
    twilio_auth_token: 'AUTH_TOKEN';                  // Your Auth Token from www.twilio.com/console
  }
};

Fliplet.Communicate.sendSMS(options);

Let us know if you require to use another SMS provider and we’ll check whether we can integrate it on our system.


Share a URL

Screenshots

Native apps

Native apps will use the operating systems’ built-in features to integrate with any other apps installed on the device.

iOS Android

Web apps

Web apps will show users a URL to copy and provide icons to share the URL with popular servives.

Desktop Mobile

Fliplet.Communicate.shareURL()

(Returns Promise)

Fliplet.Communicate.shareURL() lets users share a URL. The Promise is resolved when the action is completed or dismissed. The share options are passed to the resolving function, with an additional completed property to signify if an action was completed or cancelled.

// A simple way to share a URL
Fliplet.Communicate.shareURL('https://maps.google.com/?addr=EC2A+4DN');

// Add an optional message for apps that support the sharing a URL with a message
Fliplet.Communicate.shareURL({
  url: 'https://maps.google.com/?addr=EC2A+4DN',
  message: 'Drop by and say hi!'
});

Recommendation: Optionally provide a target to enure the share popover appears in the right place on iPads.

Fliplet.Communicate.shareURL({
  url: 'https://maps.google.com/?addr=EC2A+4DN',
  target: '#target'
});

jsSocials is used in web apps to let users share URLs using the following services:

Optionally provide an array of services in shares to use any of the services supported by jsSocials (see Example below).

Examples

Share a URL

Fliplet.Communicate.shareURL({
  url: 'https://maps.google.com/?addr=EC2A+4DN',
  shares: [
    'email', 'twitter', 'facebook', 'googleplus', 'linkedin',
    'pinterest', 'stumbleupon', 'pocket', 'whatsapp', 'viber',
    'messenger', 'vkontakte', 'telegram', 'line'
  ]
});

Note: The following services only work on native devices if the app is installed.

Share a page in a Fliplet app

See documentation for Fliplet.Content.


Send push notifications

(Returns Promise)

Available options:

Fliplet.Communicate.sendPushNotification(appId, {
  title: 'Lorem ipsum',
  body: 'Irure sed ad do dolor ad ut ut anim.'
});

Note: only app publishers and editors are allowed to send push notifications.


Back to API documentation