Receiving Catalog Changes on VTEX IO
Recipe
-
Clone the app https://github.com/vtex-apps/events-example
- This example app also exports some service routes, but we're not gonna use it. Feel free to remove it, or integrate just the events section into another app. Every IO app is able to handle events with a
node
service.
- This example app also exports some service routes, but we're not gonna use it. Feel free to remove it, or integrate just the events section into another app. Every IO app is able to handle events with a
-
On
node/service.json
, change the event handler name and thekeys
. You can ditch thesender
field as well. The finalevents
section should be like so:_10"events": {_10"skuChange": {_10"keys": ["broadcaster.notification"]_10}_10},- The name
skuChange
you're free to change as well. This will be used to create the code to handle that event later on.
- The name
-
After saving the
node/service.json
, let's edit thenode/index.ts
file, creating the handler function for our event. We are gonna use the keyskuChange
to that._27export default new Service<IOClients, State, ParamsContext>({_27clients: {_27options: {_27events: {_27exponentialTimeoutCoefficient: 2,_27exponentialBackoffCoefficient: 2,_27initialBackoffDelay: 50,_27retries: 1,_27timeout: TREE_SECONDS_MS,_27concurrency: CONCURRENCY,_27},_27},_27},_27events: {_27skuChange: (ctx: any) => {_27console.log('Received SKU changed event')_27console.log(ctx.body)_27},_27},_27routes: {_27hcheck: (ctx: any) => {_27setCacheContext(ctx)_27ctx.status = 200_27ctx.body = 'ok'_27},_27},_27}) -
Now, to test it on a workspace, follow the steps here