diff --git a/post.js b/post.js index ae1348b..ef7eadf 100644 --- a/post.js +++ b/post.js @@ -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" diff --git a/trigger.js b/trigger.js index 714511d..6848485 100644 --- a/trigger.js +++ b/trigger.js @@ -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, @@ -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; +}