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

Commit

Permalink
add emoji react
Browse files Browse the repository at this point in the history
  • Loading branch information
jamiebrown201 committed Apr 1, 2020
1 parent 5c2a07f commit 5a30d23
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
24 changes: 21 additions & 3 deletions post.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,17 +210,35 @@ function prepMessage(statuses) {
return message;
}

async function addReactions({ channel, post }) {}
async function addReactions({ channel, timestamp }) {
for (let i = 0; i < AWAY_TYPES.length; ++i) {
try {
const result = await web.reactions.add({
channel,
timestamp,
name: AWAY_TYPES[i].defaultEmoji
});

console.log(result);
} catch (error) {
if (error.code === ErrorCode.PlatformError) {
console.log(error.data);
} else {
console.log("Unexpected error in addReactions()");
}
}
}
}

exports.post = async function(event, context) {
try {
console.log("message", event.Records[0].Sns.Message);
const { channel, test } = JSON.parse(event.Records[0].Sns.Message);
const result = await getMembers({
const timestamp = await getMembers({
channel,
test
});
await addReactions({ channel, post: result });
await addReactions({ channel, timestamp });
return {
statusCode: 200,
body: "success"
Expand Down
6 changes: 5 additions & 1 deletion trigger.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ exports.trigger = async function(event, context) {
try {
const eventBody = JSON.parse(event.body).event;
console.log("eventBody", eventBody);
if (isReactionToOtherPost(eventBody)) {
if (isReactionToOtherPost(eventBody) || appEmojiReact(eventBody)) {
console.log("not valid emoji react");
return {
statusCode: 200,
Expand Down Expand Up @@ -99,3 +99,7 @@ function isReactionToOtherPost({ type, item_user }) {
item_user !== process.env.APP_ID
);
}

function appEmojiReact({ user, type }) {
return type === "reaction_added" && user === process.env.APP_ID;
}

0 comments on commit 5a30d23

Please sign in to comment.