Skip to content
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
23 changes: 23 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
SLACK_BOT_TOKEN=xoxb-replace-me
SLACK_SIGNING_SECRET=replace-me
REDIS_URL=redis://localhost:6379
BOT_NAME=bot
PORT=8080
TZ=Asia/Kolkata

# Human Slack user IDs allowed to use env/show storage/show users/die.
# Empty disables these commands. Comma-separated; configure outside chat.
BOT_ADMIN_IDS=
# Dedicated directory for approved environment files; empty disables env load.
HUBOT_ENV_BASE_PATH=
# In production containers, REDIS_URL must reference a reachable external Redis,
# not localhost. Keep the existing URL key prefix to preserve memory.

# Existing script configuration remains supported.
INFO_SPREADSHEET_URL=
HUBOT_YOUTUBE_API_KEY=
HUBOT_YOUTUBE_HEAR=true
HUBOT_GOOGLE_CSE_ID=
HUBOT_GOOGLE_CSE_KEY=
HUBOT_ENV_AUTH_TOKEN=
HUBOT_ENV_HIDDEN_WORDS=SECRET,PASSWORD,TOKEN,API_KEY
16 changes: 16 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 10

services:
redis:
image: redis:7-alpine
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 5s
--health-timeout 3s
--health-retries 10

steps:
- name: Check out repository
uses: actions/checkout@v4
Expand All @@ -28,6 +39,11 @@ jobs:
- name: Typecheck and test
run: npm run check

- name: Verify Redis inbox persistence and deduplication
run: npm run test:redis
env:
TEST_REDIS_URL: redis://127.0.0.1:6379

- name: Build production image
run: docker build --tag bot:test .

Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ data/
.DS_Store
# compiled TypeScript output (built via npm run build)
scripts/*.js
scripts/*.js.map
scripts/*.js.map
scripts/runtime/
20 changes: 8 additions & 12 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ FROM node:24.19.0-slim AS build

ENV NODE_ENV=development

WORKDIR /home/hubot
WORKDIR /home/bot

RUN chown node:node /home/hubot
RUN chown node:node /home/bot

COPY --chown=node:node package.json package-lock.json ./

Expand All @@ -21,26 +21,22 @@ RUN npm run build \
FROM node:24.19.0-slim AS runtime

ENV NODE_ENV=production \
HUBOT_NAME=bot \
HUBOT_OWNER="Mobile Development Group <mdg@iitr.ac.in>" \
HUBOT_SLACK_TEAM=mdgiitr \
HUBOT_DESCRIPTION="Slack bot for Mobile Development Group, IIT Roorkee" \
BOT_NAME=bot \
TZ=Asia/Kolkata \
FB_WAIT_MINUTES=1 \
IDLE_TIME_DURATION_HOURS=4 \
HUBOT_YOUTUBE_HEAR=true \
PORT=8080

WORKDIR /home/hubot
WORKDIR /home/bot

COPY --from=build --chown=node:node /home/hubot/package.json /home/hubot/package-lock.json ./
COPY --from=build --chown=node:node /home/hubot/node_modules ./node_modules
COPY --from=build --chown=node:node /home/hubot/scripts ./scripts
COPY --from=build --chown=node:node /home/bot/package.json /home/bot/package-lock.json ./
COPY --from=build --chown=node:node /home/bot/node_modules ./node_modules
COPY --from=build --chown=node:node /home/bot/scripts ./scripts
COPY --chown=node:node bin ./bin
COPY --chown=node:node hubot-scripts.json ./

USER node

EXPOSE 8080

CMD ["sh", "-c", "exec ./node_modules/.bin/hubot -n \"${HUBOT_NAME:-bot}\" -a slack"]
CMD ["node", "scripts/main.js"]
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
worker: bin/hubot -a slack -n bot
web: node scripts/main.js
232 changes: 94 additions & 138 deletions README.md

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions bin/bot
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/sh

set -e

if [ ! -f scripts/main.js ]; then
echo "Cannot launch bot: run npm ci --omit=optional --legacy-peer-deps and npm run build first." >&2
exit 1
fi

# Accept the two legacy launcher flags while deployments move to environment
# variables. Bolt itself is always the Slack adapter.
while [ "$#" -gt 0 ]; do
case "$1" in
-n|--name)
if [ "$#" -lt 2 ]; then
echo "Missing bot name after $1" >&2
exit 1
fi
BOT_NAME="$2"
export BOT_NAME
shift 2
;;
-a|--adapter)
if [ "$#" -lt 2 ] || [ "$2" != "slack" ]; then
echo "Bolt supports only the Slack adapter." >&2
exit 1
fi
shift 2
;;
*)
echo "Unknown launcher argument: $1" >&2
exit 1
;;
esac
done

exec node --env-file-if-exists=.env scripts/main.js
39 changes: 39 additions & 0 deletions bin/bot.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
@echo off
setlocal

if not exist scripts\main.js (
echo Cannot launch bot: run npm ci --omit=optional --legacy-peer-deps and npm run build first. 1>&2
exit /b 1
)

:parse_arguments
if "%~1"=="" goto launch
if /I "%~1"=="-n" goto bot_name
if /I "%~1"=="--name" goto bot_name
if /I "%~1"=="-a" goto adapter
if /I "%~1"=="--adapter" goto adapter
echo Unknown launcher argument: %~1 1>&2
exit /b 1

:bot_name
if "%~2"=="" (
echo Missing bot name after %~1 1>&2
exit /b 1
)
set "BOT_NAME=%~2"
shift
shift
goto parse_arguments

:adapter
if /I not "%~2"=="slack" (
echo Bolt supports only the Slack adapter. 1>&2
exit /b 1
)
shift
shift
goto parse_arguments

:launch
node --env-file-if-exists=.env scripts\main.js
exit /b %errorlevel%
20 changes: 3 additions & 17 deletions bin/hubot
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
#!/bin/sh

set -e

npm install --legacy-peer-deps
npm run build

compiled_script=""
if [ -d scripts ]; then
compiled_script="$(find scripts -maxdepth 1 -type f -name '*.js' -print -quit)"
fi
if [ -z "$compiled_script" ]; then
echo "Cannot launch Hubot: no compiled JavaScript files were found in scripts/." >&2
exit 1
fi

export PATH="node_modules/.bin:node_modules/hubot/node_modules/.bin:$PATH"

exec node_modules/.bin/hubot "$@"
# Backward-compatible path for existing deployments. This invokes the Bolt
# launcher and does not load the Hubot runtime.
exec "$(dirname "$0")/bot" "$@"
15 changes: 2 additions & 13 deletions bin/hubot.cmd
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
@echo off

call npm install --legacy-peer-deps
if errorlevel 1 exit /b 1

call npm run build
if errorlevel 1 exit /b 1

if not exist scripts\*.js (
echo Cannot launch Hubot: no compiled JavaScript files were found in scripts/. 1>&2
exit /b 1
)

call node_modules\.bin\hubot.cmd %*
rem Backward-compatible path; bot.cmd launches Bolt, not Hubot.
call "%~dp0bot.cmd" %*
exit /b %errorlevel%
4 changes: 4 additions & 0 deletions dev_docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ services:
- 127.0.0.1:9998:8080
env_file:
- .env
environment:
REDIS_URL: redis://redis:6379
depends_on:
- redis
1 change: 0 additions & 1 deletion external-scripts.json

This file was deleted.

1 change: 0 additions & 1 deletion hubot-scripts.json

This file was deleted.

Loading
Loading