@line/bot-sdk
Version:
Node.js SDK for LINE Messaging API
126 lines (114 loc) • 3.83 kB
text/typescript
/**
* LIFF server API
* LIFF Server API.
*
* The version of the OpenAPI document: 1.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
/* tslint:disable:no-unused-locals */
import { AddLiffAppRequest } from "../model/addLiffAppRequest";
import { AddLiffAppResponse } from "../model/addLiffAppResponse";
import { GetAllLiffAppsResponse } from "../model/getAllLiffAppsResponse";
import { UpdateLiffAppRequest } from "../model/updateLiffAppRequest";
import * as Types from "../../types";
import { ensureJSON } from "../../utils";
import { Readable } from "stream";
import HTTPClient from "../../http";
import { AxiosResponse } from "axios";
// ===============================================
// This file is autogenerated - Please do not edit
// ===============================================
interface httpClientConfig {
baseURL?: string;
channelAccessToken: string;
// TODO support defaultHeaders?
}
export class LiffClient {
private httpClient: HTTPClient;
constructor(config: httpClientConfig) {
if (!config.baseURL) {
config.baseURL = "https://api.line.me";
}
this.httpClient = new HTTPClient({
defaultHeaders: {
Authorization: "Bearer " + config.channelAccessToken,
},
responseParser: this.parseHTTPResponse.bind(this),
baseURL: config.baseURL,
});
}
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;
}
/**
* Adding the LIFF app to a channel
* @param addLiffAppRequest
*
* @see <a href="https://developers.line.biz/en/reference/liff-server/#add-liff-app"> Documentation</a>
*/
public async addLIFFApp(
addLiffAppRequest: AddLiffAppRequest,
): Promise<AddLiffAppResponse> {
const params = addLiffAppRequest;
const res = this.httpClient.post<AddLiffAppResponse>(
"/liff/v1/apps",
params,
);
return ensureJSON(res);
}
/**
* Deletes a LIFF app from a channel.
* @summary Delete LIFF app from a channel
* @param liffId ID of the LIFF app to be updated
*
* @see <a href="https://developers.line.biz/en/reference/liff-server/#delete-liff-app">Delete LIFF app from a channel Documentation</a>
*/
public async deleteLIFFApp(
liffId: string,
): Promise<Types.MessageAPIResponseBase> {
const res = this.httpClient.delete(
"/liff/v1/apps/{liffId}".replace("{liffId}", String(liffId)),
);
return ensureJSON(res);
}
/**
* Gets information on all the LIFF apps added to the channel.
* @summary Get all LIFF apps
*
* @see <a href="https://developers.line.biz/en/reference/liff-server/#get-all-liff-apps">Get all LIFF apps Documentation</a>
*/
public async getAllLIFFApps(): Promise<GetAllLiffAppsResponse> {
const res = this.httpClient.get<GetAllLiffAppsResponse>("/liff/v1/apps");
return ensureJSON(res);
}
/**
* Update LIFF app settings
* @param liffId ID of the LIFF app to be updated
* @param updateLiffAppRequest
*
* @see <a href="https://developers.line.biz/en/reference/liff-server/#update-liff-app"> Documentation</a>
*/
public async updateLIFFApp(
liffId: string,
updateLiffAppRequest: UpdateLiffAppRequest,
): Promise<Types.MessageAPIResponseBase> {
const params = updateLiffAppRequest;
const res = this.httpClient.put(
"/liff/v1/apps/{liffId}".replace("{liffId}", String(liffId)),
params,
);
return ensureJSON(res);
}
}