Skip to content

Commit

Permalink
fix an issue with private channels
Browse files Browse the repository at this point in the history
  • Loading branch information
femioladeji committed Mar 12, 2024
1 parent 0f2695b commit 8a454a0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 9 additions & 4 deletions game.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,15 @@ module.exports.start = async (event, _context, callback) => {
}));
}
const { Items: authItem } = await db.query(process.env.SLACK_AUTH_TABLE, gameItem.team_id);
console.log(JSON.stringify(authItem, null, 2));
const { access_token: accessToken } = authItem[0];
const text = `Game started, type as many English words in the thread within 60 seconds using \`${gameItem.letters}\``;
await axios.post(`https://slack.com/api/conversations.join?token=${accessToken}&channel=${gameItem.channel_id}`);
const channelJoinResponse = await axios.post(`https://slack.com/api/conversations.join?token=${accessToken}&channel=${gameItem.channel_id}`);
if (!channelJoinResponse.data.ok) {
return respond(callback, 200, JSON.stringify({
text: 'You can only play slackwords in a public channel. Please try playing it in a public channel',
response_type: 'ephemeral',
}));
}
const message = await axios.post(`https://slack.com/api/chat.postMessage?token=${accessToken}&channel=${gameItem.channel_id}&text=${text}`);
gameItem.thread = message.data.ts;
await db.insert(process.env.DYNAMO_TABLE_NAME, gameItem);
Expand Down Expand Up @@ -98,7 +103,7 @@ module.exports.end = async (eventMessage, context, callback) => {
const words = await app.retrieveMessages(`https://slack.com/api/conversations.replies?token=${accessToken}&channel=${channelId}&ts=${thread}`);
if (!words) {
return axios.post(responseUrl, JSON.stringify({
text: 'An error occurred, can you please uninstall and re-install the game',
text: 'An error occurred, can you please uninstall and re-install the game. If the error persists, please send a mail to [email protected]',
response_type: 'in_channel',
}));
}
Expand All @@ -121,7 +126,7 @@ module.exports.end = async (eventMessage, context, callback) => {
} catch (error) {
console.log(error);
await axios.post(responseUrl, JSON.stringify({
text: 'An error occurred while ending the game',
text: 'An error occurred while ending the game. Please send a mail to [email protected] if this error persists',
response_type: 'in_channel',
}));
callback(null, {
Expand Down
2 changes: 1 addition & 1 deletion serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ resources:

provider:
name: aws
runtime: nodejs16.x
runtime: nodejs18.x
region: us-west-2
versionFunctions: false
iamRoleStatements: # permissions for all of your functions can be set here
Expand Down

0 comments on commit 8a454a0

Please sign in to comment.