Skip to content

(Under Construction) A simple notification system triggered by webhooks

Notifications You must be signed in to change notification settings

henricavalcante/hooksocket

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

HookSocket

HookSocket is a tiny lightweight service to emit websockets triggered by webhooks

Getting Started

Server-side

$ npm i hooksocket
const hooksocket = require('hooksocket');

hooksocket([{
  "route": {
    "method": "post",
    "path": "/path/to/notification"
  },
  "scope": "client",
  "msg": {
    "template": "You receive a new messsage from {sender}, {link} to view."
  }
}]);

Send a json data like this to the server

{
    "clientId": "b4e9bb81e9aa37ab2a3b979f7e6f4f87",
    "templateParameters": {
      "sender": "Ball Goats",
      "link": "http://www.com"
    }
}
$ curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X POST -d '{"clientId": "b4e9bb81e9aa37ab2a3b979f7e6f4f87","templateParameters": {"sender": "Ball Goats","link": "http://www.com"}}' http://localhost:3000/path/to/notification

Client-side

<script src="https://cdn.jsdelivr.net/socket.io-client/1.3.2/socket.io.min.js"></script>
<script>
  var socket = io('ws://localhost:3001/');
  socket.on('connect', function () {

    socket.emit('subscribeClient', {
      clientKey: "b4e9bb81e9aa37ab2a3b979f7e6f4f87",
    });

    socket.on('client_notification', function (payload) {
      console.log('Client Notification', payload);
    });

  });
</script>

About

(Under Construction) A simple notification system triggered by webhooks

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published