|
@@ -60,6 +60,14 @@ const configSchema = {
|
|
|
minimum: 1,
|
|
minimum: 1,
|
|
|
maximum: 200
|
|
maximum: 200
|
|
|
},
|
|
},
|
|
|
|
|
+ retries: {
|
|
|
|
|
+ type: 'number', title: 'Retries', default: 1,
|
|
|
|
|
+ description: 'Extra attempts when Nextcloud times out or answers 429, 500, 502, 503 or 504. Posting a message is safe to repeat'
|
|
|
|
|
+ },
|
|
|
|
|
+ skipOnError: {
|
|
|
|
|
+ type: 'boolean', title: 'Skip On Error', default: false,
|
|
|
|
|
+ description: 'Return success false instead of failing the workflow. A notification that could not be sent is rarely worth ending a run over - least of all when the run is already reporting a problem'
|
|
|
|
|
+ },
|
|
|
timeoutMs: {
|
|
timeoutMs: {
|
|
|
type: 'number',
|
|
type: 'number',
|
|
|
title: 'Timeout (ms)',
|
|
title: 'Timeout (ms)',
|
|
@@ -80,6 +88,7 @@ const inputSchema = {
|
|
|
const outputSchema = {
|
|
const outputSchema = {
|
|
|
type: 'object',
|
|
type: 'object',
|
|
|
properties: {
|
|
properties: {
|
|
|
|
|
+ error: { type: 'string', description: 'Why the send failed, when Skip On Error let the run carry on' },
|
|
|
success: { type: 'boolean' },
|
|
success: { type: 'boolean' },
|
|
|
messageId: { type: 'integer', description: 'The id Talk gave the posted message' },
|
|
messageId: { type: 'integer', description: 'The id Talk gave the posted message' },
|
|
|
token: { type: 'string', description: 'The conversation it was posted to' },
|
|
token: { type: 'string', description: 'The conversation it was posted to' },
|
|
@@ -185,13 +194,8 @@ function unwrapOcs(response, what) {
|
|
|
return ocs.data;
|
|
return ocs.data;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-module.exports = {
|
|
|
|
|
- configSchema,
|
|
|
|
|
- inputSchema,
|
|
|
|
|
- outputSchema,
|
|
|
|
|
- outputs,
|
|
|
|
|
-
|
|
|
|
|
- async execute(config, input, context) {
|
|
|
|
|
|
|
+async function talk(config, input, context) {
|
|
|
|
|
+ {
|
|
|
const from = incoming(input);
|
|
const from = incoming(input);
|
|
|
|
|
|
|
|
const base = String(config.baseUrl || '').replace(/\/+$/, '');
|
|
const base = String(config.baseUrl || '').replace(/\/+$/, '');
|
|
@@ -218,7 +222,9 @@ module.exports = {
|
|
|
method: 'GET',
|
|
method: 'GET',
|
|
|
url: chatUrl + '?format=json&lookIntoFuture=0&limit=' + limit,
|
|
url: chatUrl + '?format=json&lookIntoFuture=0&limit=' + limit,
|
|
|
headers: headers,
|
|
headers: headers,
|
|
|
- timeout: timeout
|
|
|
|
|
|
|
+ timeout: timeout,
|
|
|
|
|
+ retries: Number(config.retries) >= 0 ? Number(config.retries) : 1,
|
|
|
|
|
+ retryDelayMs: 2000
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
const data = unwrapOcs(response, 'read') || [];
|
|
const data = unwrapOcs(response, 'read') || [];
|
|
@@ -258,7 +264,9 @@ module.exports = {
|
|
|
url: chatUrl + '?format=json',
|
|
url: chatUrl + '?format=json',
|
|
|
headers: headers,
|
|
headers: headers,
|
|
|
body: JSON.stringify(payload),
|
|
body: JSON.stringify(payload),
|
|
|
- timeout: timeout
|
|
|
|
|
|
|
+ timeout: timeout,
|
|
|
|
|
+ retries: Number(config.retries) >= 0 ? Number(config.retries) : 1,
|
|
|
|
|
+ retryDelayMs: 2000
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
const data = unwrapOcs(response, 'send') || {};
|
|
const data = unwrapOcs(response, 'send') || {};
|
|
@@ -270,4 +278,27 @@ module.exports = {
|
|
|
token: token
|
|
token: token
|
|
|
};
|
|
};
|
|
|
}
|
|
}
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+module.exports = {
|
|
|
|
|
+ configSchema,
|
|
|
|
|
+ inputSchema,
|
|
|
|
|
+ outputSchema,
|
|
|
|
|
+ outputs,
|
|
|
|
|
+
|
|
|
|
|
+ async execute(config, input, context) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ return await talk(config, input, context);
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ if (config.skipOnError !== true) {
|
|
|
|
|
+ throw err;
|
|
|
|
|
+ }
|
|
|
|
|
+ // A notification that could not be sent is rarely worth ending a run
|
|
|
|
|
+ // over - least of all when the run is already reporting a problem,
|
|
|
|
|
+ // where failing here would put back the very failure it replaced.
|
|
|
|
|
+ const message = (err && err.message) ? err.message : String(err);
|
|
|
|
|
+ smartbotic.log.warn('Nextcloud Talk: skipping after ' + message);
|
|
|
|
|
+ return { success: false, error: message, messageId: null, token: config.token || '' };
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
};
|
|
};
|