@line/bot-sdk
Advanced tools
Comparing version 6.8.0 to 6.8.1
@@ -8,6 +8,7 @@ /// <reference types="node" /> | ||
constructor(config: Types.ClientConfig); | ||
pushMessage(to: string, messages: Types.Message | Types.Message[], notificationDisabled?: boolean): Promise<any>; | ||
replyMessage(replyToken: string, messages: Types.Message | Types.Message[], notificationDisabled?: boolean): Promise<any>; | ||
multicast(to: string[], messages: Types.Message | Types.Message[], notificationDisabled?: boolean): Promise<any>; | ||
broadcast(messages: Types.Message | Types.Message[], notificationDisabled?: boolean): Promise<any>; | ||
private parseHTTPResponse; | ||
pushMessage(to: string, messages: Types.Message | Types.Message[], notificationDisabled?: boolean): Promise<Types.MessageAPIResponseBase>; | ||
replyMessage(replyToken: string, messages: Types.Message | Types.Message[], notificationDisabled?: boolean): Promise<Types.MessageAPIResponseBase>; | ||
multicast(to: string[], messages: Types.Message | Types.Message[], notificationDisabled?: boolean): Promise<Types.MessageAPIResponseBase>; | ||
broadcast(messages: Types.Message | Types.Message[], notificationDisabled?: boolean): Promise<Types.MessageAPIResponseBase>; | ||
getProfile(userId: string): Promise<Types.Profile>; | ||
@@ -14,0 +15,0 @@ private getChatMemberProfile; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const http_1 = require("./http"); | ||
const Types = require("./types"); | ||
const exceptions_1 = require("./exceptions"); | ||
@@ -22,7 +23,20 @@ function toArray(maybeArr) { | ||
this.config = config; | ||
this.http = new http_1.default(process.env.API_BASE_URL || "https://api.line.me/v2/bot/", { | ||
Authorization: "Bearer " + this.config.channelAccessToken, | ||
this.http = new http_1.default({ | ||
baseURL: process.env.API_BASE_URL || "https://api.line.me/v2/bot/", | ||
defaultHeaders: { | ||
Authorization: "Bearer " + this.config.channelAccessToken, | ||
}, | ||
responseParser: this.parseHTTPResponse.bind(this), | ||
}); | ||
} | ||
async pushMessage(to, messages, notificationDisabled = false) { | ||
parseHTTPResponse(response) { | ||
const { LINE_REQUEST_ID_HTTP_HEADER_NAME } = Types; | ||
let resBody = Object.assign({}, response.data); | ||
if (response.headers[LINE_REQUEST_ID_HTTP_HEADER_NAME]) { | ||
resBody[LINE_REQUEST_ID_HTTP_HEADER_NAME] = | ||
response.headers[LINE_REQUEST_ID_HTTP_HEADER_NAME]; | ||
} | ||
return resBody; | ||
} | ||
pushMessage(to, messages, notificationDisabled = false) { | ||
return this.http.post("/message/push", { | ||
@@ -34,3 +48,3 @@ messages: toArray(messages), | ||
} | ||
async replyMessage(replyToken, messages, notificationDisabled = false) { | ||
replyMessage(replyToken, messages, notificationDisabled = false) { | ||
return this.http.post("/message/reply", { | ||
@@ -37,0 +51,0 @@ messages: toArray(messages), |
/// <reference types="node" /> | ||
import { AxiosResponse } from "axios"; | ||
import { Readable } from "stream"; | ||
declare type httpClientConfig = { | ||
baseURL?: string; | ||
defaultHeaders?: any; | ||
responseParser?: <T>(res: AxiosResponse) => T; | ||
}; | ||
export default class HTTPClient { | ||
private instance; | ||
constructor(baseURL?: string, defaultHeaders?: any); | ||
private config; | ||
constructor(config?: httpClientConfig); | ||
get<T>(url: string, params?: any): Promise<T>; | ||
@@ -13,1 +20,2 @@ getStream(url: string, params?: any): Promise<Readable>; | ||
} | ||
export {}; |
@@ -9,3 +9,5 @@ "use strict"; | ||
class HTTPClient { | ||
constructor(baseURL, defaultHeaders) { | ||
constructor(config = {}) { | ||
this.config = config; | ||
const { baseURL, defaultHeaders } = config; | ||
this.instance = axios_1.default.create({ | ||
@@ -34,3 +36,7 @@ baseURL, | ||
}); | ||
return res.data; | ||
const { responseParser } = this.config; | ||
if (responseParser) | ||
return responseParser(res); | ||
else | ||
return res.data; | ||
} | ||
@@ -37,0 +43,0 @@ async postBinary(url, data, contentType) { |
@@ -14,1 +14,2 @@ "use strict"; | ||
__export(require("./exceptions")); | ||
__export(require("./types")); |
@@ -1338,3 +1338,3 @@ export interface Config { | ||
*/ | ||
columns: TemplateImageColumn; | ||
columns: TemplateImageColumn[]; | ||
}; | ||
@@ -1648,1 +1648,5 @@ export declare type TemplateImageColumn = { | ||
}; | ||
export declare const LINE_REQUEST_ID_HTTP_HEADER_NAME = "x-line-request-id"; | ||
export declare type MessageAPIResponseBase = { | ||
[LINE_REQUEST_ID_HTTP_HEADER_NAME]?: string; | ||
}; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.LINE_REQUEST_ID_HTTP_HEADER_NAME = "x-line-request-id"; |
@@ -5,2 +5,3 @@ import { Readable } from "stream"; | ||
import { JSONParseError } from "./exceptions"; | ||
import { AxiosResponse } from "axios"; | ||
@@ -31,15 +32,28 @@ function toArray<T>(maybeArr: T | T[]): T[] { | ||
this.config = config; | ||
this.http = new HTTPClient( | ||
process.env.API_BASE_URL || "https://api.line.me/v2/bot/", | ||
{ | ||
this.http = new HTTPClient({ | ||
baseURL: process.env.API_BASE_URL || "https://api.line.me/v2/bot/", | ||
defaultHeaders: { | ||
Authorization: "Bearer " + this.config.channelAccessToken, | ||
}, | ||
); | ||
responseParser: this.parseHTTPResponse.bind(this), | ||
}); | ||
} | ||
public async pushMessage( | ||
private parseHTTPResponse(response: AxiosResponse) { | ||
const { LINE_REQUEST_ID_HTTP_HEADER_NAME } = Types; | ||
let resBody = { | ||
...response.data, | ||
}; | ||
if (response.headers[LINE_REQUEST_ID_HTTP_HEADER_NAME]) { | ||
resBody[LINE_REQUEST_ID_HTTP_HEADER_NAME] = | ||
response.headers[LINE_REQUEST_ID_HTTP_HEADER_NAME]; | ||
} | ||
return resBody; | ||
} | ||
public pushMessage( | ||
to: string, | ||
messages: Types.Message | Types.Message[], | ||
notificationDisabled: boolean = false, | ||
): Promise<any> { | ||
): Promise<Types.MessageAPIResponseBase> { | ||
return this.http.post("/message/push", { | ||
@@ -52,7 +66,7 @@ messages: toArray(messages), | ||
public async replyMessage( | ||
public replyMessage( | ||
replyToken: string, | ||
messages: Types.Message | Types.Message[], | ||
notificationDisabled: boolean = false, | ||
): Promise<any> { | ||
): Promise<Types.MessageAPIResponseBase> { | ||
return this.http.post("/message/reply", { | ||
@@ -69,3 +83,3 @@ messages: toArray(messages), | ||
notificationDisabled: boolean = false, | ||
): Promise<any> { | ||
): Promise<Types.MessageAPIResponseBase> { | ||
return this.http.post("/message/multicast", { | ||
@@ -81,3 +95,3 @@ messages: toArray(messages), | ||
notificationDisabled: boolean = false, | ||
): Promise<any> { | ||
): Promise<Types.MessageAPIResponseBase> { | ||
return this.http.post("/message/broadcast", { | ||
@@ -84,0 +98,0 @@ messages: toArray(messages), |
@@ -1,2 +0,2 @@ | ||
import axios, { AxiosInstance, AxiosError } from "axios"; | ||
import axios, { AxiosInstance, AxiosError, AxiosResponse } from "axios"; | ||
import { Readable } from "stream"; | ||
@@ -8,6 +8,15 @@ import { HTTPError, ReadError, RequestError } from "./exceptions"; | ||
type httpClientConfig = { | ||
baseURL?: string; | ||
defaultHeaders?: any; | ||
responseParser?: <T>(res: AxiosResponse) => T; | ||
}; | ||
export default class HTTPClient { | ||
private instance: AxiosInstance; | ||
private config: httpClientConfig; | ||
constructor(baseURL?: string, defaultHeaders?: any) { | ||
constructor(config: httpClientConfig = {}) { | ||
this.config = config; | ||
const { baseURL, defaultHeaders } = config; | ||
this.instance = axios.create({ | ||
@@ -43,3 +52,6 @@ baseURL, | ||
}); | ||
return res.data; | ||
const { responseParser } = this.config; | ||
if (responseParser) return responseParser<T>(res); | ||
else return res.data; | ||
} | ||
@@ -46,0 +58,0 @@ |
@@ -1482,3 +1482,3 @@ export interface Config { | ||
*/ | ||
columns: TemplateImageColumn; | ||
columns: TemplateImageColumn[]; | ||
}; | ||
@@ -1804,1 +1804,6 @@ | ||
}; | ||
export const LINE_REQUEST_ID_HTTP_HEADER_NAME = "x-line-request-id"; | ||
export type MessageAPIResponseBase = { | ||
[LINE_REQUEST_ID_HTTP_HEADER_NAME]?: string; | ||
}; |
{ | ||
"name": "@line/bot-sdk", | ||
"version": "6.8.0", | ||
"version": "6.8.1", | ||
"description": "Node.js SDK for LINE Messaging API", | ||
@@ -69,3 +69,3 @@ "engines": { | ||
"lcov", | ||
"text-summary" | ||
"text" | ||
], | ||
@@ -72,0 +72,0 @@ "sourceMap": true, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
168199
4378
0