npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

line-notify-sdk

v2.0.1

Published

🔩 A third party node.js line notify sdk.

Downloads

76

Readme

line-notify-sdk-nodejs

GitHub package.json version Typescript npm GitHub code size in bytes GitHub license

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.

Authentication API

  1. GET https://notify-bot.line.me/oauth/authorize
    • notify.generateOauthURL(state)
  2. POST https://notify-bot.line.me/oauth/token
    • notify.getToken(client_code)

Notification API

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

Installation

npm install line-notify-sdk

Usage

Authentication

1. Initialization

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=

2. Generate authentication link

notify.generateOauthURL(state)

return [string]

Example :

const url = notify.generateOauthURL('somerandomstate')

3. Get token from code

notify.getToken(clientCode)

return [promise] resolves to [string]

Example:

const token = await notify.getToken(clientCode)
//token: ZnCpYyTJq7_this_is_user_token_alxj8nWpzBl1

Notification

Initialization

Import module and initial sdk object. Does not require environment variables to send Notifications

const notifySDK = require('line-notify-sdk')
const notify = new notifySDK()

Get token status

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'}
}

Send notification

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

Revoke token

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

TypeScript

// 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');

Others

  • Example Authentication using Express server at example/server.js
  • Example Notifications at example/notify.js

API Rate Limits

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)

Contributing

Thanks to all the people who already contributed!