UNPKG

@line/bot-sdk

Version:
139 lines (126 loc) 4.74 kB
/** * LINE Messaging API * This document describes LINE Messaging API. * * The version of the OpenAPI document: 0.0.1 * * * 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 { AcquireChatControlRequest } from "../model/acquireChatControlRequest"; import { DetachModuleRequest } from "../model/detachModuleRequest"; import { GetModulesResponse } from "../model/getModulesResponse"; 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 LineModuleClient { 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; } /** * If the Standby Channel wants to take the initiative (Chat Control), it calls the Acquire Control API. The channel that was previously an Active Channel will automatically switch to a Standby Channel. * @param chatId The `userId`, `roomId`, or `groupId` * @param acquireChatControlRequest * * @see <a href="https://developers.line.biz/en/reference/partner-docs/#acquire-control-api"> Documentation</a> */ public async acquireChatControl( chatId: string, acquireChatControlRequest?: AcquireChatControlRequest, ): Promise<Types.MessageAPIResponseBase> { const params = acquireChatControlRequest; const res = this.httpClient.post( "/v2/bot/chat/{chatId}/control/acquire".replace( "{chatId}", String(chatId), ), params, ); return ensureJSON(res); } /** * The module channel admin calls the Detach API to detach the module channel from a LINE Official Account. * @param detachModuleRequest * * @see <a href="https://developers.line.biz/en/reference/partner-docs/#unlink-detach-module-channel-by-operation-mc-admin"> Documentation</a> */ public async detachModule( detachModuleRequest?: DetachModuleRequest, ): Promise<Types.MessageAPIResponseBase> { const params = detachModuleRequest; const res = this.httpClient.post("/v2/bot/channel/detach", params); return ensureJSON(res); } /** * Gets a list of basic information about the bots of multiple LINE Official Accounts that have attached module channels. * @param start Value of the continuation token found in the next property of the JSON object returned in the response. If you can\'t get all basic information about the bots in one request, include this parameter to get the remaining array. * @param limit Specify the maximum number of bots that you get basic information from. The default value is 100. Max value: 100 * * @see <a href="https://developers.line.biz/en/reference/partner-docs/#get-multiple-bot-info-api"> Documentation</a> */ public async getModules( start?: string, limit?: number, ): Promise<GetModulesResponse> { const queryParams = { start: start, limit: limit, }; const res = this.httpClient.get<GetModulesResponse>( "/v2/bot/list", queryParams, ); return ensureJSON(res); } /** * To return the initiative (Chat Control) of Active Channel to Primary Channel, call the Release Control API. * @param chatId The `userId`, `roomId`, or `groupId` * * @see <a href="https://developers.line.biz/en/reference/partner-docs/#release-control-api"> Documentation</a> */ public async releaseChatControl( chatId: string, ): Promise<Types.MessageAPIResponseBase> { const res = this.httpClient.post( "/v2/bot/chat/{chatId}/control/release".replace( "{chatId}", String(chatId), ), ); return ensureJSON(res); } }