IC.Notify - imonology/ImonCloud-Doc GitHub Wiki

---------------------------------------------------

IC.Notify.sendSMS(dst_num,text,onDone,media_urls,sp)

  • Description: Send an SMS message to a phone number or phone numbers.

Parameters

  1. dst_num
  • Type: String or Array of Strings
  • Description: Phone number which a message will be sent to. A phone number must start with a + and be followed by digits,for example +886912345678.
  1. text
  • Type: String
  • Description: Content of a message.
  1. onDone
  • Type: Function
  • Description: CallBack function.
  1. media_urls (optional)
  • Type:
  • Description: Not yet test.
  1. sp (optional)
  • Type:
  • Description: Service provider. Not yet implement.

Return Value

  • None

Example

var onDone = function (err, MIR) {
	if (err) {
		console.log(err.toString());
	}
	else {
		console.log(MIR);
	}
};
IC.Notify.sendSMS("+886912345678", "Hello World!", onDone);

---------------------------------------------------

IC.Notify.customizeMethod(name,cb)

  • Description: Add a customized notification method.

Parameters

  1. name
  • Type: String
  • Description: Name of customized method.
  1. cb
  • Type: Function
  • Description: Definition of customized method.
    • Parameters
      1. info
        • Type: Object
        • Description: Event information.
      2. user
        • Type: Object
        • Description: User data.

Return Value

  • true if type of cb is Function, otherwise false.

Example

var cb = function(info, user) {
	console.log("Hello " + user.account);
	console.log(info);
};
IC.Notify.customizeMethod("Hello", cb);

---------------------------------------------------

IC.Notify.register(level,methods,account,cb)

  • Description: Add an event level with notification methods to an account or all accounts. There are three built-in notification methods: SMS, email, client.

Parameters

  1. level
  • Type: String
  • Description: Name of an event level.
  1. methods
  • Type: Array of Strings
  • Description: Names of notification methods which will be registered to corresponding account and level.
  1. account (optional)
  • Type: String
  • Description: Account name. If it is not given, register methods to level of all accounts.
  1. cb
  • Type: Function
  • Description: CallBack function.
    • Parameters
      1. err
        • Type: Error Object
        • Description:

Return Value

  • None

Example

var cb = function (err) {
	if (err) {
		console.log(err.toString());
	}
};
IC.Notify.register("red", ["SMS", "email", "client", "Hello"], "kent", cb);

---------------------------------------------------

IC.Notify.subscribe(account,connection,cb)

  • Description: Subscribe account's notification levels which have client method for sending online web notifications to it.

Parameters

  1. account
  • Type: String
  • Description: Account name.
  1. connection
  • Type: Object
  • Description: Web socket connection object.
  1. cb
  • Type: Function
  • Description: CallBack function.
    • Parameters
      1. err
        • Type: Error Object
        • Description:

Return Value

  • None

Example

var cb = function (err) {
	if (err) {
		console.log(err.toString());
	}
};
IC.Notify.subscribe("kent", event.conn, cb);

---------------------------------------------------

IC.Notify.alert(name,info,level)

  • Description: Issue a notification to accounts who would like to receive it when an event occurred with specific level.

Parameters

  1. name
  • Type: String
  • Description: Event name.
  1. info
  • Type: Object
  • Description: Object providing event information. In current version, info must have a String type property msg as an event description.
  1. level
  • Type: String
  • Description: Event level.

Return Value

  • None

Example

var info = {msg: "This is a test."};
IC.Notify.alert("Hello World!", info, "black");

---------------------------------------------------

IC.Notify.ftpUpload(config,filepaths,cb)

  • Description: Upload files to home directory of an user of a FTP server.

Parameters

  1. config
  • Type: Object
  • Description: Object must have at least three String type properties: host, user and password. See this for more configurations.
  1. filepaths
  • Type: Object or Array of Objects
  • Description: Object must have two String type properties local and remote. local is the filepath which will be uploaded to remote, and remote is the filepath where local will be uploaded to.
  1. cb
  • Type: Function
  • Description: CallBack function.
    • Parameters
      1. err
        • Type: Error Object
        • Description: When uploading files, there may be errors and cb may be called multiple times. In this situation use Boolean type property fin to determine the last cb call. An event emitter should be implemented instead of using callbacks in the future.

Return Value

  • None

Example

var cb = function (err) {
	if (err) {
		if (err.fin) {
			event.done(err.toString(), "demo");
		}
		else {
			LOG.warn(err.toString(), "demo");
		}
	}
	else {
		event.done("OK");
	}
};

var filepath = [
	{
		local: "test_ftp.tmp",
		remote: "TEST_FTP1.tmp"
	},
	{
		local: "test_ftp.tmp",
		remote: "TEST_FTP2.tmp"
	},
	{
		local: "lobby/nonexist",
		remote: "TEST_FTP3.tmp"
	},
	{
		local: "lobby/handler.js",
		remote: "tmp/TEST_FTP4.tmp"
	},
	{
		local: "settings.js",
		remote: "TEST_FTP5.tmp"
	}
];

var config = {
	host: "src.imoncloud.com",
	user: IC.Settings.ftp.username,
	password: IC.Settings.ftp.password
};
	
IC.Notify.ftpUpload(config, filepath, cb);

---------------------------------------------------