plex-webhooks
v0.1.6
Published
Server for receiving plex webhooks. Useful for automation or action related local scripting.
Downloads
7
Readme
plex-webhooks v.0.1
Introduction
The plex-webhooks library is used to build an Express 4 based server written in TypeScript for handling webhooks generated by Plex servers. For more information on these webhooks see: Plex Webhooks.
Philosophy
This package is intended to aid in setting up an express server to process Plex Webhooks. User implemented Plex webhook handlers can be registered with the server for dispatch on certain events. The library should provide for easy extension of an existing express server or easy setup of a new one.
Quick Start
- Install the plex-webhooks library into your package.
npm install --save plex-webhooks
- Setup a
config/
directory and config file(s). These are read by plex-webhooks using the config NPM package. For example, yourconfig/default.json
might look like:
{
"server": {
"name": "plex-monitor",
"version": "0.1.0",
"port": 3344
},
"plex": {
"logdir": "/tmp/plex",
"uploads": "/tmp/plex/uploads"
}
}
Note: the plex.logdir
path is where the webhook handler will log the incoming request JSON payloads. The plex.uploads
path is where the multer will deposit any uploaded files (like posters).
- Write your application. Here is a really basic example:
import { server, MulterFiles, PlexDispatcher } from 'plex-webhooks';
// note we are using "any" type for the "payload" but future versions will ideally provide interfaces
// for the various events that might be handled
async function handleMediaPlayEvent(payload: any, files: MulterFiles): Promise<void> {
console.log('Media play event occurred.');
}
PlexDispatcher.getInstance().register('media.play', handleMediaPlayEvent);
const app = server.app();
app.listen(server.port, () => console.log(server.msg.good));
Example config/default.json
{
"server": {
"name": "plex-monitor",
"version": "0.1.0",
"port": 3344
},
"plex": {
"logdir": "/tmp/plex",
"uploads": "/tmp/plex/uploads"
}
}
Important! This is ALPHA
This is currently alpha, just a serious start to get the ball rolling, things may change. Post feature requests and bugs to Issues.