- Published on
Filtering Messages by Channel
- Authors
- Name
- Tom Hacohen
- @TomHacohen
Channels are a way to filter which messages are sent to which endpoint. They are similar to event types in that way, though they are different in other ways.
Similarly to event types, you can set an endpoint to listen to multiple channels. These endpoints will then only receive messages sent to those specific channels. Where they differ is that event types, unlike channels, define the type of the message and imply a specific consistent schema; channels, however, filter based the expected recipient or group of recipients.
How to use it
You first need to enable support to it for each of your environments from the dashboard.
Once enabled, your customers will see a new Channels
section in the endpoint creation and edit screens in the Application Portal, or alternatively you can set it per endpoint in the API.
When sending messages, make sure to set corresponding channels in the channels
field, as seen in the following example:
await svix.message.create('app_id', {
eventType: 'user.signup',
channels: ['project_123', 'project_group_11'],
payload: {
username: 'test_user',
email: 'test@example.com',
},
})
What is this for?
Channels are useful for when you have a variety of sub-categories or recipients that expect the same types of messages but just need additional filtering.
For example, consider Github. You may want to define webhooks for the whole organization, but only send certain events to certain endpoints based on the repository. You could just create a Svix App per repository and then manually add the endpoints to each, but it makes for a much better experience to have the webhook handling defined in one place with the same endpoints listening to multiple projects.
So for example, you can have svix
, svix/svix-libs
and svix/svix-docs
as channels, and then have Github send messages for both svix
and for each repo whenever an event occurs on a specific repository. Github's customers can then create endpoints that listen to events either for the whole group, or for each repository in particular.
Finishing notes
Channels may not be useful for everyone, which is why they are off by default and need to be enabled explicitly from the dashboard. However they unlock a variety of new possibilities and a number of interesting use-cases.
You can read more about them in the channels section of the docs. Please don't hesitate to reach out if you have thoughts or feedback. Looking forward to hearing from you!
Coming next
We have a lot more in the works that we'll share in upcoming updates, stay tuned! If you have any thoughts or suggestions regarding what we should work on next, please join the Svix Slack and let us know!
This is it for this update, but make sure to follow us on Twitter, Github or RSS for the latest updates for the Svix webhook provider, or join the discussion on our community Slack.