Skip to content

Ninjuy/line-bot-typescript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

line-bot-typescript

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


Features / ฟีเจอร์

  • 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

Commands / คำสั่งที่รองรับ

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 ตอบกลับอัตโนมัติ

Getting Started / เริ่มต้นใช้งาน

1. Create a LINE Bot / สร้าง LINE Bot

  1. ไปที่ LINE Developers Console
  2. สร้าง channel ใหม่แบบ Messaging API
  3. คัดลอก Channel Secret และ Channel Access Token

2. Clone & Install / โคลนและติดตั้ง

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 ของคุณใน .env

3. Run with local tunnel / รันพร้อม local tunnel

npm 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)


Project Structure / โครงสร้างโปรเจกต์

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

Extending / ต่อยอด

  • เพิ่ม 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

Requirements / ความต้องการของระบบ

  • Node.js 18+
  • LINE Developer account (ฟรี)
  • ngrok (สำหรับ local development) — npm install -g ngrok

License

MIT

About

LINE Bot starter with TypeScript — webhook handling, flex messages, quick replies, and signature verification using @line/bot-sdk

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors