bark

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2023 License: MIT Imports: 7 Imported by: 0

README

bark

go.dev reference

  • Just a simple SDK to send notification to Bark server with APIv2.

Reference

Prompt

Write a Go SDK with proper naming and schema for Bark API. Here's the brief documentation for the API.

POST 请求支持JSON,例如:

curl -X "POST" "https://api.day.app/your_key" \
     -H 'Content-Type: application/json; charset=utf-8' \
     -d $'{
  "body": "Test Bark Server",
  "title": "Test Title",
  "badge": 1,
  "category": "myNotificationCategory",
  "sound": "minuet.caf",
  "icon": "https://day.app/assets/images/avatar.jpg",
  "group": "test",
  "url": "https://mritd.com"
}'

JSON 请求 key 可以放进请求体中,URL 路径须为 /push,例如

curl -X "POST" "https://api.day.app/push" \
     -H 'Content-Type: application/json; charset=utf-8' \
     -d $'{
  "body": "Test Bark Server",
  "title": "Test Title",
  "device_key": "your_key"
}'

请求参数 支持的参数列表,具体效果可在APP内预览。

参数 说明
title 推送标题
body 推送内容
level 推送中断级别。active:默认值,系统会立即亮屏显示通知;timeSensitive:时效性通知,可在专注状态下显示通知。;passive:仅将通知添加到通知列表,不会亮屏提醒。
badge 推送角标,可以是任意数字
autoCopy iOS14.5以下自动复制推送内容,iOS14.5以上需手动长按推送或下拉推送
copy 复制推送时,指定复制的内容,不传此参数将复制整个推送内容。
sound 可以为推送设置不同的铃声
icon 为推送设置自定义图标,设置的图标将替换默认Bark图标。 图标会自动缓存在本机,相同的图标 URL 仅下载一次。
group 对消息进行分组,推送将按group分组显示在通知中心中。也可在历史消息列表中选择查看不同的群组。
isArchive 传 1 保存推送,传其他的不保存推送,不传按APP内设置来决定是否保存。
url 点击推送时,跳转的URL ,支持URL Scheme 和 Universal Link

Documentation

Overview

Package bark provides a simple SDK for Bark service.

Index

Constants

This section is empty.

Variables

AllSounds contains all available built-in ringtone sounds.

Functions

This section is empty.

Types

type ArchiveType

type ArchiveType uint8

ArchiveType indicates whether the notification should be archived, overriding the user's settings on the device.

const (
	// ArchiveNo indicates that the notification should not be archived.
	ArchiveNo ArchiveType = 0
	// ArchiveYes indicates that the notification should be archived.
	ArchiveYes ArchiveType = 1
)

type AutomaticallyCopyType

type AutomaticallyCopyType uint8

AutomaticallyCopyType indicates whether the notification should be automatically copied to the clipboard.

const (
	// AutomaticallyCopyNo indicates that the notification should not be automatically copied to the clipboard.
	AutomaticallyCopyNo AutomaticallyCopyType = 0
	// AutomaticallyCopyYes indicates that the notification should be automatically copied to the clipboard.
	AutomaticallyCopyYes AutomaticallyCopyType = 1
)

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client represents a Bark client.

func NewClient

func NewClient(baseURL string) *Client

NewClient returns a new Bark client. The baseURL should be the URL of your Bark service, e.g. https://api.day.app

func (*Client) Push

func (c *Client) Push(pushRequest *PushRequest) (*PushResponse, error)

Push sends a push request to the Bark service.

type InterruptionLevel

type InterruptionLevel string

InterruptionLevel indicates the importance and delivery timing of a notification.

const (
	// InterruptionLevelActive indicates that iOS presents the notification immediately, lights up the screen, and can play a sound.
	InterruptionLevelActive InterruptionLevel = "active"
	// InterruptionLevelTimeSensitive indicates that iOS presents the notification immediately, lights up the screen, can play a sound, and breaks through system notification controls.
	InterruptionLevelTimeSensitive InterruptionLevel = "timeSensitive"
	// InterruptionLevelPassive indicates that iOS adds the notification to the notification list without lighting up the screen or playing a sound.
	InterruptionLevelPassive InterruptionLevel = "passive"
)

type PushRequest

type PushRequest struct {
	Key               string                `json:"device_key"`
	Title             string                `json:"title"`
	Body              string                `json:"body"`
	Category          string                `json:"category,omitempty"`
	Interruption      InterruptionLevel     `json:"level,omitempty"`
	Sound             SoundName             `json:"sound,omitempty"`
	AutomaticallyCopy AutomaticallyCopyType `json:"autoCopy,omitempty"`
	CopyContent       string                `json:"copy,omitempty"`
	ShouldArchive     ArchiveType           `json:"isArchive,omitempty"`
	BadgeNumber       int                   `json:"badge,omitempty"`
	IconURL           string                `json:"icon,omitempty"`
	ClickURL          string                `json:"url,omitempty"`
	Group             string                `json:"group,omitempty"`
}

PushRequest represents a push request.

func NewPushRequest

func NewPushRequest(key, title, body string) *PushRequest

NewPushRequest returns a new PushRequest with the given key, title and body, and other fields are not set.

type PushResponse

type PushResponse struct {
	Code      int    `json:"code"`
	Timestamp int64  `json:"timestamp"`
	Message   string `json:"message,omitempty"`
}

PushResponse represents a push response.

type SoundName

type SoundName string

SoundName represents name of built-in ringtone sounds of Bark app.

const (
	SoundDefault            SoundName = ""
	SoundSilence            SoundName = "silence"
	SoundAlarm              SoundName = "alarm"
	SoundAnticipate         SoundName = "anticipate"
	SoundBell               SoundName = "bell"
	SoundBirdsong           SoundName = "birdsong"
	SoundBloom              SoundName = "bloom"
	SoundCalypso            SoundName = "calypso"
	SoundChime              SoundName = "chime"
	SoundChoo               SoundName = "choo"
	SoundDescent            SoundName = "descent"
	SoundElectronic         SoundName = "electronic"
	SoundFanfare            SoundName = "fanfare"
	SoundGlass              SoundName = "glass"
	SoundGoToSleep          SoundName = "gotosleep"
	SoundHealthNotification SoundName = "healthnotification"
	SoundHorn               SoundName = "horn"
	SoundLadder             SoundName = "ladder"
	SoundMailSent           SoundName = "mailsent"
	SoundMinuet             SoundName = "minuet"
	SoundMultiwayInvitation SoundName = "multiwayinvitation"
	SoundNewMail            SoundName = "newmail"
	SoundNewsFlash          SoundName = "newsflash"
	SoundNoir               SoundName = "noir"
	SoundPaymentSuccess     SoundName = "paymentsuccess"
	SoundShake              SoundName = "shake"
	SoundSherwoodForest     SoundName = "sherwoodforest"
	SoundSpell              SoundName = "spell"
	SoundSuspense           SoundName = "suspense"
	SoundTelegraph          SoundName = "telegraph"
	SoundTiptoes            SoundName = "tiptoes"
	SoundTypewriters        SoundName = "typewriters"
	SoundUpdate             SoundName = "update"
)

Name of available built-in ringtone sounds of Bark app

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL