1.0.2 • Published 6 years ago

push-integration v1.0.2

Weekly downloads
14
License
-
Repository
github
Last release
6 years ago

🔸Push Integration

Install

Using npm

$ npm install --save push-integration

Supports

Platform
Line
Messenger
Wechat

Example

With JavaScript

const bot = require("push-integration")

const lineClient = new bot.LineClient({
    id: "<Channel id>",
    secret: "<Channel secret>",
    token: "<Channel access token>"
}, "<Channel name>")
const clients = new bot.Client([lineClient])

With TypeScript

import * as bot from "push-integration"
const lineClient = new bot.LineClient({
    id: "<Channel id>",
    secret: "<Channel secret>",
    token: "<Channel access token>"
}, "<Channel name>")
const clients = new bot.Client([lineClient])

or

import { Client, LineClient, WechatClient } from "push-integration"
const lineClient = new Client({
    id: "<Channel id>",
    secret: "<Channel secret>",
    token: "<Channel access token>"
}, "<Channel name>")
const clients = new Client([lineClient])

Add new Channel

const wechatClient = new WechatClient(CONFIG, "<Channel name>")
clients.use(wechatClient)

Send Message

const message = {
    channel: "<Channel name>",
    receiver: "<User id>",
    message: {
        type: "<Message type>",
        ...<Message object>
    }
}

clients.send(message)
    .then(result => {
        console.log(JSON.stringify(result, null, 4))
        /*
        {
            status: "ok"
        }
        */
    })
    .catch(error => {
        console.log(JSON.stringify(error, null, 4))
        /*
        {
            status: "error",
            message: "<Error message>"
        }
        */
    })