Starter template for LINE Messager bot aiming for easy LINE bot creation
Click Here for template using @line-bot/sdk 7.0.0
- Commands handling for easy commands creation
- Dynamic webhook event handling
- Postback handling for easy postback event creation
- Almost all
message.type
examples are available - QuickDB examples (intended for local hosting, you probably need to change it if you want to host somewhere else)
-
getMessageContent(message.id)
example usage - Displaying Rich menu
- Bonus : Akinator
- Node.js 20 or higher
- Create account and official account here
- Clone this repo
- Install all the package
npm install
- make
.env
file and fill with your respective informationchannelAccessToken= # Bot access token channelSecret= # Bot channel secret baseurl= # Server callback url
- start the bot
node .
Ngrok URL can be directly registered as the webhook URL in LINE Developers console means you can host your bot on your system
you can make new command by creating .js
file on the commands/{category} folder like this
module.exports = {
command: 'text',
aliases: ['ping'],
category: "example",
description: 'Text message example',
handler: (client, blobClient, event) => {
client.replyMessage({
replyToken: event.replyToken,
messages: [
{
type: 'text',
text: 'This is text message example'
}
]
});
},
};
Alternatively you can use user snippets that come with this repo :
Snippets | Descriptions |
---|---|
command | Create new command handler |
replyMessage | create new replyMessage structure |
postback | Create new postback handler |
see example for other message.type
It's a very rough method of handling rich menu if not the worst :< Uncomment these lines of code below in index.js
to create a new rich menu everytime bot is running, there is not so many use cases i can think of when using rich menu. Maybe you can.
More about Rich menu can be found here : https://developers.line.biz/en/docs/messaging-api/using-rich-menus/
This is folder structure if you setup the bot correctly
/commands
/db
/example
/utility
/downloads
/events
/handlers
/loaders
/node_modules
/postbacks
/static
/audio
/image
/RichMenu_DesignTemplate
/imagemap
/video
.env
.gitignore
index.js
package-lock.json
package.json
richMenu.js
*Don't modify events and loaders folder unless you know what you're doing
See the official API documentation for more information
- English: https://developers.line.biz/en/docs/messaging-api/overview/
- Japanese: https://developers.line.biz/ja/docs/messaging-api/overview/
line-bot-sdk-nodejs documentation: https://line.github.io/line-bot-sdk-nodejs/#getting-started
Feel free to fork and make a pull request