summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornztqa <nztqa@users.noreply.github.com>2017-07-09 15:02:17 +0900
committernztqa <nztqa@users.noreply.github.com>2017-07-09 15:02:17 +0900
commit429e2f9992c94248c54f1f77127f8d0b003e7a7c (patch)
tree2c5a327ad3d0bb0466afbacd8a857a71bb925866
parentbcd42ad958159d1501b8f9a3df0f4a1ff1076f5b (diff)
downloadwekan-429e2f9992c94248c54f1f77127f8d0b003e7a7c.tar.gz
wekan-429e2f9992c94248c54f1f77127f8d0b003e7a7c.tar.bz2
wekan-429e2f9992c94248c54f1f77127f8d0b003e7a7c.zip
Add method outgoingWebhooks
-rw-r--r--server/notifications/outgoing.js47
1 files changed, 47 insertions, 0 deletions
diff --git a/server/notifications/outgoing.js b/server/notifications/outgoing.js
new file mode 100644
index 00000000..a5bbc737
--- /dev/null
+++ b/server/notifications/outgoing.js
@@ -0,0 +1,47 @@
+const postCatchError = Meteor.wrapAsync((url, options, resolve) => {
+ HTTP.post(url, options, (err, res) => {
+ if (err) {
+ resolve(null, err.response);
+ } else {
+ resolve(null, res);
+ }
+ });
+});
+
+Meteor.methods({
+ outgoingWebhooks(integration, description, params) {
+ check(integration, Object);
+ check(description, String);
+ check(params, Object);
+
+ const quoteParams = _.clone(params);
+ ['card', 'list', 'oldList', 'board', 'comment'].forEach((key) => {
+ if (quoteParams[key]) quoteParams[key] = `"${params[key]}"`;
+ });
+
+ const user = Users.findOne(integration.userId);
+ const text = `${params.user} ${TAPi18n.__(description, quoteParams, user.getLanguage())}\n${params.url}`;
+
+ if (text.length === 0) return;
+
+ const value = {
+ text: `${text}`,
+ };
+
+ const options = {
+ headers: {
+ // 'Content-Type': 'application/json',
+ // 'X-Wekan-Activities-Token': 'Random.Id()',
+ },
+ data: value,
+ };
+
+ const response = postCatchError(integration.url, options);
+
+ if (response && response.statusCode && response.statusCode === 200) {
+ return true; // eslint-disable-line consistent-return
+ } else {
+ throw new Meteor.Error('error-invalid-webhook-response');
+ }
+ },
+});