mirror of
https://github.com/wekan/wekan.git
synced 2025-04-24 05:57:13 -04:00
Add method outgoingWebhooks
This commit is contained in:
parent
bcd42ad958
commit
429e2f9992
1 changed files with 47 additions and 0 deletions
47
server/notifications/outgoing.js
Normal file
47
server/notifications/outgoing.js
Normal file
|
@ -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');
|
||||
}
|
||||
},
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue