Skip to content

Instantly share code, notes, and snippets.

@maciejmatu
Created February 28, 2019 23:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maciejmatu/298050a2a3844c143e9073d7cb93b15d to your computer and use it in GitHub Desktop.
Save maciejmatu/298050a2a3844c143e9073d7cb93b15d to your computer and use it in GitHub Desktop.
Simple server-less slack webtask
const { WebClient } = require('@slack/client');
const fetch = require("node-fetch");
const API_URL = 'http://ron-swanson-quotes.herokuapp.com/v2/quotes';
const CHANNEL_ID = 'D6X9SM885';
module.exports = async (context, cb) => {
const [quote] = await fetch(API_URL).then(res => res.json());
const { chat } = new WebClient(context.secrets.SLACK_TOKEN);
const res = await chat.postMessage({
channel: CHANNEL_ID,
text: `Ron swanson quote for the day: \n*${quote}*`
});
return cb(null, { message: res.ts });
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment