openclaw/.claude/hooks/discord-task-start.sh
Shunsuke Hayashi 4d74fdf593 feat(aws): add ECS Fargate deployment for Clawdbot Discord bot
Add complete ECS Fargate infrastructure for Clawdbot Discord bot
deployment on AWS.

## Infrastructure (Terraform)
- **VPC**: 100.64.0.0/16 with DNS support
- **Public Subnets**: 2 subnets in different AZs
- **ECR Repository**: clawdbot/bot with lifecycle policy
- **IAM Roles**: Task Role (DynamoDB+S3) + Execution Role
- **ECS Resources**: Fargate (256 CPU, 2048 MB memory)
- **Security Group**: Outbound only
- **CloudWatch**: Log group with 7-day retention

## Security Improvements
- Discord Bot Token → AWS Secrets Manager
- IAM policy with least privilege principle
- No plaintext secrets in code

## Code Quality
- Fix all 22 lint errors
- Add *.d.ts to oxlint ignore patterns
- Fix Dockerfile .buildstamp for Linux compatibility

Closes #2049

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-26 13:38:43 +09:00

65 lines
1.8 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# Clawdbot Discord Task Start Notification Hook
# SessionStart: Declare task start
# clawdbot のパス
CLAWDBOT_DIR="${CLAWDBOT_DIR:-$HOME/dev/clawdbot}"
CLAWDBOT_CLI="$CLAWDBOT_DIR/dist/entry.js"
# CLIが存在するか確認
[ ! -f "$CLAWDBOT_CLI" ] && exit 0
# Discord 設定
DISCORD_CHANNEL_ID="${DISCORD_NOTIFY_CHANNEL:-1465087451113722019}" # #status
DISCORD_ACCOUNT_ID="${DISCORD_NOTIFY_ACCOUNT:-ppal}"
# セッションIDPPIDを使用してサブシェルでも一貫性を確保
SESSION_ID="${CLAUDE_SESSION_ID:-${PPID:-$$}}"
# タスク情報保存先
TASK_INFO_FILE="/tmp/clawdbot-task-info-${USER}-${SESSION_ID}.txt"
# クリーンアップ用trap
trap "rm -f $TASK_INFO_FILE" EXIT INT TERM
# タスク開始情報を保存
cat > "$TASK_INFO_FILE" << EOF
TASK_START_TIME=$(date '+%Y-%m-%d %H:%M:%S')
TASK_USER=${USER:-unknown}
TASK_HOST=$(hostname)
TASK_PWD=$PWD
TASK_SESSION_ID=${SESSION_ID}
EOF
# セッション開始メッセージ
START_MESSAGE="🚀 **Claude Code セッション開始**
📅 開始時刻: $(date '+%Y-%m-%d %H:%M:%S')
👤 ユーザー: ${USER:-unknown}
🖥️ ホスト: $(hostname -s 2>/dev/null || hostname | cut -d'.' -f1)
📁 ワークディレクトリ: $PWD
🆔 セッションID: ${SESSION_ID}
⏳ 作業開始..."
# Discord 送信
if [ -n "$DISCORD_WEBHOOK_URL" ]; then
(
curl -s -X POST "$DISCORD_WEBHOOK_URL" \
-H "Content-Type: application/json" \
-d "{\"content\": \"$START_MESSAGE\"}" \
>/dev/null 2>&1
) &
elif [ -n "$DISCORD_ACCOUNT_ID" ]; then
(
node "$CLAWDBOT_CLI" message send \
--channel discord \
--account "$DISCORD_ACCOUNT_ID" \
--target "$DISCORD_CHANNEL_ID" \
--message "$START_MESSAGE" \
>/dev/null 2>&1
) &
fi
exit 0