Skip to content
This repository has been archived by the owner on Jun 9, 2022. It is now read-only.

Commit

Permalink
add trigger mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
jamiebrown201 committed Feb 19, 2020
1 parent 0f4daa1 commit 016515a
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 17 deletions.
47 changes: 47 additions & 0 deletions data/types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
module.exports = {
AWAY_TYPES: (() => {
return [
{
keywords: ["ill", "sick"],
emoji: [":ill:", ":face_with_head_bandage:"],
type: "ill"
},
{
keywords: ["ooo", "office", "out", "busy", "conference", "training"],
emoji: [":no_entry_sign:"],
type: "ooo"
},
{
keywords: ["home", "wfh", "working", "work"],
emoji: [":house:", ":house_with_garden:", ":computer:"],
type: "wfh"
},
{
keywords: ["birthday", "cake", ":cake:"],
emoji: [":birthday:", ":cake:", ":cupcake:"],
type: "cake"
},
{
keywords: ["mat", "maternity", "pat", "paternity", "parental"],
emoji: [":baby:", ":baby_bottle:", ":pregnant_woman:"],
type: "parent"
},
{
keywords: [
"holiday",
"vacation",
"vacationing",
"annual",
"leave",
"al",
"a/l",
"travelling",
"travel",
"traveling"
],
emoji: [":palm_tree:", ":airplane:", ":desert_island", ":sunny:"],
type: "holiday"
}
];
})()
};
20 changes: 15 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"license": "MIT",
"dependencies": {
"@slack/web-api": "^5.4.0",
"axios": "^0.19.2",
"dotenv": "^8.2.0"
},
"devDependencies": {
Expand Down
11 changes: 6 additions & 5 deletions handler.js → post.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
"use strict";

if (process.env.NODE_ENV !== "production") require("dotenv").config();
const { WebClient, ErrorCode } = require("@slack/web-api");

Expand Down Expand Up @@ -165,14 +163,17 @@ function prepMessage(statuses) {
return message;
}

exports.handler = async function(event, context) {
exports.post = async function(event, context) {
console.log("EVENT: \n" + JSON.stringify(event, null, 2));
console.log(
"JSON.parse(event.body).event.channel",
JSON.parse(event.body).event.channel
);
const result = await getMembers({
channel: JSON.parse(event.body).event.channel
});

return {
statusCode: 200,
body: JSON.stringify(result)
body: "success"
};
};
4 changes: 2 additions & 2 deletions serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ plugins:
- serverless-offline

functions:
handler:
handler: handler.handler
post:
handler: post.post
events:
- http:
path: handler
Expand Down
13 changes: 8 additions & 5 deletions trigger.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
exports.handler = async function(event, context) {
console.log("EVENT: \n" + JSON.stringify(event, null, 2));
const result = await getMembers({
channel: JSON.parse(event.body).event.channel
const axios = require("axios");

exports.trigger = async function(event, context) {
axios({
method: "post",
url: "http://localhost:3000/handler",
data: event.body
});

return {
statusCode: 200,
body: JSON.stringify(result)
body: "success"
};
};

0 comments on commit 016515a

Please sign in to comment.