Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/setup packer #7

Merged
merged 7 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions Dockerfile
NichArchA82 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@ WORKDIR /app/command-handler
RUN npm ci
RUN npm link

# Install dependencies and link server globally
# Install dependencies for express server
WORKDIR /app/server
RUN npm ci
RUN npm link

# Go to bot directory, install dependencies, and link both command-handler and server
WORKDIR /app/bot
RUN npm ci
RUN npm link command-handler server
RUN npm link command-handler

# Expose port 5000
EXPOSE 5000
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ If you would like to change the source code, or compile the slack Bot yourself:
},
"settings": {
"event_subscriptions": {
"request_url": "<your server's url>",
"bot_events": [
"message.channels",
"message.groups",
Expand All @@ -74,10 +75,11 @@ If you would like to change the source code, or compile the slack Bot yourself:
]
},
"interactivity": {
"is_enabled": true
"is_enabled": true,
"request_url": "<your server's url>"
},
"org_deploy_enabled": false,
"socket_mode_enabled": true,
"socket_mode_enabled": false,
"token_rotation_enabled": false
}
}
Expand Down
100 changes: 56 additions & 44 deletions bot/package-lock.json

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

6 changes: 3 additions & 3 deletions bot/src/commands/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ export default {
})
},

run: ({ response, message }) => {
run: ({ response, event }) => {

response({
blocks: [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": `Hey there <@${message.user}>!`
"text": `Hey there <@${event.user}>!`
},
"accessory": {
"type": "button",
Expand All @@ -32,7 +32,7 @@ export default {
}
}
],
text: `Hey there <@${message.user}>!`
text: `Hey there <@${event.user}>!`
})
}
}
4 changes: 2 additions & 2 deletions bot/src/commands/hello.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ const delay = (ms) => {
export default {
description: 'Replies with Hello',

run: async ({ response, message }) => {
run: async ({ response, event }) => {
await delay(5000);

response({
text: `Hey there <@${message.user}>!`
text: `Hey there <@${event.user}>!`
})
}
}
16 changes: 9 additions & 7 deletions bot/src/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import pkg from '@slack/bolt'
const { App, LogLevel } = pkg;
const { App, ExpressReceiver, LogLevel } = pkg;
import CH from 'command-handler';
import path from 'path';
import 'dotenv/config';
import 'server';
import server from '../../server/server.js';
import logger from 'command-handler/src/util/logger.js';

const log = logger();
Expand All @@ -17,19 +17,21 @@ const customLogger = {
error: (message) => log.error(message),
};

//receiver to integrate express with bolt
const receiver = new ExpressReceiver({
signingSecret: process.env.SIGNING_SECRET,
});

const app = new App({
token: process.env.BOT_TOKEN,
signingSecret: process.env.SIGNING_SECRET,
socketMode: true,
receiver,
appToken: process.env.APP_TOKEN,
LogLevel: LogLevel.DEBUG,
logger: customLogger,
});

(async () => {
await app.start(process.env.BOLT_PORT || 3000);
log.info('Bot is ready');

server(receiver);
new CH({
app,
featuresDir: path.join(process.cwd(), 'src', 'features'),
Expand Down
4 changes: 4 additions & 0 deletions command-handler/src/cmd-handler/buttons.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ const registeredButtons = {
"^button_delete_": {
command: 'vm',
isRegex: true,
},
"^button_create_image_": {
command: 'vm',
isRegex: true,
}
};

Expand Down
4 changes: 2 additions & 2 deletions command-handler/src/cmd-handler/run-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export default async ({
commandName,
handler,
app,
message,
event,
args,
say
}) => {
Expand All @@ -21,5 +21,5 @@ export default async ({
say(obj)
};

command.run({ handler, app, message, response, text, args });
command.run({ handler, app, event, response, text, args });
};
14 changes: 9 additions & 5 deletions command-handler/src/commands/vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ export default {
//list hetzner servers
hetzner.listServers({ app, body })
} else if (actionId === 'button_create_vm') {
//create the hetzner server
hetzner.createServer({ app, body });
//select the hetzner server to create before calling the create server
hetzner.selectImage({ app, body });

} else if (actionId.startsWith('button_start')) {
const vmid = actionId.split('_')[2];
Expand All @@ -29,17 +29,21 @@ export default {
//delete the server
hetzner.deleteServer({app, body, serverName})

} else if (actionId.startsWith('button_create_image')) {
const imageName = actionId.split('_')[3];
const imageID = actionId.split('_')[4];
hetzner.createServer({ app, body, imageID, imageName });
} else {
response({
text: `This button is registered with the vm command, but does not have an action associated with it.`
})
}
},

run: async ({ message, app }) => {
run: async ({ event, app }) => {
app.client.chat.postEphemeral({
channel: `${message.channel}`,
user: `${message.user}`,
channel: `${event.channel}`,
user: `${event.user}`,
blocks: [
{
"type": "section",
Expand Down
Loading