Wiki source code of Notification

Version 6.1 by Maurice Gasco on 2015/10/30 09:55

Show last authors
1 (% style="font-family: sans-serif; font-size: 14px; font-style: normal; font-weight: normal; text-align: start; line-height: 19.6px;" %)
2 Api to send emails or SMS using a notification template. Notification templates can be defined in Administration tab, "Workflows and Notifications" menu and "Notifications Templates" menu
3
4 (% style="font-family: sans-serif; font-style: normal; text-align: start;" %)
5 == (% style="font-size: 22.54px; background-color: rgb(245, 245, 245);" %)Functions(%%) ==
6
7 (% style="font-family: sans-serif; font-style: normal; text-align: start;" %)
8 === (% style="font-size: 20.44px;" %)init(template)(%%) ===
9
10 (% style="font-family: sans-serif; font-size: 14px; font-style: normal; font-weight: normal; text-align: start; line-height: 19.6px;" %)
11 Init the notification with the template. template in an Entity object.
12
13 (% style="font-family: sans-serif; font-style: normal; text-align: start;" %)
14 === (% style="font-size: 20.44px;" %)setFrom(email, title)(%%) ===
15
16 (% style="font-family: sans-serif; font-size: 14px; font-style: normal; font-weight: normal; text-align: start; line-height: 19.6px;" %)
17 Set the sender informations.
18
19 * email is a string representing the email address of the sender.
20 * title is a string representing his name.
21
22 (% style="font-family: sans-serif; font-style: normal; text-align: start;" %)
23 === (% style="font-size: 20.44px;" %)setReplyTo(email, title)(%%) ===
24
25 (% style="font-family: sans-serif; font-size: 14px; font-style: normal; font-weight: normal; text-align: start; line-height: 19.6px;" %)
26 Set the "reply to" informations.
27
28 * email is a string representing the email address of the sender.
29 * title is a string representing his name.
30
31 (% style="font-family: sans-serif; font-style: normal; text-align: start;" %)
32 === (% style="font-size: 20.44px;" %)setTo(recipient, group)(%%) ===
33
34 (% style="font-family: sans-serif; font-size: 14px; font-style: normal; font-weight: normal; text-align: start; line-height: 19.6px;" %)
35 Set the recipient informations
36
37 (% style="font-family: sans-serif; font-size: 14px; font-style: normal; font-weight: normal; text-align: start; line-height: 19.6px;" %)
38 * recipient is either :
39 (% style="font-size: 14px;" %)
40 ** a string representing an email address
41 ** an Entity object representing a User or a Group
42 ** an Array of Entity objects of Users or Groups
43 * group is an Entity object representing a group used for delegation
44
45 (% style="font-family: sans-serif; font-style: normal; text-align: start;" %)
46 === (% style="font-size: 20.44px;" %)setCc(recipient)(%%) ===
47
48 (% style="font-family: sans-serif; font-size: 14px; font-style: normal; font-weight: normal; text-align: start; line-height: 19.6px;" %)
49 Set the copy informations
50
51 (% style="font-family: sans-serif; font-size: 14px; font-style: normal; font-weight: normal; text-align: start; line-height: 19.6px;" %)
52 * recipient is either :
53 (% style="font-size: 14px;" %)
54 ** a string representing an email address
55 ** an Entity object representing a User or a Group
56 ** an Array of Entity objects of Users or Groups
57
58 (% style="font-family: sans-serif; font-style: normal; text-align: start;" %)
59 === (% style="font-size: 20.44px;" %)setBCc(recipient)(%%) ===
60
61 (% style="font-family: sans-serif; font-size: 14px; font-style: normal; font-weight: normal; text-align: start; line-height: 19.6px;" %)
62 Set the copy informations
63
64 (% style="font-family: sans-serif; font-size: 14px; font-style: normal; font-weight: normal; text-align: start; line-height: 19.6px;" %)
65 * recipient is either :
66 (% style="font-size: 14px;" %)
67 ** a string representing an email address
68 ** an Entity object representing a User or a Group
69 ** an Array of Entity objects of Users or Groups
70
71 (% style="font-family: sans-serif; font-size: 14px; font-style: normal; font-weight: normal; text-align: start;" %)
72 (((
73 (% style="font-family: sans-serif; font-style: normal; text-align: start;" %)
74 === (% style="font-size: 20.44px;" %)setVariable(name, data)(%%) ===
75
76 (% style="font-family: sans-serif; font-size: 14px; font-style: normal; font-weight: normal; text-align: start; line-height: 19.6px;" %)
77 Set a variable in the javascript context used to compose the notification. Subject and Body of the notification template can be composed dynamically with variable resolution using the following syntax : ${data.rqTitle}
78
79 (% style="font-family: sans-serif; font-size: 14px; font-style: normal; font-weight: normal; text-align: start; line-height: 19.6px;" %)
80 * name is the variable name, for example "data"
81 * data is an Entity object or a basic javascript object
82
83 (((
84 (% style="font-family: sans-serif; font-style: normal; text-align: start;" %)
85 === (% style="font-size: 20.44px;" %)compose()(%%) ===
86
87 (% style="font-family: sans-serif; font-size: 14px; font-style: normal; font-weight: normal; text-align: start; line-height: 19.6px;" %)
88 Build the notification using the templates, parameters and variables set and returns en Entity object representing the notification. The notification can be modified before being sent.
89 )))
90 )))
91
92
93 (% style="font-family: sans-serif; font-size: 14px; font-style: normal; font-weight: normal; text-align: start;" %)
94 (((
95 (% style="font-size: 14px;" %)
96 (((
97 (% style="font-family: sans-serif; font-style: normal; text-align: start;" %)
98 === (% style="font-size: 20.44px;" %)send()(%%) ===
99
100 (% style="font-family: sans-serif; font-size: 14px; font-style: normal; font-weight: normal; text-align: start; line-height: 19.6px;" %)
101 Compose and send the notification
102 )))
103 )))
104
105
106 (% style="text-align: start;" %)
107 (((
108 (((
109 (% style="font-family: sans-serif; font-size: 14px; font-style: normal; font-weight: normal; text-align: start;" %)
110 === (% style="font-size: 20.44px;" %)send(notification)(%%) ===
111
112 (% style="text-align: start;" %)
113 (% style="line-height: 19.6px;" %)Send the notification.
114
115 * notification is an Entity object representing the notification. This object is the result of the compose function
116 )))
117 )))
118
119
120
121
122
123 (% style="font-family: sans-serif; font-style: normal; text-align: start;" %)
124 === (% style="color: rgb(34, 34, 34); font-family: sans-serif; font-size: 14px; font-style: normal; font-weight: normal; line-height: 19.6px; text-align: start; background-color: rgb(245, 245, 245);" %)Example:(%%) ===
125
126 {{code language="javascript"}}
127 var notif = new Notification();
128 var template = sysNotificationTemplate.Get('402881e650a9d76c0150b7f4299d29ce');
129 notif.init(template);
130 notif.setVariable("data", data);
131
132 notif.setTo("user1@gmail.com");
133 notif.setTo("user2@gmail.com");
134 notif.setFrom("noreply@requea.com");
135 notif.send();
136 {{/code}}
This wiki is licensed under a Creative Commons 2.0 license
XWiki Enterprise 9.11.5 - Documentation