Skip to content

Commit 63c60f0

Browse files
committed
Initial working release 0.0.1
1 parent 462618c commit 63c60f0

12 files changed

+1965
-0
lines changed

.env.local.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
API_KEY="very-long-password"
2+
DETA_PROJECT_KEY="project_key_secure"

LICENSE

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
![PPHook](https://github.com/tomcollis/PPHook/blob/main/img/PPHook-Banner.png?raw=true)
2+
3+
# PPHook = **P**(ush)**P**(ull)(Web)**Hook**
4+
[![Buy me coffee](https://img.shields.io/badge/Buy%20me%20-coffee!-orange.svg?logo=buy-me-a-coffee&color=795548)](https://paypal.me/TomCollisUK/2)
5+
[![GitHub stars](https://img.shields.io/github/stars/tomcollis/PPHook)](https://github.com/tomcollis/PPHook/stargazers)
6+
[![GitHub issues](https://img.shields.io/github/issues/tomcollis/PPHook)](https://github.com/tomcollis/PPHook/issues)
7+
[![Github All Releases download count](https://img.shields.io/github/downloads/tomcollis/PPHook/total.svg?style=flat)](https://github.com/tomcollis/PPHook/releases/latest)
8+
[![GitHub latest release version](https://img.shields.io/github/v/release/tomcollis/PPHook.svg?style=flat)](https://github.com/tomcollis/PPHook/releases/latest)
9+
10+
[![Deploy](https://button.deta.dev/1/svg)](https://go.deta.dev/deploy)
11+
12+
This app/service was created because I wanted to use webhooks with self-hosted apps and did not want the requirements of installing agents, opening firewall ports or needing a static IP and having the system be available 24/7 to ensure no webhooks are missed. There are many services (free and chargeable) that provide a webhook relay service, but the ones I looked at just relayed the information to another webhook, which did not solve my problem.
13+
14+
This service allows webhooks to be **Pushed** (submitted) and saved, and then **Pulled** (retrieved) at any time in the future. The webhooks can be tagged with a source system identifier (source-id), and then downloaded by source system, this allows different processes or tools to download the webhooks from specific systems.
15+
16+
This service can also be used with some cloud hosted automation services that do not allow webhooks but do allow scheduled get requests (e.g., Microsoft Power Automate).
17+
18+
___
19+
## Environment Variables
20+
21+
To run this code, you will need to provide following environment variables, you will be prompted automatically when using Deploy to [Deta](https://www.deta.sh/).
22+
23+
`DETA_PROJECT_KEY` - automatically populate when deployed to [Deta Micro](https://www.deta.sh/) or [Deta Space](https://deta.space/)
24+
25+
`API_KEY` - can be generated at [keycdn Tools](https://tools.keycdn.com/sha256-online-generator)
26+
27+
___
28+
## Deploy to [Deta](https://www.deta.sh/)
29+
30+
To deploy this project on Deta, click the button below:
31+
32+
[![Deploy](https://button.deta.dev/1/svg)](https://go.deta.dev/deploy)
33+
34+
You will automatically be prompted to enter the required environment variables.
35+
All data will be private in your own account.
36+
37+
___
38+
## API Reference
39+
40+
#### Post Webhook
41+
42+
```http
43+
POST /p
44+
```
45+
46+
| Parameter | Type | Description |
47+
| :-------- | :------- | :------------------------- |
48+
| `source` | `string` | **Optional but Recommended**. Source System Key, can be anything you want or left blank .|
49+
50+
All data is stored in your [Deta](https://www.deta.sh/) account in a [Deta](https://www.deta.sh/) Base called 'PPHook'. This means your data is not available for me or anyone else to see, but do not forget it is only protected by your API key. Your API Key is not required to post data.
51+
52+
###### Example
53+
54+
```http
55+
POST /p?source=system-name
56+
BODY {
57+
"value1": "a-to-z",
58+
"value2": "1-to-9",
59+
"value3": "500"
60+
}
61+
```
62+
63+
The BODY data can be in any format, with as many or as few fields as you want. The service will reply in the following format.
64+
65+
```http
66+
RESPONSE 200
67+
BODY {
68+
"success": "data received",
69+
"key": 1628781752490,
70+
"body": {
71+
"value1": "a-to-z",
72+
"value2": "1-to-9",
73+
"value3": "500"
74+
},
75+
"source": "system-2"
76+
}
77+
```
78+
This response is what is stored in the [Deta](https://www.deta.sh/) Base:
79+
80+
| Parameter | Type | Description |
81+
| :-------- | :------- | :------------------------- |
82+
| `key` | `string` | This is automatically generated with a UNIX Timestamp. |
83+
| `body` | `JSON` | This is the body of your POST, no validation or modification is performed. |
84+
| `source` | `string` | This is the key used to collate the webhooks that are stored. If this field is left blank (not recommended) when posting, it will be modified to 'unknown'. |
85+
86+
___
87+
88+
#### Get items for source system by id
89+
90+
```http
91+
GET /webhooks/$source
92+
```
93+
This will return all webhooks from the system with a matching source key and delete all corresponding results from the [Deta](https://www.deta.sh/) Base by design to minimise the length of time your data is stored online.
94+
95+
| Parameter | Type | Description |
96+
| :-------- | :------- | :------------------------- |
97+
| `api-key` | `string` | **Required**. Your API key |
98+
99+
###### Example Response
100+
101+
```http
102+
GET /webhooks/system-2?api-key=verysecure
103+
BODY
104+
{
105+
"items": [
106+
{
107+
"body": {
108+
"value1": "a-to-z",
109+
"value2": "1-to-9",
110+
"value3": "500"
111+
},
112+
"key": "1628782459290",
113+
"source": "system2"
114+
},
115+
{
116+
"body": {
117+
"value1": "a-to-z",
118+
"value2": "1-to-9",
119+
"value3": "500"
120+
},
121+
"key": "1628782460100",
122+
"source": "system2"
123+
}
124+
]
125+
}
126+
```
127+
128+
The webhooks received are returned in an array called 'items', this means they can be processed through another application.
129+
130+
#### Get items for source system unknown
131+
132+
```http
133+
GET /webhooks
134+
```
135+
This will retrieve all webhooks posted without a source key, it will also delete all corresponding results from the database by design.
136+
137+
| Parameter | Type | Description |
138+
| :-------- | :------- | :------------------------- |
139+
| `api-key` | `string` | **Required**. Your API key |
140+
141+
The responses are the same as the above request with the included system-id.
142+
143+
___
144+
## Feedback
145+
146+
If you have any feedback, you can:
147+
148+
[![](https://img.shields.io/static/v1?label=Message%20on&message=Telegram&color=27A7E7&logo=telegram&style=for-the-badge)](https://t.me/tomcollis)
149+
150+
or
151+
152+
[![](https://img.shields.io/static/v1?label=Create%20New&message=Issue&color=4EC820&logo=github&style=for-the-badge)](https://github.com/tomcollis/PPHook/issues)
153+
154+
___
155+
## Acknowledgements
156+
- This was a sample app, used as my starting point. [ExpressJS Example - Simple Web API](https://github.com/expressjs/express/blob/28db2c2c5cf992c897d1fbbc6b119ee02fe32ab1/examples/web-service/index.js)

Spacefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Spacefile Docs: https://go.deta.dev/docs/spacefile/v0
2+
v: 0
3+
micros:
4+
- name: HookStack
5+
src: ./
6+
engine: nodejs16
7+
public_routes:
8+
- "/*"
9+
primary: true
10+
presets:
11+
env:
12+
- name: MY_DATA_KEY
13+
description: Integrate my new Space App with my new Collection. Yes!!
14+
default: "please input your data key"
15+
- name: API_KEY
16+
description: API Key for retrieving data
17+
default: "very-long-password"

img/PPHook-Banner.png

35.8 KB
Loading

img/PPHook-Logo_128px.png

3.62 KB
Loading

img/PPHook-Logo_512px.png

14.8 KB
Loading

img/PPHook-Logo_SVG.svg

Lines changed: 17 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)