ntfy Delphi 相关消息接口文档

news/2024/7/7 23:44:33

关联文档:

  1. ntfy 实现消息订阅和通知(无需注册、无需服务器,太好了)_海纳老吴的博客-CSDN博客
  2. 群晖 nas 自建 ntfy 通知服务(梦寐以求)_海纳老吴的博客-CSDN博客

目录

一、消息实体对象接口

1. 消息发布方消息接口

2. 消息订阅方接口


一、消息实体对象接口

1. 消息发布方消息接口

uses
  Notify.Notification.Contract;


//实际定义的接口
INotifyNotification = interface
    ['{BE2E83B7-C39E-4985-93F9-4468976B6AC5}']
    function Topic: String; overload;
    function Topic(const AValue: String): INotifyNotification; overload;
    function MessageContent: String; overload;
    function MessageContent(const AValue: String): INotifyNotification; overload;
    function Title: String; overload;
    function Title(const AValue: String): INotifyNotification; overload;
    function Tags: INotifyTags; overload;
    function Tags(const AValue: INotifyTags): INotifyNotification; overload;
    function Priority: TNotifyPriority; overload;
    function Priority(const AValue: TNotifyPriority): INotifyNotification; overload;
    function AttachURL(const AValue: String): INotifyNotification; overload;
    function FilePath: String; overload;
    function AttachFile(const AValue: String): INotifyNotification; overload;
    function FileName: String; overload;
    function Click: String overload;
    function Click(const AValue: String): INotifyNotification; overload;
    function Action: INotifyAction; overload;
    function Action(const AValue: INotifyAction): INotifyNotification; overload;
    function ClearActions: INotifyNotification; overload;
    function AsJSONString: String;
    function Email: String; overload;
    function Email(const AValue: String): INotifyNotification; overload;
    function Icon: String; overload;
    function Icon(const AValue: String): INotifyNotification; overload;
    function Delay: String; overload;
    function Delay(const AValue: String): INotifyNotification; overload;
  end;

接口说明:

序号参数(函数)说明
1Topicstring:字面意思是主题,实际就是消息发布方和订阅放约定的"暗号"。只有这个"暗号"对上了,订阅放才能收到发布方的消息。
2MessageContentstring:发布的消息内容字符串,最大长度4096字节
3Titlestring:标题,消息体的标题,一般设置为简短的URL
4TagsINotifyTags:

可以用表情符号和其他相关字符串标记信息:

表情符号: 如果标签与表情符号简码相匹配,就会被转换为表情符号并添加到标题或信息中。
其他标签: 如果标签不匹配,则会在通知下方列出。
此功能对于警告(⚠️、️🚨 或 🚩)等内容非常有用,但也可以简单地标记其他信息(如脚本名称、主机名等)。请使用表情符号简码列表了解哪些标记可以转换为表情符号。

参见:Sending messages - ntfy

5PriorityTNotifyPriority:所有信息都有一个优先级,它定义了手机通知你的紧急程度。总共分5级,默认是3,数值大表示优先级高。
6AttachURLINotifyNotification:

您可以使用外部 URL 来指定附件的托管位置,而不是向手机发送本地文件。这可以是 Dropbox 链接、社交媒体上的文件或任何其他公开可用的 URL。由于文件是外部托管的,因此上述的过期时间或大小限制在此不适用。

要附加外部文件,只需输入AValue参数即可,例如 https://example.com/flower.jpg 会生成文件名 flower.jpg)。要覆盖此文件名,可以发送 X-Filename 标头或查询参数(或其任何别名 Filename、File 或 f)。

7AttachFile

要将电脑中的文件作为附件发送,可以将其作为 PUT 请求主体发送。如果信息大于最大信息大小(4,096 字节)或包含非 UTF-8 字符,ntfy 服务器会自动检测 MIME 类型和大小,并将信息作为附件文件发送。要以附件形式发送较小的纯文本信息或文件,必须通过 X-Filename 标头或查询参数(或其别名 Filename、File 或 f)传递文件名。

默认情况下,按照 ntfy.sh 的配置方式,附件的最大大小为 15 MB(每个访问者的附件总大小为 100 MB)。附件会在 3 小时后过期,这通常会给用户足够的时间下载,或让安卓应用自动下载。还请查看以下其他限制。

8Clickstring:您可以定义点击通知时打开的 URL。如果您的通知与 Zabbix 警报或您希望提供深度链接的事务有关,这可能会很有用。点击通知将打开网页浏览器(或应用程序)并打开网站。

