DEV Community

Alfredo Salzillo
Alfredo Salzillo

Posted on • Edited on

1

Meeting the Octocat

Once upon a time there was a Denosaur...

Welcome gentl-octocats, today I wanted to create a Github Action to use IFTTT Webhooks and i know that all i need will be a simple curl in any Linux container, but, I'm a developer, and i like to try new thinks. And at the moment of the writing what is the hottest news in the Javascript environment?

You guess right! Deno.

So let's start building a github action with a Deno runner.

The image of the Denosaur

First of all we need an image with Deno, and after a simple research i have found hayd/alpine-deno:1.1.0.

So let's start writing the Dockerfile

FROM hayd/alpine-deno:1.1.0

WORKDIR /app

# Prefer not to run as root.
USER deno

# These steps will be re-run upon each file change in your working directory:
ADD . .
# Compile the main app so that it doesn't need to be compiled each startup/entry.
RUN deno cache main.ts

CMD ["run", "--allow-net", "--allow-env", "/app/main.ts"]
Enter fullscreen mode Exit fullscreen mode

Using the Denosaur

The actions it's a simple ts file how will fetch a request to the webhook like this

const input = (key: string) => Deno.env.get(`INPUT_${key}`);

const eventName = input('EVENT');
const key = input('KEY');
const value1 = input('VALUE1');
const value2 = input('VALUE2');
const value3 = input('VALUE3');

console.log(`calling webhook for ${eventName} with`, value1, value2, value3);

await fetch(`https://maker.ifttt.com/trigger/${eventName}/with/key/${key}`, {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ value1, value2, value3 }),
});
Enter fullscreen mode Exit fullscreen mode

The Octocat Action

End last but not least the github action definition

# action.yml
name: 'IFTTT Webhook'
description: 'Call an IFTTT Webhook'
inputs:
  event:  # id of input
    description: 'IFTTT webhook event'
    required: true
  key:
     description: 'IFTTT webhook key'
     required: true
  value1:
     description: 'IFTTT webhook optional parameter'
     required: false
  value2:
     description: 'IFTTT webhook optional parameter'
     required: false
  value3:
     description: 'IFTTT webhook optional parameter'
     required: false
runs:
  using: 'docker'
  image: 'Dockerfile'
Enter fullscreen mode Exit fullscreen mode

End of the story

And at the end of the story, in only 5 minutes I have made ifttt-webhook-action using Deno.

ifttt-webhook-action

A GitHub action that triggers an IFTTT webhooks event. This is useful for example when you want to trigger a IFTTT webhook after your deployment succeeds.

Usage

See action.yml

steps:
  - uses: alfredosalzillo/ifttt-webhook-action@master
    with:
      event: your-webhook-event
      key: your-webhook-secret-key
      value1: optional-value
      value2: optional-value
      value3: optional-value
Enter fullscreen mode Exit fullscreen mode

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (1)

Collapse
 
craigmorten profile image
Craig Morten

Nice one!

(FYI I think you have the brackets the wrong way round for your links! 🙃)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more