UNPKG

@taoya785/flow-bark

Version:

Bark notification plugin for activepieces

137 lines (131 loc) 4.45 kB
import { createAction, Property, } from '@activepieces/pieces-framework' import { auth } from '../auth' import { buildBarkUrl, sendBarkNotification } from '../common/utils' export const sendNotificationAction = createAction({ name: 'send_notification', displayName: '发送推送通知', description: '发送一个Bark推送通知', 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, }), group: Property.ShortText({ displayName: '分组', description: '推送的分组名称', required: false, }), icon: Property.ShortText({ displayName: '图标', description: '自定义推送图标的URL (仅iOS15及以上支持)', required: false, }), sound: Property.StaticDropdown({ displayName: '提示音', description: '推送的提示音', required: false, options: { disabled: false, options: [ { label: '默认', value: 'default' }, { label: '警报', value: 'alarm' }, { label: '预警', value: 'anticipate' }, { label: '铃声', value: 'bell' }, { label: '鸟叫', value: 'birdsong' }, { label: '上升', value: 'bloom' }, { label: '书签', value: 'calypso' }, { label: '轻叮', value: 'chime' }, { label: '合唱', value: 'choo' }, { label: '倒计时', value: 'descent' }, { label: '电子', value: 'electronic' }, { label: '梦幻', value: 'fanfare' }, { label: '玻璃', value: 'glass' }, { label: '哼唱', value: 'gotosleep' }, { label: '脉冲', value: 'healthnotification' }, { label: '信号', value: 'horn' }, { label: '阶梯', value: 'ladder' }, { label: '邮件', value: 'mailsent' }, { label: '机械', value: 'minuet' }, { label: '完成', value: 'multiwayinvitation' }, { label: '新消息', value: 'newmail' }, { label: '通知', value: 'newsflash' }, { label: '礼物', value: 'noir' }, { label: '暂停', value: 'paymentsuccess' }, { label: '滚动', value: 'shake' }, { label: '摇铃', value: 'sherwoodforest' }, { label: '轻弹', value: 'silence' }, { label: '明星', value: 'spell' }, { label: '悬念', value: 'suspense' }, { label: '轻敲', value: 'telegraph' }, { label: '主题', value: 'tiptoes' }, { label: '打字', value: 'typewriters' }, { label: '更新', value: 'update' }, ], }, }), level: Property.StaticDropdown({ displayName: '推送级别', description: '推送通知的级别', required: false, options: { disabled: false, options: [ { label: '默认', value: 'active' }, { label: '时效性通知', value: 'timeSensitive' }, { label: '被动通知', value: 'passive' }, { label: '重要警告', value: 'critical' }, ], }, }), call: Property.Checkbox({ displayName: '连续响铃', description: '设置通知铃声是否循环播放', required: false, defaultValue: false, }), }, async run({ auth, propsValue }) { const { baseUrl, key } = auth const { title, subtitle, body, url, group, icon, sound, level, call } = propsValue // 构建推送URL const pushUrl = buildBarkUrl(baseUrl, key, title, subtitle, body) // 构建参数 const params: Record<string, string> = {} 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 sendBarkNotification(pushUrl, params) return response.body }, })