要定义通知的点击操作,请将 URL 作为 X-Click 标头(或其别名 Click)的值。如果传递的是网站 URL(http:// 或 https://),网络浏览器就会打开。如果传递的是可由其他应用程序处理的其他 URI,则负责的应用程序可能会打开。

例如

http:// 或 https:// 将打开浏览器(如果注册了 URL,则打开应用程序)
mailto:链接将打开您的邮件应用程序,如 mailto:phil@example.com
geo:链接将打开谷歌地图,例如 geo:0,0?q=1600+Amphitheatre+Parkway,+Mountain+View,+CA
ntfy:// 链接将打开 ntfy(参见 ntfy:// 链接),例如 ntfy://ntfy.sh/stats
twitter:// 链接将打开 Twitter,例如 twitter://user?screen_name=...
...
 
9Action

您可以为通知添加操作按钮,让自己直接对通知做出反应。这一点非常有用,而且应用广泛。

您可以控制家用电器(打开/关闭车库门、改变恒温器的温度......),对常见的监控警报做出反应(磁盘已满时清除日志......),还可以做很多其他事情。一切尽在掌握。

目前支持以下操作:

查看: 点击操作按钮后打开网站或应用程序
广播: 广播:点击操作按钮时发送安卓广播意图(仅支持安卓系统)
http:点击操作按钮时发送 HTTP POST/GET/PUT 请求

10Email可以通过邮件发布消息
11Icon您可以在通知文本旁边添加一个图标。只需通过 X-Icon 标头或查询参数(或其别名 Icon)来指定图标所在的 URL。客户端将自动下载该图标(除非该图标已缓存在本地,且使用时间不超过 24 小时),并将其显示在通知中。图标会缓存在客户端本地,直到通知被删除。目前只支持 JPEG 和 PNG 图像。
12Delay

您可以延迟发送信息,让 ntfy 在稍后日期发送。这可以用来给自己发送提醒信息,甚至在以后执行命令(如果订阅者对信息采取了行动)。

使用方法非常简单。您可以使用 X-Delay 标头(或其任何别名:Delay、X-At、At、X-In 或 In)设置发送时间,可以指定 Unix 时间戳(如 1639194738)、持续时间(如 30m、3h、2 天)或自然语言时间字符串(如上午 10 点、晚上 8:30、明天、下午 3 点、星期二、上午 7 点等)。

从今天起,您可以设置的最小延迟时间为 10 秒,最大延迟时间为 3 天。目前无法进行其他配置。

2. 消息订阅方接口

unit Notify.Event.Contract;

interface

uses
  System.SysUtils,
  Notify.Types,
  Notify.Action.Contract,
  Notify.Attachment.Contract,
  System.Generics.Collections;

type

  INotifyEventActions = TDictionary<String, INotifyAction>;

  INotifyEvent = interface
    ['{0342B585-BB88-4A63-9C41-8848B90B6042}']
    function Id: String; overload;
    function Id(const AValue: String): INotifyEvent; overload;
    function Time: Integer; overload;
    function Time(const AValue: Integer): INotifyEvent; overload;
    function Event: String; overload;
    function Event(const AValue: String): INotifyEvent; overload;
    function Topic: String; overload;
    function Topic(const AValue: String): INotifyEvent; overload;
    function Tags: TArray<String>; overload;
    function Tags(const AValue: TArray<String>): INotifyEvent; overload;
    function Click: String; overload;
    function Click(const AValue: String): INotifyEvent; overload;
    function Title: String; overload;
    function Title(const AValue: String): INotifyEvent; overload;
    function MessageContent: String; overload;
    function MessageContent(const AValue: String): INotifyEvent; overload;
    function Priority: TNotifyPriority; overload;
    function Priority(const AValue: TNotifyPriority): INotifyEvent; overload;
    function Action: INotifyAction; overload;
    function Action(const AValue: INotifyAction): INotifyEvent; overload;
    function Actions: INotifyEventActions;
    function Attachment: INotifyAttachment; overload;
    function Attachment(const AValue: INotifyAttachment): INotifyEvent; overload;
    function Icon: String; overload;
    function Icon(const AValue: String): INotifyEvent; overload;
  end;

  TNotifyEventProc = TProc<INotifyEvent>;

implementation

end.

接口说明:

订阅方的主体参数和发布方是一致的,但是订阅放方对了如下参数:

FieldRequiredTypeExampleDescription
id✔️stringhwQ2YpKdmgRandomly chosen message identifier
time✔️number1635528741Message date time, as Unix time stamp
expires(✔)️number1673542291Unix time stamp indicating when the message will be deleted, not set if Cache: no is sent
event✔️openkeepalivemessage, or poll_requestmessageMessage type, typically you'd be only interested in message
topic✔️stringtopic1,topic2Comma-separated list of topics the message is associated with; only one for all message events, but may be a list in open events
message-stringSome messageMessage body; always present in message events
title-stringSome titleMessage title; if not set defaults to ntfy.sh/<topic>
tags-string array["tag1","tag2"]List of tags that may or not map to emojis
priority-1, 2, 3, 4, or 54Message priority with 1=min, 3=default and 5=max
click-URLhttps://example.comWebsite opened when notification is clicked
actions-JSON arraysee actions buttonsAction buttons that can be displayed in the notification
attachment-JSON objectsee belowDetails about an attachment (name, URL, size, ...)

Attachment (part of the message, see attachments for details):

FieldRequiredTypeExampleDescription
name✔️stringattachment.jpgName of the attachment, can be overridden with X-Filename, see attachments
url✔️URLhttps://example.com/file.jpgURL of the attachment
type-️mime typeimage/jpegMime type of the attachment, only defined if attachment was uploaded to ntfy server
size-️number33848Size of the attachment in bytes, only defined if attachment was uploaded to ntfy server
expires-️number1635528741Attachment expiry date as Unix time stamp, only defined if attachment was uploaded to ntfy server


http://lihuaxi.xjx100.cn/news/1447960.html

相关文章

地毯(暴力+差分两种方法)

题目描述 在 nx n 的格子上有 m 个地毯。 给出这些地毯的信息&#xff0c;问每个点被多少个地毯覆盖。 输入格式 第一行&#xff0c;两个正整数 n,m。意义如题所述。 接下来 m 行&#xff0c;每行两个坐标 (x_1,y_1) 和 (x_2,y_2)&#xff0c;代表一块地毯&#xff0c;左上…

像素相关知识

物理像素 指的是物理设备上真实的小方块个数&#xff0c;就是拿放大镜看屏幕时看到的像素点&#xff0c; 每个物理像素具体的大小是不固定的&#xff0c;不同设备不相同&#xff0c;由厂家设置 逻辑像素 指的就是我们css用到的px这个单位的像素 像素比&#xff08;DPR&…

运营商三要素 API:构建安全高效的身份验证系统

当今数字化的世界中&#xff0c;身份验证是各行各业中至关重要的一环。为了保护用户的隐私和数据安全&#xff0c;企业需要寻求一种既安全可靠又高效便捷的身份验证方式。运营商三要素 API 应运而生&#xff0c;为构建安全高效的身份验证系统提供了有力的解决方案。 运营商三要…

【skynet】skynet 下载编译

写在前面 skynet 是相当有水准的一个系统框架&#xff0c;但是目前多数资料都是默认读者有一定的经验&#xff0c;对于从零开始的小伙伴来说比较心累。所以看能不能自己做一个从零开始的笔记&#xff0c;不是帮助别人&#xff0c;主要还是帮助自己。 文章目录 写在前面准备工作…

SQL注入是什么?如何防范?

什么是SQL注入&#xff1f; SQL注入&#xff08;SQLi&#xff09;是一种注入攻击&#xff0c;可以执行恶意SQL语句。它通过将任意SQL代码插入数据库查询&#xff0c;使攻击者能够完全控制Web应用程序后面的数据库服务器。攻击者可以使用SQL注入漏洞绕过应用程序安全措施&#…

第4章 微服务框架主体搭建

mini商城第4章 微服务框架主体搭建 一、课题 框架搭建 二、回顾 1、整体业务功能分析 2、根据业务需求设计表结构及字段 三、目标 1、版本控制器的搭建使用 2、能独立自主的搭建微服务框架 3、学会考虑一些公共的工具组件 4、网关模块的应用 四、内容 第1章 版本控…

一个小时入门 EJB

前置知识 在开始学习Java EE的Enterprise JavaBeans (EJB)之前&#xff0c;以下是一些你可能需要提前了解的技术和概念&#xff1a; Java基础&#xff1a;熟悉Java的基础知识&#xff0c;包括面向对象的概念&#xff08;例如类、接口、继承和多态等&#xff09;、基本的数据结…

Lua脚本对比redis事务区别是什么

redis官方对于lua脚本的解释&#xff1a;Redis使用同一个Lua解释器来执行所有命令&#xff0c;同时&#xff0c;Redis保证以一种原子性的方式来执行脚本&#xff1a;当lua脚本在执行的时候&#xff0c;不会有其他脚本和命令同时执行&#xff0c;这种语义类似于 MULTI/EXEC。从别…