IC.Notify - imonology/ImonCloud-Doc GitHub Wiki
-
sendSMS(dst_num,text,onDone,media_urls,sp)
- Description: Send an SMS message to a phone number or phone numbers.
-
- Description: Add a customized notification method.
-
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
.
- Description: Add an event level with notification methods to an account or all accounts. There are three built-in notification methods:
-
subscribe(account,connection,cb)
- Description: Subscribe account's notification levels which have
client
method for sending online web notifications to it.
- Description: Subscribe account's notification levels which have
-
- Description: Issue a notification to accounts who would like to receive it when an event occurred with specific level.
-
ftpUpload(config,filepaths,cb)
- Description: Upload files to home directory of an user of a FTP server.
---------------------------------------------------
IC.Notify.sendSMS(dst_num,text,onDone,media_urls,sp)
- Description: Send an SMS message to a phone number or phone numbers.
Parameters
- dst_num
- Type:
String
orArray 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
.
- text
- Type:
String
- Description: Content of a message.
- onDone
- Type:
Function
- Description: CallBack function.
- Parameters
- err
- Type:
Error Object
- Description:
- Type:
- MIR
- Type:
Object
- Description: Message Instance Resource
- Type:
- err
- Parameters
- media_urls (optional)
- Type:
- Description: Not yet test.
- 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
- name
- Type:
String
- Description: Name of customized method.
- cb
- Type:
Function
- Description: Definition of customized method.
- Parameters
- info
- Type:
Object
- Description: Event information.
- Type:
- user
- Type:
Object
- Description: User data.
- Type:
- info
- Parameters
Return Value
true
if type ofcb
isFunction
, otherwisefalse
.
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
- level
- Type:
String
- Description: Name of an event level.
- methods
- Type:
Array of Strings
- Description: Names of notification methods which will be registered to corresponding
account
andlevel
.
- account (optional)
- Type:
String
- Description: Account name. If it is not given, register
methods
tolevel
of all accounts.
- cb
- Type:
Function
- Description: CallBack function.
- Parameters
- err
- Type:
Error Object
- Description:
- Type:
- err
- Parameters
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
- account
- Type:
String
- Description: Account name.
- connection
- Type:
Object
- Description: Web socket connection object.
- cb
- Type:
Function
- Description: CallBack function.
- Parameters
- err
- Type:
Error Object
- Description:
- Type:
- err
- Parameters
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
- name
- Type:
String
- Description: Event name.
- info
- Type:
Object
- Description: Object providing event information. In current version,
info
must have aString
type propertymsg
as an event description.
- 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
- config
- Type:
Object
- Description: Object must have at least three
String
type properties:host
,user
andpassword
. See this for more configurations.
- filepaths
- Type:
Object
orArray of Objects
- Description: Object must have two
String
type propertieslocal
andremote
.local
is the filepath which will be uploaded toremote
, andremote
is the filepath wherelocal
will be uploaded to.
- cb
- Type:
Function
- Description: CallBack function.
- Parameters
- err
- Type:
Error Object
- Description: When uploading files, there may be errors and
cb
may be called multiple times. In this situation useBoolean
type propertyfin
to determine the lastcb
call. An event emitter should be implemented instead of using callbacks in the future.
- Type:
- err
- Parameters
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);
---------------------------------------------------