This project is a third-party LINE Notify SDK.
LINE official didn't provide SDK of Notify function. It's not convenient for developers.
This package is TypeScript
compatible and contains TypeScript declarations.
Official LINE Notify API provides endpoints for Authentication
and Notification
, so does this project.
GET
https://notify-bot.line.me/oauth/authorize- notify.generateOauthURL(state)
POST
https://notify-bot.line.me/oauth/token- notify.getToken(client_code)
GET
https://notify-api.line.me/api/status- notify.getStatus(token)
POST
https://notify-api.line.me/api/notify- notify.notify(token, message, imageThumbnail, imageFullsize, stickerPackageId, stickerId, notificationDisabled)
POST
https://notify-api.line.me/api/revoke- notify.revoke(token)
npm install line-notify-sdk
Import module and initial sdk object. Constructor's arguments are optional if you have default variables in your environment.
const notifySDK = require('line-notify-sdk')
const notify = new notifySDK(clientID,clientSecret,redirectURI)
// These parameters are optional if you have
// default variables in your environment
Default environment variables
LINE_NOTIFY_CLIENT_ID=
LINE_NOTIFY_CLIENT_SECRET=
LINE_NOTIFY_REDIRECT_URI=
notify.generateOauthURL(state)
return
[string]
Example :
const url = notify.generateOauthURL('somerandomstate')
notify.getToken(clientCode)
return
[promise] resolves to [string]
Example:
const token = await notify.getToken(clientCode)
//token: ZnCpYyTJq7_this_is_user_token_alxj8nWpzBl1
Import module and initial sdk object. Does not require environment variables to send Notifications
const notifySDK = require('line-notify-sdk')
const notify = new notifySDK()
notify.getStatus(token)
return
[promise] resolves to [object]
Example:
try {
const info = await notify.getStatus(token)
// info : { status: 200, message: 'ok', targetType: 'USER', target: 'yiyu0x' }
} catch (error) {
// error : { status: 4xx, message: 'Invalid access token or other message from LINE'}
}
notify.notify(token, message, imageThumbnail, imageFullsize, stickerPackageId, stickerId, notificationDisabled)
return: [promise] resolves to [object]
Example:
// Send a message
notify.notify(token, 'hello').then((body) => {
console.log(body)
//{ status: 200, message: 'ok' }
}).catch((e)=>console.log(e))
// Send a sticker
notify.notify(token, 'Here is my sticker', '', '', 1, 1).then((body) => {
console.log(body)
}).catch((e)=>console.log(e))
notify.revoke(token)
return
[promise] resolves to [object]
Example:
// revoke token
notify.revoke(token).then((body) => {
console.log(body)//{ status: 200, message: 'ok' }
}).catch((e)=>console.log(e))
// your-project.ts
import { notifySDK } from "line-notify-sdk";
const notify = new notifySDK();
notify.generateOauthURL('somerandomstate');
notify.getToken('clientCodeFromCallback');
notify.getStatus('yourToken');
notify.notify('yourMessage');
notify.revoke('yourToken');
- Example Authentication using Express server at
example/server.js
- Example Notifications at
example/notify.js
Reference : LINE Docs
There is a limit to the number of times an API can be called on each service. The default number is set to 1000.
The limit is per access token.
The API Rate Limit status, can be checked on the response header of the API.
Header name | Description |
---|---|
X-RateLimit-Limit | The limit of API calls per hour |
X-RateLimit-Remaining | The number of possible remaining API calls |
X-RateLimit-ImageLimit | The limit of Uploading image per hour |
X-RateLimit-ImageRemaining | The number of possible remaining Uploading image |
X-RateLimit-Reset | The time when the limit is reset (UTC epoch seconds) |
Thanks to all the people who already contributed!