
Security News
Crates.io Implements Trusted Publishing Support
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
layer-webhooks
Advanced tools
Node.js library, which provides a wrapper for the Layer Webhooks API
A Node.js library, which provides a wrapper for the Layer Webhooks API.
The Layer Webhooks API is a REST API for creating, pausing and deleting Webhooks for notifying your servers of events within your Layer ecosystem.
This library supports requests from your servers only.
You can find full documentation on the Webhooks API at developer.layer.com/docs/webhooks.
npm install layer-webhooks
var LayerWebhooks = require('layer-webhooks');
// Initialize by providing your Layer credentials
var layer = new LayerWebhooks({
token: API_TOKEN,
appId: APP_ID
});
// Register a webhook
layer.webhooks.register({
events: ['message.sent'],
url: 'https://mydomain.com/mywebhooks/messages-sent',
secret: 'Frodo is a Dodo',
config: {
name: 'My sample webhook'
}
}, function(err, res) {
if (err) return console.error(err);
// Webhook registered
});
To use this library you need to create a new instance of the layer-webhooks
module by passing config
object to a constructor.
Layer API constructor is initialized with the following configuration values:
token
- Layer Platform API token which can be obtained from Developer DashboardappId
- Layer application IDOptional values:
version
- API version to use (default: 1.0
)timeout
- Request timeout in milliseconds (default: 10000
milliseconds)agent
- Instance of https.Agent to use HTTPS KeepAliveagentOptions
- Or use Agent options hash directlydebug
- Enable debugging (default: false
)Layer Webhooks API allows you to register webhooks and receive https requests whenever the specified events occur. Supported webhook events can be seen in Webhook Events.
Retrieve a webhook with the specified ID
webhookId
- A webhook ID: layer:///apps/082d4684-0992-11e5-a6c0-1697f925ec7b/webhooks/f5ef2b54-0991-11e5-a6c0-1697f925ec7b
callback(err, res)
- Callback function returns an error and response objectslayer.webhooks.get(webhookId, function(err, res) {
if (err) return console.error(err);
// A hook object
var webhook = res.body;
});
List all webhooks for your app.
layer.webhooks.list(function(err, res) {
if (err) return console.error(err);
var webhooks = res.body;
});
Registers a webhook with Layer's servers.
options.events
- An array of event types that your service needs.options.url
- The url to send webhook events to.options.secret
- An arbitrary string you provide; used to validate that webhook events come from layer's services rather than an unauthorized request on your endpoint.options.config
- A hash of values (no nested data; string values only) that will be provided with each webhook event sent to your server.callback(err, res)
- Optional Callback function returns an error and response objectslayer.webhooks.register({
events: ['message.sent'],
url: 'https://mydomain.com/mywebhooks/messages-sent',
secret: 'Frodo is a Dodo',
config: {
name: 'My sample webhook'
}
}, function(err, res) {
if (err) return console.error(err);
// Webhook registered
});
Enables a webhook that was previously disabled.
webhookId
- A webhook ID: layer:///apps/082d4684-0992-11e5-a6c0-1697f925ec7b/webhooks/f5ef2b54-0991-11e5-a6c0-1697f925ec7b
; this value is provided with each webhook event sent to your server.callback(err, res)
- Optional Callback function returns an error and response objectslayer.webhooks.enable(webhookId, function(err, res) {
if (err) return console.error(err);
// Webhook enabled
});
Disables a webhook that was previously disabled.
webhookId
- A webhook ID: layer:///apps/082d4684-0992-11e5-a6c0-1697f925ec7b/webhooks/f5ef2b54-0991-11e5-a6c0-1697f925ec7b
; this value is provided with each webhook event sent to your server.callback(err, res)
- Optional Callback function returns an error and response objectslayer.webhooks.disable(webhookId, function(err, res) {
if (err) return console.error(err);
// Webhook disabled
});
Deletes a webhook that was previously disabled.
webhookId
- A webhook ID: layer:///apps/082d4684-0992-11e5-a6c0-1697f925ec7b/webhooks/f5ef2b54-0991-11e5-a6c0-1697f925ec7b
; this value is provided with each webhook event sent to your server.callback(err, res)
- Optional Callback function returns an error and response objectslayer.webhooks.delete(webhookId, function(err, res) {
if (err) return console.error(err);
// Webhook deleted
});
All the above functions can be used to return a promise by appending the Async
suffix to the function name e.g.:
layer.getAsync({webhookId: myId}).then(function(res) {
// Webhook description
var hook = res.body;
}).catch(function(err) {
console.error(err);
});
The unit tests are based on the mocha module, which may be installed via npm. To run the tests make sure that the npm dependencies are installed by running npm install
from the project directory.
npm test
Layer API is an Open Source project maintained by Layer. Feedback and contributions are always welcome and the maintainers try to process patches as quickly as possible. Feel free to open up a Pull Request or Issue on Github.
For a list of version changes please refer to Github releases page.
FAQs
Node.js library, which provides a wrapper for the Layer Webhooks API
We found that layer-webhooks demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.
Research
/Security News
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.