Giter VIP home page Giter VIP logo

line-notify-sdk-nodejs's Introduction

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

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!

line-notify-sdk-nodejs's People

Contributors

dependabot[bot] avatar wolffparkinson avatar yiyu0x avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

wolffparkinson

line-notify-sdk-nodejs's Issues

Would you create camel case method names?

Most JavaSript naming conventions use camel case instead of snake case.

Would you please add camel case method names to this project?

Considering the backward compatibility, let both styles exist is a better way.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.