@taoya785/flow-bark
Version:
Bark notification plugin for activepieces
131 lines (127 loc) • 5.18 kB
JavaScript
'use strict';
const piecesFramework = require('@activepieces/pieces-framework');
const auth = require('../auth.js');
const utils = require('../common/utils.js');
const sendNotificationAction = piecesFramework.createAction({
name: "send_notification",
displayName: "\u53D1\u9001\u63A8\u9001\u901A\u77E5",
description: "\u53D1\u9001\u4E00\u4E2ABark\u63A8\u9001\u901A\u77E5",
auth: auth.auth,
requireAuth: true,
props: {
title: piecesFramework.Property.ShortText({
displayName: "\u6807\u9898",
description: "\u63A8\u9001\u901A\u77E5\u7684\u6807\u9898",
required: false
}),
subtitle: piecesFramework.Property.ShortText({
displayName: "\u526F\u6807\u9898",
description: "\u63A8\u9001\u901A\u77E5\u7684\u526F\u6807\u9898",
required: false
}),
body: piecesFramework.Property.LongText({
displayName: "\u5185\u5BB9",
description: "\u63A8\u9001\u901A\u77E5\u7684\u6B63\u6587\u5185\u5BB9",
required: true
}),
url: piecesFramework.Property.ShortText({
displayName: "\u8DF3\u8F6CURL",
description: "\u70B9\u51FB\u63A8\u9001\u540E\u8DF3\u8F6C\u7684URL\u5730\u5740",
required: false
}),
group: piecesFramework.Property.ShortText({
displayName: "\u5206\u7EC4",
description: "\u63A8\u9001\u7684\u5206\u7EC4\u540D\u79F0",
required: false
}),
icon: piecesFramework.Property.ShortText({
displayName: "\u56FE\u6807",
description: "\u81EA\u5B9A\u4E49\u63A8\u9001\u56FE\u6807\u7684URL (\u4EC5iOS15\u53CA\u4EE5\u4E0A\u652F\u6301)",
required: false
}),
sound: piecesFramework.Property.StaticDropdown({
displayName: "\u63D0\u793A\u97F3",
description: "\u63A8\u9001\u7684\u63D0\u793A\u97F3",
required: false,
options: {
disabled: false,
options: [
{ label: "\u9ED8\u8BA4", value: "default" },
{ label: "\u8B66\u62A5", value: "alarm" },
{ label: "\u9884\u8B66", value: "anticipate" },
{ label: "\u94C3\u58F0", value: "bell" },
{ label: "\u9E1F\u53EB", value: "birdsong" },
{ label: "\u4E0A\u5347", value: "bloom" },
{ label: "\u4E66\u7B7E", value: "calypso" },
{ label: "\u8F7B\u53EE", value: "chime" },
{ label: "\u5408\u5531", value: "choo" },
{ label: "\u5012\u8BA1\u65F6", value: "descent" },
{ label: "\u7535\u5B50", value: "electronic" },
{ label: "\u68A6\u5E7B", value: "fanfare" },
{ label: "\u73BB\u7483", value: "glass" },
{ label: "\u54FC\u5531", value: "gotosleep" },
{ label: "\u8109\u51B2", value: "healthnotification" },
{ label: "\u4FE1\u53F7", value: "horn" },
{ label: "\u9636\u68AF", value: "ladder" },
{ label: "\u90AE\u4EF6", value: "mailsent" },
{ label: "\u673A\u68B0", value: "minuet" },
{ label: "\u5B8C\u6210", value: "multiwayinvitation" },
{ label: "\u65B0\u6D88\u606F", value: "newmail" },
{ label: "\u901A\u77E5", value: "newsflash" },
{ label: "\u793C\u7269", value: "noir" },
{ label: "\u6682\u505C", value: "paymentsuccess" },
{ label: "\u6EDA\u52A8", value: "shake" },
{ label: "\u6447\u94C3", value: "sherwoodforest" },
{ label: "\u8F7B\u5F39", value: "silence" },
{ label: "\u660E\u661F", value: "spell" },
{ label: "\u60AC\u5FF5", value: "suspense" },
{ label: "\u8F7B\u6572", value: "telegraph" },
{ label: "\u4E3B\u9898", value: "tiptoes" },
{ label: "\u6253\u5B57", value: "typewriters" },
{ label: "\u66F4\u65B0", value: "update" }
]
}
}),
level: piecesFramework.Property.StaticDropdown({
displayName: "\u63A8\u9001\u7EA7\u522B",
description: "\u63A8\u9001\u901A\u77E5\u7684\u7EA7\u522B",
required: false,
options: {
disabled: false,
options: [
{ label: "\u9ED8\u8BA4", value: "active" },
{ label: "\u65F6\u6548\u6027\u901A\u77E5", value: "timeSensitive" },
{ label: "\u88AB\u52A8\u901A\u77E5", value: "passive" },
{ label: "\u91CD\u8981\u8B66\u544A", value: "critical" }
]
}
}),
call: piecesFramework.Property.Checkbox({
displayName: "\u8FDE\u7EED\u54CD\u94C3",
description: "\u8BBE\u7F6E\u901A\u77E5\u94C3\u58F0\u662F\u5426\u5FAA\u73AF\u64AD\u653E",
required: false,
defaultValue: false
})
},
async run({ auth: auth2, propsValue }) {
const { baseUrl, key } = auth2;
const { title, subtitle, body, url, group, icon, sound, level, call } = propsValue;
const pushUrl = utils.buildBarkUrl(baseUrl, key, title, subtitle, body);
const params = {};
if (url)
params.url = url;
if (group)
params.group = group;
if (icon)
params.icon = icon;
if (sound)
params.sound = sound;
if (level)
params.level = level;
if (call)
params.call = "1";
const response = await utils.sendBarkNotification(pushUrl, params);
return response.body;
}
});
exports.sendNotificationAction = sendNotificationAction;