A demo bot for the AI Encode Hackathon, built for the Luffa messaging platform.
LuffaBot connects to the Luffa Bot API using a polling model — it sends a request to the API every second to check for new messages, then processes and responds to them.
┌────────────┐ POST /receive ┌──────────────────┐
│ │ ◄───────────────── │ │
│ Luffa API │ │ LuffaBot (Node) │
│ │ ──────────────────►│ │
└────────────┘ POST /send └──────────────────┘
POST /sendGroup ▲
│ every 1s
▼
Poll for messages
- Receive — Every 1 second, the bot polls
POST /robot/receivewith its secret key to fetch new messages from users and groups. - Parse & Deduplicate — Messages are parsed (handling double-JSON-encoding) and filtered by
msgIdto avoid processing duplicates. - Process — The bot checks if the message is a command or plain text:
- Commands (
/help,/ping,/quiz, etc.) get a specific response. - Plain text in private chat gets echoed back.
- New users receive a welcome message on first contact.
- New groups receive a welcome message with interactive buttons.
- Commands (
- Reply — Responses are sent via
POST /robot/send(private) orPOST /robot/sendGroup(group).
| Endpoint | Method | Description |
|---|---|---|
/robot/receive |
POST | Poll for new messages |
/robot/send |
POST | Send a private message |
/robot/sendGroup |
POST | Send a group message (supports buttons) |
All requests use Content-Type: application/json and require the bot secret key.
- Welcome message — Greets first-time users with a welcome message
- Commands:
/help— List available commands/ping— Health check (responds with "Pong!")/echo <text>— Echoes back your message/quiz— Fun quiz question ("Is London the capital of the United Kingdom?") with Yes/No buttons in group chats/answer yes|no— Answer the quiz in private chat/about— Bot info
- Echo mode — Non-command private messages are echoed back
- Group chat support — Commands work in group chats with interactive buttons
- Interactive buttons — Quiz and welcome messages use
confirm/buttonarrays in group chats (buttons are a group-only API feature) - Deduplication — Filters duplicate messages by
msgId
- Node.js (v16+)
- A Luffa bot secret key from robot.luffa.im
git clone <repo-url>
cd LuffaBot
npm installCreate a .env file in the project root:
BOT_SECRET=your_bot_secret_key_herenpm startYou should see:
LuffaBot started! Polling for messages...
LuffaBot/
├── index.js # Bot logic — polling, commands, message handling
├── .env # Bot secret key (not committed)
├── .gitignore # Ignores node_modules and .env
├── package.json # Project config and dependencies
└── README.md # This file
Full Luffa Bot API documentation is available at: https://robot.luffa.im/docManagement/operationGuide