|  | 
|  | 1 | +import alerty from "../../alerty.app.mjs"; | 
|  | 2 | +import { URGENCY_OPTIONS } from "../../common/constants.mjs"; | 
|  | 3 | +import { parseObject } from "../../common/utils.mjs"; | 
|  | 4 | + | 
|  | 5 | +export default { | 
|  | 6 | +  key: "alerty-notify-devices", | 
|  | 7 | +  name: "Notify Devices", | 
|  | 8 | +  description: "Sends a notification to active devices. [See the documentation](https://alerty.dev/api/notify)", | 
|  | 9 | +  version: "0.0.1", | 
|  | 10 | +  type: "action", | 
|  | 11 | +  props: { | 
|  | 12 | +    alerty, | 
|  | 13 | +    message: { | 
|  | 14 | +      type: "string", | 
|  | 15 | +      label: "Message", | 
|  | 16 | +      description: "The message to be included in the push notification.", | 
|  | 17 | +    }, | 
|  | 18 | +    title: { | 
|  | 19 | +      type: "string", | 
|  | 20 | +      label: "Title", | 
|  | 21 | +      description: "Title for your notification message.", | 
|  | 22 | +      optional: true, | 
|  | 23 | +    }, | 
|  | 24 | +    image: { | 
|  | 25 | +      type: "string", | 
|  | 26 | +      label: "Image URL", | 
|  | 27 | +      description: "URL of an image to be displayed in the notification.", | 
|  | 28 | +      optional: true, | 
|  | 29 | +    }, | 
|  | 30 | +    icon: { | 
|  | 31 | +      type: "string", | 
|  | 32 | +      label: "Icon URL", | 
|  | 33 | +      description: "URL of an image to be used as an icon by the notification. Default: Alerty Logo", | 
|  | 34 | +      optional: true, | 
|  | 35 | +    }, | 
|  | 36 | +    deviceId: { | 
|  | 37 | +      type: "string[]", | 
|  | 38 | +      label: "Device ID", | 
|  | 39 | +      description: "Specific device IDs to send the notification to. If no Device Id is included, the push message will be sent to all active devices on your account.", | 
|  | 40 | +      optional: true, | 
|  | 41 | +    }, | 
|  | 42 | +    urgency: { | 
|  | 43 | +      type: "string", | 
|  | 44 | +      label: "Urgency", | 
|  | 45 | +      description: "Urgency of the notification. Default: very-low", | 
|  | 46 | +      options: URGENCY_OPTIONS, | 
|  | 47 | +      optional: true, | 
|  | 48 | +    }, | 
|  | 49 | +    actions: { | 
|  | 50 | +      type: "string[]", | 
|  | 51 | +      label: "Actions", | 
|  | 52 | +      description: "Actions for the notification, each item should be a JSON string. Example: { \"action\": \"https://example.com\", \"title\": \"Open Site\", \"icon\": \"https://example.com/icon.png\" }", | 
|  | 53 | +      optional: true, | 
|  | 54 | +    }, | 
|  | 55 | +  }, | 
|  | 56 | +  async run({ $ }) { | 
|  | 57 | +    const response = await this.alerty.makeRequest({ | 
|  | 58 | +      $, | 
|  | 59 | +      data: { | 
|  | 60 | +        message: this.message, | 
|  | 61 | +        title: this.title, | 
|  | 62 | +        image: this.image, | 
|  | 63 | +        icon: this.icon, | 
|  | 64 | +        device_id: parseObject(this.deviceId), | 
|  | 65 | +        urgency: this.urgency, | 
|  | 66 | +        actions: parseObject(this.actions), | 
|  | 67 | +      }, | 
|  | 68 | +    }); | 
|  | 69 | + | 
|  | 70 | +    $.export("$summary", `Notification sent with message: "${this.message}"`); | 
|  | 71 | +    return response; | 
|  | 72 | +  }, | 
|  | 73 | +}; | 
0 commit comments