(Web)Hooked on a feeling with Serverless.

Who am I?

Agenda

  1. Webhooks?
  2. Serverless??
  3. Examples
  4. Recap

Webhooks

“Webhooks are user-defined HTTP callbacks.”

timothyfitz.com/2009/02/09/what-webhooks-are-and-why-you-should-care/

Have been around for like 10 years now, but … who cares?!? 🤷‍♂️

I won't pay for a server regularly just to fiddle around with some webhooks now and then.

Serverless

Better known as cloud functions or FaaS.

… is actually a misnomer.

A word that suggests an idea that is known to be wrong.
Schematic graphic of a cloud function invocation. ( Source: Video content generated solution with AWS Lambda )

Advantages

  • High scalability out of the box
  • No DoS (but DoW …?!)
  • Better control over costs

Who offers FaaS?

  • AWS
  • Google Cloud Platform & Firebase
  • Azure
  • IBM
  • Apache OpenWhisk

<3

<service>.addEventListener(
  '<webhook>',
  <lambdaFn>
);
        

Benefits

  • Build & deploy a prototype relatively simple and fast
  • Test it with little (financial) effort
  • Ditch it or grow within the Cloud Platform Ecosystem

Examples

Static Twitter API

What bothered me …

Either use the official Twitter Widget and load a lot of crap.

Or maintain a service that proxies the Twitter API.

Serverless + IFTTT to the rescue!!1

Btw: since the THAT in IFTTT can be a webhook, literally everything on this planet can trigger your cloud function! 🌍

Mind blown!

So what do we need?

A twitter app to get access to the API …

Screenshot of the twitter app wizard.

A cloud function …

We'll use the serverless framework here …

Definition of a Lambda function in serverless.yml

A S3 bucket …

Definition of a Lambda function in serverless.yml

Allow the function to write a file into the bucket …

Definition of an IAM role in serverless.yml

Allow the world to read the tweets …

Definition of a bucket policy in serverless.yml

Set up the cloud function …

Definition of the basic Lambda code

Set up an applet on IFTTT …

Screenshot of IFTT

Eventually the tweets arrive …

Example JSON file containing tweets.

Which we can use for a static twitter widget …

NPM Telegram Bot

For this example I use ClaudiaJS, because it makes things easy.

Also it brings the BotBuilder, which makes things even easier!

So what do we need?

A new Telegram bot. So let's go to the Botfather …

Screenshot of Telegram chat with the Botfather

A cloud function …

Definition of a Lambda function for the Telegram bot

That's it! The ClaudiaJS-CLI takes care of the rest. 😲

… don't forget to pass it the bot's secret key though!!

Demo time!

Github Release Newsletter

Imagine sending a newsletter containing the changelog on every release.

The only thing you have to do …

Releasing!

Obviously semantic-release writes the changelog for you. 😏

So what do we need?

Screenshot of mobile Mailchimp website
  1. Create a list for the subscribers …
  2. Create a template for the newsletter.

Set up the cloud function

We'll use the serverless framework here again …

Definition of a Lambda function in serverless.yml

Gathering data from the request payload …

Definition of a Lambda function in serverless.yml

Fetching more data, setting up the newsletter & sending it into the world.

Definition of a Lambda function in serverless.yml

After deploying the function we can set up GitHub …

Screenshot of the webhook settings on Github

That's it. Demo time!

Recap

Webhooks are cool.

Cloud functions are also cool.

Combine both for a lot of profit & win.

Thanks! 😃