Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/digital-alchemy-ts/gotify

Rest API bindings for gotify
https://github.com/digital-alchemy-ts/gotify

automation digital-alchemy gotify home-automation nodejs notifications typescript

Last synced: about 2 months ago
JSON representation

Rest API bindings for gotify

Awesome Lists containing this project

README

        

# 📨 Welcome to the Gotify Adapter Library

- [Extended docs](https://docs.digital-alchemy.app)
- [Discord](https://discord.gg/JkZ35Gv97Y)

This library acts as a simple set of REST adapters for Gotify, primarily used for emitting messages from your application.

## ⚙️ Configuration

- **`BASE_URL`**: Target server for API.
- **`CHANNEL_MAPPING`**: Map tokens to friendly names to use within the application.

```ini
[gotify.CHANNEL_MAPPING]
app_name=token
another_app=token
app_the_third=token
```

- **`TOKEN`**: Application token.

## 🛠 Services

- **`application`**
- **`client`**
- **`message`**

## 🌐 Multi-channel Type-friendly Messages

> Create a wrapper to send messages from a particular application, using the correct credentials, and quick to type.

```typescript
enum MyGotifyApps {
testing = "testing",
reminders = "reminders",
}

export function MyGotifyServices({ gotify, config }: TServiceParams) {
return {
...(Object.fromEntries(
Object.values(MyGotifyApps).map(i => [
i,
async (message: Message) => {
await gotify.message.create({
...message,
appid: config.gotify.CHANNEL_MAPPING[i],
});
},
]),
) as Record<`${MyGotifyApps}`, (message: Message) => Promise>),
};
}
```

> Send messages:

```typescript
export function MyService({ app, lifecycle, internal }: TServiceParams) {
lifecycle.onReady(async() => {

await app.gotify.reminders({
message: `Failed to create countdown timer for ${internal.utils.relativeDate(target)}`,
});
})
}
```