LINE bot translation worker powered by OpenAI and Cloudflare Workers.
- Node.js
>=20.0.0 - pnpm
11.7.0via Corepack - Cloudflare account + Wrangler
- LINE Messaging API channel
- OpenAI API key
- Enable pnpm and install dependencies:
corepack enablecorepack prepare pnpm@11.7.0 --activatepnpm install
- Configure secrets:
pnpm exec wrangler secret put LINE_CHANNEL_SECRETpnpm exec wrangler secret put LINE_CHANNEL_ACCESS_TOKENpnpm exec wrangler secret put OPENAI_API_KEY
- Optional secret for precise mention matching:
pnpm exec wrangler secret put LINE_BOT_USER_ID
- Deploy once to create the required Durable Object binding for atomic idempotency and rate limiting:
pnpm deploy
OPENAI_MODEL(current default:gpt-4o-mini)OPENAI_FALLBACK_MODEL(current default:gpt-4.1-mini)TRANSLATION_MODE(auto | ja2zh | zh2ja)TRANSLATION_STYLE(business | casual | neutral | polite)TRIGGER_MODE(all | mention | direct)TRIGGER_MENTIONGROUP_TRANSLATION_ENABLED(true | false, defaultfalse)true: translate every text message in groups and rooms.false: groups and rooms translate only when the bot is explicitly tagged (@翻譯or a command tag).
DEBUG_LOG(true | false)MAX_INPUT_CHARSMAX_OUTPUT_TOKENSOPENAI_TIMEOUT_MSMAX_WEBHOOK_BODY_BYTES(default:65536)RATE_LIMIT_PER_MINIDEMPOTENCY_TTL_SECONDSERROR_REPLY_ENABLED
The Worker explicitly sends store: false to OpenAI. It does not persist message text; the Durable Object stores only short-lived event IDs and rate-limit counters.
pnpm dev
pnpm run typecheckpnpm test -- --run- CI runs both commands on pull requests and pushes to
main.
pnpm deploy- Continuous deployment is not configured yet. Add it separately after defining the Cloudflare environment and repository secrets.
- Set
DEBUG_LOGtotrue. - Deploy.
- Check logs with
pnpm exec wrangler tailor Cloudflare dashboard. - For bot profile debug:
GET /debug/bot-info?debug=1
- Set
DEBUG_LOGback tofalseafter troubleshooting.
Invalid signature: wrongLINE_CHANNEL_SECRET.- OpenAI
insufficient_quota: billing/quota issue. - No reply in group mention mode:
- Mention metadata may be absent for plain text tags.
- Use command tags (
@TWJP,@JPTW,@ENJP,@JPEN) or configureLINE_BOT_USER_ID.
@TWJP,@JPTW,@ENJP,@JPEN- Optional style suffix:
-N(neutral/plain),-P(polite),-B(business) - Examples:
@TWJP 明天麻煩你確認一下-> defaults to polite Japanese (です・ます)@TWJP-N 明天麻煩你確認一下@TWJP-B 請協助安排下週會議@JPTW-P お手数ですが、ご確認をお願いいたします