{"id":19188214,"url":"https://github.com/mathdroid/node-line-messaging-api","last_synced_at":"2025-05-08T02:45:37.283Z","repository":{"id":46623371,"uuid":"71428134","full_name":"mathdroid/node-line-messaging-api","owner":"mathdroid","description":"Unofficial SDK for LINE Messaging API 🤖 💬","archived":false,"fork":false,"pushed_at":"2021-10-03T12:26:52.000Z","size":154,"stargazers_count":41,"open_issues_count":3,"forks_count":11,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-05-02T15:09:29.863Z","etag":null,"topics":["bot","bot-framework","event-listener","line","line-bot","nodejs","wip"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/node-line-messaging-api","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mathdroid.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-10-20T05:24:54.000Z","updated_at":"2025-03-26T11:05:57.000Z","dependencies_parsed_at":"2022-09-23T03:11:07.916Z","dependency_job_id":null,"html_url":"https://github.com/mathdroid/node-line-messaging-api","commit_stats":null,"previous_names":[],"tags_count":36,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathdroid%2Fnode-line-messaging-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathdroid%2Fnode-line-messaging-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathdroid%2Fnode-line-messaging-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mathdroid%2Fnode-line-messaging-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mathdroid","download_url":"https://codeload.github.com/mathdroid/node-line-messaging-api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252989811,"owners_count":21836665,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bot","bot-framework","event-listener","line","line-bot","nodejs","wip"],"created_at":"2024-11-09T11:24:03.053Z","updated_at":"2025-05-08T02:45:37.261Z","avatar_url":"https://github.com/mathdroid.png","language":"JavaScript","readme":"# node-line-messaging-api\n\n\u003e Unofficial SDK for Line's Messaging API\n\n```sh\nnpm install --save node-line-messaging-api\n```\n\n# Usage\n\nExample live bot ([`proofreader-dog`](https://github.com/mathdroid/proofreader-dog))\n\n```js\nconst LineBot = require('node-line-messaging-api')\nconst {secret, token} = require('../config')\nconst {lint} = require('./api')\n\nconst Messages = LineBot.Messages\nconst PORT = process.env.PORT || 5050\n\nconst dog = new LineBot({\n    secret,\n    token,\n    options: {\n        port: PORT,\n        tunnel: false,\n        verifySignature: true,\n        endpoint: '/'\n    }\n})\n\ndog.on('webhook', ({port, endpoint}) =\u003e {\n    console.log(`dog is online on http://localhost:${port}${endpoint}`)\n})\n\ndog.on('tunnel', ({url}) =\u003e {\n    console.log(`tunnel to local machine created at ${url}`)\n})\n\ndog.on('text', async event =\u003e {\n    try {\n        const {displayName} = await dog.getProfileFromEvent(event)\n        const {replyToken, message: {text}} = event\n        const {suggestions, typos} = await lint(text)\n        const replyText = `Woof! Hi ${displayName}!\\n\\nI've read your message:\\n\\n${text}`\n        const replyBalloon = new Messages().addText(replyText)\n        const reasons = suggestions.length \u0026\u0026 suggestions.map(({reason}) =\u003e reason).join('\\n\\n')\n        if (reasons) replyBalloon.addSticker({packageId: 1, stickerId: 15}).addText(`My dog-sense 🐕 has some suggestions:\\n\\n${reasons}`)\n        const words = typos.length \u0026\u0026 typos.map(({word, suggestions}) =\u003e `Error on word \"${word}\". Did you mean ${suggestions.join('/')}?`).join('\\n\\n')\n        if (words) replyBalloon.addSticker({packageId: 1, stickerId: 10}).addText(`🤔🔥 A bit of typographical errors:\\n\\n${words}`)\n        if (!reasons \u0026\u0026 !words) replyBalloon.addSticker({packageId: 1, stickerId: 14}).addText('Woof woof! I can\\'t find any errors! 🐶 Nice job!')\n        dog.replyMessage(replyToken, replyBalloon.commit())\n    } catch ({message}) {\n        console.log(message)\n    }\n})\n\n```\n\n## Events\n\nListen-able events:\n\n### `webhook`\n\nEmitted when webhook listener is created successfully. Emits `{port, endpoint}`.\n\n### `tunnel`\n\nEmitted when local tunnel is created successfully for development. Emits `{url}`.\n\n### `events`\nEmitted on all events, returns an array of `event`s.\n\n\n### `event`\nEmitted on all events, returns an array of `event`s.\n\n### `message`, `follow`, `unfollow`, `join`, `leave`, `postback`, `beacon`\n\nEmitted on parsing event types, returns that specific event.\n\n### `text`, `image`, `video`, `audio`, `location`, `sticker`, `non-text`, `message-with-content`\n\nEmitted on parsing message types (more specific), returns that specific event. Can be made more specific according to source type. For example, `Bot.on('image:user', fn)` will run `fn` only if it receives an `image` message type from `user` source type (won't work in `group`s/`room`s).\n\n\n## Webhook\n\nBy default, webhook will listen on port `5463`. You should change it if it interferes with something.\n\n## Messages\n\n`Messages` class is a helper in composing your messages.\n\n# API\n\n## LineBot\n\n\n- `LineBot`\n\n  - `new LineBot({secret, token, options})`\n\n  - `.on(event, function callback (eventContent) {})` // Standard event listener. Events are shown above.\n\n  - `.onText(regexp, function callback (event, match) {})` // Executes callback everytime a message.text matches regexp\n\n  - `.multicast(channels, messages)` =\u003e Promise\n\n  - `.replyMessage(replyToken, messages)` =\u003e Promise\n\n  - `.pushMessage(channel, messages)` =\u003e Promise\n\n  - `.getContent(messageId)` =\u003e Promise\n\n  - `.getProfile(userId)` =\u003e Promise\n\n  - `.getContentFromEvent(event)` =\u003e Promise\n\n  - `.getProfileFromEvent(event)` =\u003e Promise\n\n  - `.leaveChannel({groupId, roomId})` =\u003e Promise //pick one between groupId or roomId\n\n- `Messages`\n\n  - `new Messages()` // creates an empty array of messages. Maximum 5 messages following LINE's spec.\n\n  - `.addRaw(message)` // message Object following LINE's spec\n\n  - `.addText(message)` // message may be a string or an object with .text property. Chainable.\n\n  - `.addImage({originalUrl, previewUrl})` // `originalUrl` and `previewUrl` must be a HTTPS link to a JPG or PNG image. (size \u003c 1MB, width \u003c 1024px)\n\n  - `.addAudio({originalUrl, duration})` // `originalUrl` must be a HTTPS link to m4a audio. `duration` is in milliseconds.\n\n  - `.addVideo({originalUrl, previewUrl})` // same as `.addImage` but mp4 \u003c 10MB for the originalUrl.\n\n  - `.addLocation({title = 'My Location', address = 'Here\\'s the location.', latitude, longitude})` // lat and lon is of `number` type\n\n  - `.addSticker({packageId, stickerId})` // both params are of number type. see https://devdocs.line.me/files/sticker_list.pdf\n\n  - `.addButtons({thumbnailImageUrl, altText, title, text, actions})` // Buttons template message. `actions` is an array of [`action` objects](https://devdocs.line.me/en/#template-action). length of `actions` \u003c=4\n\n  - `.addConfirm({altText, text, actions})` // confirmation type. `actions` max length = 2\n\n  - `.addCarousel({altText, columns})` // where `columns` is an array of [`column` object](https://devdocs.line.me/en/#column-object). Column object is in the shape of `{thumbnailImageUrl, title, text, actions}`. `actions` is an array of [`action` objects](https://devdocs.line.me/en/#template-action).\n\n  - `.addVideo, etc` (WIP)\n\n  - `.commit()` // returns the payload (array of messages)\n\n# Installation\n\n```\nnpm install --save node-line-messaging-api\n```\n\nor\n\n```\nyarn add node-line-messaging-api\n```\n\n# Deployment\n\n1. Prepare your cloud host, note IP Address.\n\n2. Provide HTTPS support for the webhook endpoint.\n\n3. Register for an account in business.line.me, choose Messaging API and then dev-trial.\n\n4. Open developers.line.me for your account, note the `APP_SECRET`.\n\n5. Issue a `TOKEN` and note it.\n\n6. Go to server whitelist, add your IP Address.\n\n7. Create your bot, input your `APP_SECRET` and `TOKEN`.\n\n8. Deploy to your cloud host, and wait for events to come in!\n\n# Contributing\n\n**PRs welcome**. Open Issues first. ;)\n\n\n# License\n\nThe MIT License (MIT)\n\nCopyright \u0026copy; 2016 [Muhammad Mustadi](https://mustadi.xyz)\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmathdroid%2Fnode-line-messaging-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmathdroid%2Fnode-line-messaging-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmathdroid%2Fnode-line-messaging-api/lists"}