Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@line/bot-sdk

Package Overview
Dependencies
Maintainers
4
Versions
66
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@line/bot-sdk - npm Package Compare versions

Comparing version 2.0.0 to 3.0.0

package-lock.json

20

CHANGELOG.md

@@ -0,1 +1,21 @@

## 3.0.0 (8 Sep 2017)
#### Major
* Implement "Get group/room member profile" API (#15)
* Implement "Get group/room member IDs" API (#23)
* `getMessageContent` now returns `Promise<ReadableStream>` (#20)
#### Type
* Add "datetimepicker" support (#21)
* Fix typo in `TemplateURIAction` type (#21)
#### Misc
* Package updates and corresponding fixes
* Use npm 5 instead of Yarn in dev
* Fix `clean` script to work in Windows
* Use "axios" for internal HTTP client instead of "got" (#20)
## 2.0.0 (12 June 2017)

@@ -2,0 +22,0 @@

6

dist/client.d.ts

@@ -9,3 +9,7 @@ /// <reference types="node" />

getProfile(userId: string): Promise<Line.Profile>;
getMessageContent(messageId: string): NodeJS.ReadableStream;
getGroupMemberProfile(groupId: string, userId: string): Promise<Line.Profile>;
getRoomMemberProfile(roomId: string, userId: string): Promise<Line.Profile>;
getGroupMemberIds(groupId: string): Promise<string[]>;
getRoomMemberIds(roomId: string): Promise<string[]>;
getMessageContent(messageId: string): Promise<NodeJS.ReadableStream>;
leaveGroup(groupId: string): Promise<any>;

@@ -12,0 +16,0 @@ leaveRoom(roomId: string): Promise<any>;

@@ -15,4 +15,4 @@ "use strict";

return this.post(URL.push, {
messages: util_1.toArray(messages),
to,
messages: util_1.toArray(messages),
});

@@ -22,4 +22,4 @@ }

return this.post(URL.reply, {
messages: util_1.toArray(messages),
replyToken,
messages: util_1.toArray(messages),
});

@@ -29,4 +29,4 @@ }

return this.post(URL.multicast, {
messages: util_1.toArray(messages),
to,
messages: util_1.toArray(messages),
});

@@ -37,2 +37,28 @@ }

}
getGroupMemberProfile(groupId, userId) {
return this.get(URL.groupMemberProfile(groupId, userId));
}
getRoomMemberProfile(roomId, userId) {
return this.get(URL.roomMemberProfile(roomId, userId));
}
getGroupMemberIds(groupId) {
const load = (start) => this.get(URL.groupMemberIds(groupId, start))
.then((res) => {
if (!res.next) {
return res.memberIds;
}
return load(res.next).then((extraIds) => res.memberIds.concat(extraIds));
});
return load();
}
getRoomMemberIds(roomId) {
const load = (start) => this.get(URL.roomMemberIds(roomId, start))
.then((res) => {
if (!res.next) {
return res.memberIds;
}
return load(res.next).then((extraIds) => res.memberIds.concat(extraIds));
});
return load();
}
getMessageContent(messageId) {

@@ -39,0 +65,0 @@ return this.stream(URL.content(messageId));

18

dist/exceptions.d.ts
export declare class SignatureValidationFailed extends Error {
signature: string;
constructor(msg: string, signature: string);
constructor(message: string, signature: string);
}
export declare class JSONParseError extends Error {
raw: string;
constructor(msg: string, raw: string);
raw: any;
constructor(message: string, raw: any);
}
export declare class RequestError extends Error {
code: string;
private origin;
constructor(gotErr: RequestError);
private originalError;
constructor(message: string, code: string, originalError: Error);
}
export declare class ReadError extends Error {
private origin;
constructor(gotErr: ReadError);
private originalError;
constructor(originalError: Error);
}

@@ -21,4 +21,4 @@ export declare class HTTPError extends Error {

statusMessage: string;
private origin;
constructor(gotErr: HTTPError);
private originalError;
constructor(message: string, statusCode: number, statusMessage: string, originalError: Error);
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class SignatureValidationFailed extends Error {
constructor(msg, signature) {
super(msg);
constructor(message, signature) {
super(message);
this.signature = signature;

@@ -11,4 +11,4 @@ }

class JSONParseError extends Error {
constructor(msg, raw) {
super(msg);
constructor(message, raw) {
super(message);
this.raw = raw;

@@ -19,6 +19,6 @@ }

class RequestError extends Error {
constructor(gotErr) {
super(gotErr.message);
this.code = gotErr.code;
this.origin = gotErr;
constructor(message, code, originalError) {
super(message);
this.code = code;
this.originalError = originalError;
}

@@ -28,5 +28,5 @@ }

class ReadError extends Error {
constructor(gotErr) {
super(gotErr.message);
this.origin = gotErr;
constructor(originalError) {
super(originalError.message);
this.originalError = originalError;
}

@@ -36,9 +36,9 @@ }

class HTTPError extends Error {
constructor(gotErr) {
super(gotErr.message);
this.statusCode = gotErr.statusCode;
this.statusMessage = gotErr.statusMessage;
this.origin = gotErr;
constructor(message, statusCode, statusMessage, originalError) {
super(message);
this.statusCode = statusCode;
this.statusMessage = statusMessage;
this.originalError = originalError;
}
}
exports.HTTPError = HTTPError;
/// <reference types="node" />
export declare function stream(url: string, headers: any): NodeJS.ReadableStream;
export declare function stream(url: string, headers: any): Promise<NodeJS.ReadableStream>;
export declare function get(url: string, headers: any): Promise<any>;
export declare function post(url: string, headers: any, body?: any): Promise<any>;
export declare function post(url: string, headers: any, data?: any): Promise<any>;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const got = require("got");
const axios_1 = require("axios");
const exceptions_1 = require("./exceptions");
const pkg = require("../package.json"); // tslint:disable-line no-var-requires
function parseJSON(raw) {
try {
return JSON.parse(raw);
function checkJSON(raw) {
if (typeof raw === "object") {
return raw;
}
catch (err) {
throw new exceptions_1.JSONParseError(err.message, raw);
else {
throw new exceptions_1.JSONParseError("Failed to parse response body as JSON", raw);
}
}
function wrapError(err) {
if (err instanceof got.RequestError) {
throw new exceptions_1.RequestError(err);
if (err.response) {
throw new exceptions_1.HTTPError(err.message, err.response.status, err.response.statusText, err);
}
else if (err instanceof got.ReadError) {
else if (err.code) {
throw new exceptions_1.RequestError(err.message, err.code, err);
}
else if (err.config) {
// unknown, but from axios
throw new exceptions_1.ReadError(err);
}
else if (err instanceof got.HTTPError) {
throw new exceptions_1.HTTPError(err);
}
// otherwise, just rethrow

@@ -30,3 +31,5 @@ throw err;

headers["User-Agent"] = userAgent;
return got.stream(url, { headers });
return axios_1.default
.get(url, { headers, responseType: "stream" })
.then((res) => res.data);
}

@@ -36,19 +39,16 @@ exports.stream = stream;

headers["User-Agent"] = userAgent;
return got
return axios_1.default
.get(url, { headers })
.then((res) => parseJSON(res.body))
.then((res) => checkJSON(res.data))
.catch(wrapError);
}
exports.get = get;
function post(url, headers, body) {
function post(url, headers, data) {
headers["Content-Type"] = "application/json";
headers["User-Agent"] = userAgent;
return got
.post(url, {
body: JSON.stringify(body),
headers,
})
.then((res) => parseJSON(res.body))
return axios_1.default
.post(url, data, { headers })
.then((res) => checkJSON(res.data))
.catch(wrapError);
}
exports.post = post;

@@ -6,3 +6,7 @@ export declare const reply: string;

export declare const profile: (userId: string) => string;
export declare const groupMemberProfile: (groupId: string, userId: string) => string;
export declare const roomMemberProfile: (roomId: string, userId: string) => string;
export declare const groupMemberIds: (groupId: string, start?: string) => string;
export declare const roomMemberIds: (roomId: string, start?: string) => string;
export declare const leaveGroup: (groupId: string) => string;
export declare const leaveRoom: (roomId: string) => string;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const qs = require("querystring");
const baseURL = process.env.API_BASE_URL || "https://api.line.me/v2/bot/";
const apiURL = (path) => baseURL + path;
const apiURL = (path, query) => baseURL + path + (query ? `?${qs.stringify(query)}` : "");
exports.reply = apiURL("message/reply");

@@ -10,3 +11,7 @@ exports.push = apiURL("message/push");

exports.profile = (userId) => apiURL(`profile/${userId}`);
exports.groupMemberProfile = (groupId, userId) => apiURL(`group/${groupId}/member/${userId}`);
exports.roomMemberProfile = (roomId, userId) => apiURL(`room/${roomId}/member/${userId}`);
exports.groupMemberIds = (groupId, start) => apiURL(`group/${groupId}/members/ids`, start ? { start } : null);
exports.roomMemberIds = (roomId, start) => apiURL(`room/${roomId}/members/ids`, start ? { start } : null);
exports.leaveGroup = (groupId) => apiURL(`group/${groupId}/leave`);
exports.leaveRoom = (roomId) => apiURL(`room/${roomId}/leave`);

@@ -18,4 +18,4 @@ import { get, post, stream } from "./http";

return this.post(URL.push, {
messages: toArray(messages),
to,
messages: toArray(messages),
});

@@ -26,4 +26,4 @@ }

return this.post(URL.reply, {
messages: toArray(messages),
replyToken,
messages: toArray(messages),
});

@@ -34,4 +34,4 @@ }

return this.post(URL.multicast, {
messages: toArray(messages),
to,
messages: toArray(messages),
});

@@ -44,3 +44,37 @@ }

public getMessageContent(messageId: string): NodeJS.ReadableStream {
public getGroupMemberProfile(groupId: string, userId: string): Promise<Line.Profile> {
return this.get(URL.groupMemberProfile(groupId, userId));
}
public getRoomMemberProfile(roomId: string, userId: string): Promise<Line.Profile> {
return this.get(URL.roomMemberProfile(roomId, userId));
}
public getGroupMemberIds(groupId: string): Promise<string[]> {
const load = (start?: string): Promise<string[]> =>
this.get(URL.groupMemberIds(groupId, start))
.then((res: { memberIds: string[], next?: string }) => {
if (!res.next) {
return res.memberIds;
}
return load(res.next).then((extraIds) => res.memberIds.concat(extraIds));
});
return load();
}
public getRoomMemberIds(roomId: string): Promise<string[]> {
const load = (start?: string): Promise<string[]> =>
this.get(URL.roomMemberIds(roomId, start))
.then((res: { memberIds: string[], next?: string }) => {
if (!res.next) {
return res.memberIds;
}
return load(res.next).then((extraIds) => res.memberIds.concat(extraIds));
});
return load();
}
public getMessageContent(messageId: string): Promise<NodeJS.ReadableStream> {
return this.stream(URL.content(messageId));

@@ -69,5 +103,5 @@ }

private stream(url: string): NodeJS.ReadableStream {
private stream(url: string): Promise<NodeJS.ReadableStream> {
return stream(url, this.authHeader());
}
}

@@ -1,9 +0,7 @@

import * as got from "got";
export class SignatureValidationFailed extends Error {
public signature: string;
constructor(msg: string, signature: string) {
super(msg);
this.signature = signature;
constructor(
message: string,
public signature: string,
) {
super(message);
}

@@ -13,7 +11,7 @@ }

export class JSONParseError extends Error {
public raw: string;
constructor(msg: string, raw: string) {
super(msg);
this.raw = raw;
constructor(
message: string,
public raw: any,
) {
super(message);
}

@@ -23,9 +21,8 @@ }

export class RequestError extends Error {
public code: string;
private origin: Error;
constructor(gotErr: RequestError) {
super(gotErr.message);
this.code = gotErr.code;
this.origin = gotErr;
constructor(
message: string,
public code: string,
private originalError: Error,
) {
super(message);
}

@@ -35,7 +32,6 @@ }

export class ReadError extends Error {
private origin: Error;
constructor(gotErr: ReadError) {
super(gotErr.message);
this.origin = gotErr;
constructor(
private originalError: Error,
) {
super(originalError.message);
}

@@ -45,12 +41,10 @@ }

export class HTTPError extends Error {
public statusCode: number;
public statusMessage: string;
private origin: Error;
constructor(gotErr: HTTPError) {
super(gotErr.message);
this.statusCode = gotErr.statusCode;
this.statusMessage = gotErr.statusMessage;
this.origin = gotErr;
constructor(
message: string,
public statusCode: number,
public statusMessage: string,
private originalError: Error,
) {
super(message);
}
}

@@ -1,2 +0,2 @@

import * as got from "got";
import axios, { AxiosError } from "axios";
import {

@@ -11,17 +11,27 @@ HTTPError,

function parseJSON(raw: string): any {
try {
return JSON.parse(raw);
} catch (err) {
throw new JSONParseError(err.message, raw);
function checkJSON(raw: any): any {
if (typeof raw === "object") {
return raw;
} else {
throw new JSONParseError("Failed to parse response body as JSON", raw);
}
}
function wrapError(err: Error) {
if (err instanceof got.RequestError) {
throw new RequestError(err as any);
} else if (err instanceof got.ReadError) {
throw new ReadError(err as any);
} else if (err instanceof got.HTTPError) {
throw new HTTPError(err as any);
function wrapError(err: AxiosError) {
if (err.response) {
throw new HTTPError(
err.message,
err.response.status,
err.response.statusText,
err,
);
} else if (err.code) {
throw new RequestError(
err.message,
err.code,
err,
);
} else if (err.config) {
// unknown, but from axios
throw new ReadError(err);
}

@@ -35,5 +45,7 @@

export function stream(url: string, headers: any): NodeJS.ReadableStream {
export function stream(url: string, headers: any): Promise<NodeJS.ReadableStream> {
headers["User-Agent"] = userAgent;
return got.stream(url, { headers });
return axios
.get(url, { headers, responseType: "stream" })
.then((res) => res.data as NodeJS.ReadableStream);
}

@@ -43,18 +55,16 @@

headers["User-Agent"] = userAgent;
return got
return axios
.get(url, { headers })
.then((res: any) => parseJSON(res.body))
.then((res) => checkJSON(res.data))
.catch(wrapError);
}
export function post(url: string, headers: any, body?: any): Promise<any> {
export function post(url: string, headers: any, data?: any): Promise<any> {
headers["Content-Type"] = "application/json";
headers["User-Agent"] = userAgent;
return got
.post(url, {
body: JSON.stringify(body),
headers,
})
.then((res: any) => parseJSON(res.body))
return axios
.post(url, data, { headers })
.then((res) => checkJSON(res.data))
.catch(wrapError);
}

@@ -22,3 +22,3 @@ import { raw } from "body-parser";

// https://nodejs.org/api/http.html#http_message_headers
const signature = req.headers["x-line-signature"];
const signature = req.headers["x-line-signature"] as string;

@@ -25,0 +25,0 @@ if (!signature) {

@@ -0,11 +1,33 @@

import * as qs from "querystring";
const baseURL: string = process.env.API_BASE_URL || "https://api.line.me/v2/bot/";
const apiURL = (path: string) => baseURL + path;
const apiURL = (path: string, query?: object) =>
baseURL + path + (query ? `?${qs.stringify(query)}` : "");
export const reply: string = apiURL("message/reply");
export const push: string = apiURL("message/push");
export const multicast: string = apiURL("message/multicast");
export const content = (messageId: string) => apiURL(`message/${messageId}/content`);
export const content = (messageId: string) =>
apiURL(`message/${messageId}/content`);
export const profile = (userId: string) => apiURL(`profile/${userId}`);
export const groupMemberProfile = (groupId: string, userId: string) =>
apiURL(`group/${groupId}/member/${userId}`);
export const roomMemberProfile = (roomId: string, userId: string) =>
apiURL(`room/${roomId}/member/${userId}`);
export const groupMemberIds = (groupId: string, start?: string) =>
apiURL(`group/${groupId}/members/ids`, start ? { start } : null);
export const roomMemberIds = (roomId: string, start?: string) =>
apiURL(`room/${roomId}/members/ids`, start ? { start } : null);
export const leaveGroup = (groupId: string) => apiURL(`group/${groupId}/leave`);
export const leaveRoom = (roomId: string) => apiURL(`room/${roomId}/leave`);
{
"name": "@line/bot-sdk",
"version": "2.0.0",
"version": "3.0.0",
"description": "Node.js SDK for LINE Messaging API",

@@ -14,3 +14,3 @@ "engines": {

"lint": "tslint '{lib,test}/**/*.ts'",
"clean": "rm -rf dist",
"clean": "del-cli dist",
"prebuild": "npm run lint && npm run clean",

@@ -33,17 +33,18 @@ "build": "tsc",

"@types/body-parser": "^1.16.3",
"@types/node": "^7.0.4",
"body-parser": "^1.17.1",
"got": "^6.7.1"
"@types/node": "^7.0.31",
"axios": "^0.16.2",
"body-parser": "^1.17.2"
},
"devDependencies": {
"@types/express": "^4.0.35",
"@types/mocha": "^2.2.40",
"express": "^4.15.2",
"@types/mocha": "^2.2.41",
"del-cli": "^1.1.0",
"express": "^4.15.3",
"gitbook-cli": "^2.3.0",
"mocha": "^3.2.0",
"ts-node": "^3.0.2",
"tslint": "^5.1.0",
"typescript": "^2.1.5"
"mocha": "^3.4.2",
"ts-node": "^3.0.6",
"tslint": "^5.4.3",
"typescript": "^2.3.4"
},
"license": "Apache-2.0"
}

@@ -11,7 +11,6 @@ # line-bot-sdk-nodejs

Using [npm](https://www.npmjs.com/) or [Yarn](https://yarnpkg.com/):
Using [npm](https://www.npmjs.com/):
``` bash
$ npm install @line/bot-sdk
$ yarn add @line/bot-sdk
```

@@ -18,0 +17,0 @@

/* tslint:disable interface-over-type-literal no-namespace */
// Type definitions globally used in source code
// FIXME: got has no ts declarations for the time being
declare module "got";
declare namespace Line {

@@ -47,3 +44,9 @@ export type ClientConfig = {

export type LeaveEvent = { type: "leave" } & EventBase;
export type PostbackEvent = { type: "postback", postback: { data: string } } & ReplyableEvent;
export type PostbackEvent = {
type: "postback",
postback: {
data: string,
params?: string,
},
} & ReplyableEvent;
export type BeaconEvent = ReplyableEvent & {

@@ -136,3 +139,3 @@ type: "beacon",

export type TemplateContent = TemplateButtons | TemplateConfirm | TemplateCarousel;
export type TemplateContent = TemplateButtons | TemplateConfirm | TemplateCarousel | TemplateImageCarousel;
export type TemplateButtons = {

@@ -143,3 +146,3 @@ type: "buttons",

text: string,
actions: TemplateAction[],
actions: TemplateAction<{ label: string }>[],
};

@@ -149,3 +152,3 @@ export type TemplateConfirm = {

text: string,
actions: TemplateAction[],
actions: TemplateAction<{ label: string }>[],
};

@@ -158,7 +161,20 @@ export type TemplateCarousel = { type: "carousel", columns: TemplateColumn[] };

text: string,
actions: TemplateAction[],
actions: TemplateAction<{ label: string }>[],
};
export type TemplateAction = TemplatePostbackAction | TemplateMessageAction | TemplateURIAction;
export type TemplateActionBase = { label: string };
export type TemplateImageCarousel = {
type: "image_carousel",
columns: TemplateImageColumn,
};
export type TemplateImageColumn = {
imageUrl: string,
action: TemplateAction<{ label?: string }>,
};
export type TemplateAction<Label> =
| TemplatePostbackAction & Label
| TemplateMessageAction & Label
| TemplateURIAction & Label
| TemplateDatetimePickerAction & Label;
export type TemplatePostbackAction = {

@@ -168,11 +184,19 @@ type: "postback",

text?: string,
} & TemplateActionBase;
};
export type TemplateMessageAction = {
type: "message",
text: string,
} & TemplateActionBase;
};
export type TemplateURIAction = {
type: "template",
type: "uri",
uri: string,
} & TemplateActionBase;
};
export type TemplateDatetimePickerAction = {
type: "datetimepicker",
data: string,
mode: "date" | "time" | "datetime",
initial?: string,
max?: string,
min?: string,
};
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc