@taoya785/flow-bark
Version:
Bark notification plugin for activepieces
74 lines (67 loc) • 1.99 kB
text/typescript
import {
createAction,
Property,
} from '@activepieces/pieces-framework'
import { auth } from '../auth'
import { buildBarkUrl, sendBarkNotification } from '../common/utils'
export const sendTimeSensitiveAction = createAction({
name: 'send_time_sensitive',
displayName: '发送时效性通知',
description: '发送一个时效性通知,可在专注状态下显示',
auth,
requireAuth: true,
props: {
title: Property.ShortText({
displayName: '标题',
description: '通知的标题',
required: false,
}),
subtitle: Property.ShortText({
displayName: '副标题',
description: '通知的副标题',
required: false,
}),
body: Property.LongText({
displayName: '内容',
description: '通知的内容',
required: true,
}),
url: Property.ShortText({
displayName: '跳转URL',
description: '点击通知后跳转的URL地址',
required: false,
}),
sound: Property.StaticDropdown({
displayName: '提示音',
description: '通知的提示音',
required: false,
options: {
disabled: false,
options: [
{ label: '默认', value: 'default' },
{ label: '预警', value: 'anticipate' },
{ label: '铃声', value: 'bell' },
{ label: '轻叮', value: 'chime' },
{ label: '通知', value: 'newsflash' },
],
},
}),
},
async run({ auth, propsValue }) {
const { baseUrl, key } = auth
const { title, subtitle, body, url, sound } = propsValue
// 构建推送URL
const pushUrl = buildBarkUrl(baseUrl, key, title, subtitle, body)
// 构建参数
const params: Record<string, string> = {
level: 'timeSensitive', // 时效性通知级别
}
if (url)
params.url = url
if (sound)
params.sound = sound
// 发送推送请求
const response = await sendBarkNotification(pushUrl, params)
return response.body
},
})