EN: LINE Bot starter built with TypeScript and the official
@line/bot-sdk. Includes webhook handling, text messages, flex messages, quick replies, and signature verification.TH: LINE Bot starter สร้างด้วย TypeScript และ
@line/bot-sdkอย่างเป็นทางการ รองรับ webhook, ข้อความ text, flex message, quick reply และการตรวจสอบ signature
- Webhook handler — LINE signature verification / ตรวจสอบ signature อัตโนมัติ
- Text messages — plain text และ command router
- Flex messages — product card, confirmation dialog
- Quick replies — category picker
- Event handlers — message, follow, unfollow
- TypeScript — type safety เต็มรูปแบบกับ LINE SDK types
| Command | EN | TH |
|---|---|---|
/help |
Show available commands | แสดงคำสั่งทั้งหมด |
/flex |
Sample product card (Flex Message) | ตัวอย่าง product card |
/quick |
Category picker with Quick Reply | เลือกหมวดหมู่แบบ Quick Reply |
/confirm |
Confirmation dialog | กล่องยืนยัน |
/info |
Bot information | ข้อมูล Bot |
| anything else | Echo reply | ตอบกลับอัตโนมัติ |
- ไปที่ LINE Developers Console
- สร้าง channel ใหม่แบบ Messaging API
- คัดลอก Channel Secret และ Channel Access Token
git clone https://github.com/Ninjuy/line-bot-typescript.git
cd line-bot-typescript
npm install
cp .env.example .env
# EN: Add your LINE credentials to .env
# TH: เพิ่ม LINE credentials ของคุณใน .envnpm run dev # EN: Start bot on port 3000 / TH: เริ่ม bot บน port 3000
npm run tunnel # EN: Expose via ngrok / TH: เปิด public URL ด้วย ngrokคัดลอก ngrok HTTPS URL → วางใน LINE Developers Console เป็น Webhook URL
(เช่น https://xxxx.ngrok.io/webhook)
src/
├── handlers/
│ ├── eventHandler.ts # Routes LINE events to handlers
│ └── messageHandler.ts # Command router for text messages
├── messages/
│ ├── text.ts # Text message builders
│ ├── flex.ts # Flex message templates
│ └── quickReply.ts # Quick reply builders
├── middleware/
│ └── lineWebhook.ts # Signature verification
└── app.ts # Express setup + webhook endpoint
- เพิ่ม command — เพิ่ม case ใน
messageHandler.ts - Flex template ใหม่ — เพิ่มฟังก์ชันใน
messages/flex.ts - Push notification — ใช้
client.pushMessage(userId, messages) - Postback events — จัดการ
event.type === "postback"ในeventHandler.ts - Rich menu — ใช้
client.createRichMenu()API
- Node.js 18+
- LINE Developer account (ฟรี)
- ngrok (สำหรับ local development) —
npm install -g ngrok
MIT