Webhook example using AWS Lambda

Hey! Maybe you saw that we released more featured webhooks last week. This allows a more direct integration on the server-side and keeps your app posted about new accounts and transactions.
If you need some implementation tips, here is how we internally tested webhooks using AWS Lambda function through an API Gateway proxy:

const Zabo = require('zabo-sdk-js')

exports.handler = async (event, context, callback) => {
  console.log('Received event:', JSON.stringify(event, null, 2))

  let body = {}
  if (event.body && event.body !== '') {
    body = JSON.parse(event.body)
  }

  console.log('Parsed body:', JSON.stringify(body, null, 2))

  if (body.event === 'account.post') {
    const zabo = await Zabo.init({
      apiKey: process.env.ZABO_API_KEY,
      secretKey: process.env.ZABO_SECRET_KEY,
      env: process.env.ZABO_ENV
    })

    try {
      // We use a pre-created user to simplify the account linking
      const user = await zabo.users.getOne(process.env.USER_ID)
      await zabo.users.addAccount(user, body.account)
    } catch (error) {
      console.log(`Error adding account to user ${process.env.USER_ID}:`, error.message)
    }
  }

  return callback(null, {
    statusCode: 200,
    headers: { 'Content-Type': '*/*' },
    body: 'OK'
  })
}