UNPKG

@line/bot-sdk

Version:
259 lines (238 loc) 10.6 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 { GetMessageContentTranscodingResponse } from "../model/getMessageContentTranscodingResponse.js"; import * as Types from "../../types.js"; import { ensureJSON, buildPath } from "../../utils.js"; import { Readable } from "node:stream"; import HTTPFetchClient, { convertResponseToReadable, mergeHeaders, } from "../../http-fetch.js"; // =============================================== // This file is autogenerated - Please do not edit // =============================================== interface httpClientConfig { /** * Base URL for requests. * Defaults to 'https://api-data.line.me'. * You can override this for testing or to use a mock server. */ baseURL?: string; /** * Channel access token used for authorization. */ channelAccessToken: string; /** * Extra headers merged into every request. */ defaultHeaders?: Record<string, string>; } /** * @see {@link LineBotClient} for a unified interface that wraps this client. */ export class MessagingApiBlobClient { private httpClient: HTTPFetchClient; /** * Initializes a new `MessagingApiBlobClient`. * * @param config Configuration for this API client. * @param config.baseURL The base URL for requests. Defaults to `https://api-data.line.me`. * @param config.channelAccessToken The channel access token used for authorization. * @param config.defaultHeaders Extra headers merged into every request. * * @example * const client = new MessagingApiBlobClient({ * channelAccessToken: process.env.LINE_CHANNEL_ACCESS_TOKEN!, * }); */ constructor(config: httpClientConfig) { const baseURL = config.baseURL || "https://api-data.line.me"; const defaultHeaders = mergeHeaders(config.defaultHeaders, { Authorization: "Bearer " + config.channelAccessToken, }); this.httpClient = new HTTPFetchClient({ defaultHeaders: defaultHeaders, baseURL: baseURL, }); } /** * Download image, video, and audio data sent from users. * Calls `GET https://api-data.line.me/v2/bot/message/{messageId}/content`. * To inspect the HTTP status code or response headers, use {@link getMessageContentWithHttpInfo}. * @param messageId Message ID of video or audio * @returns A promise resolving to the response body. * @see <a href="https://developers.line.biz/en/reference/messaging-api/#get-content">LINE Developers documentation</a> */ public async getMessageContent(messageId: string): Promise<Readable> { return (await this.getMessageContentWithHttpInfo(messageId)).body; } /** * Download image, video, and audio data sent from users. * Calls `GET https://api-data.line.me/v2/bot/message/{messageId}/content`. * This method returns the response body together with the underlying `httpResponse`. * @param messageId Message ID of video or audio * @returns A promise resolving to the response body together with the underlying `httpResponse`. * @see <a href="https://developers.line.biz/en/reference/messaging-api/#get-content">LINE Developers documentation</a> */ public async getMessageContentWithHttpInfo( messageId: string, ): Promise<Types.ApiResponseType<Readable>> { const requestPath = buildPath("/v2/bot/message/{messageId}/content", { messageId: messageId, }); const response = await this.httpClient.get(requestPath); return { httpResponse: response, body: convertResponseToReadable(response), }; } /** * Get a preview image of the image or video * Calls `GET https://api-data.line.me/v2/bot/message/{messageId}/content/preview`. * To inspect the HTTP status code or response headers, use {@link getMessageContentPreviewWithHttpInfo}. * @param messageId Message ID of image or video * @returns A promise resolving to the response body. * @see <a href="https://developers.line.biz/en/reference/messaging-api/#get-image-or-video-preview">LINE Developers documentation</a> */ public async getMessageContentPreview(messageId: string): Promise<Readable> { return (await this.getMessageContentPreviewWithHttpInfo(messageId)).body; } /** * Get a preview image of the image or video * Calls `GET https://api-data.line.me/v2/bot/message/{messageId}/content/preview`. * This method returns the response body together with the underlying `httpResponse`. * @param messageId Message ID of image or video * @returns A promise resolving to the response body together with the underlying `httpResponse`. * @see <a href="https://developers.line.biz/en/reference/messaging-api/#get-image-or-video-preview">LINE Developers documentation</a> */ public async getMessageContentPreviewWithHttpInfo( messageId: string, ): Promise<Types.ApiResponseType<Readable>> { const requestPath = buildPath( "/v2/bot/message/{messageId}/content/preview", { messageId: messageId, }, ); const response = await this.httpClient.get(requestPath); return { httpResponse: response, body: convertResponseToReadable(response), }; } /** * Verify the preparation status of a video or audio for getting * Calls `GET https://api-data.line.me/v2/bot/message/{messageId}/content/transcoding`. * To inspect the HTTP status code or response headers, use {@link getMessageContentTranscodingByMessageIdWithHttpInfo}. * @param messageId Message ID of video or audio * @returns A promise resolving to the response body. * @see <a href="https://developers.line.biz/en/reference/messaging-api/#verify-video-or-audio-preparation-status">LINE Developers documentation</a> */ public async getMessageContentTranscodingByMessageId( messageId: string, ): Promise<GetMessageContentTranscodingResponse> { return ( await this.getMessageContentTranscodingByMessageIdWithHttpInfo(messageId) ).body; } /** * Verify the preparation status of a video or audio for getting * Calls `GET https://api-data.line.me/v2/bot/message/{messageId}/content/transcoding`. * This method returns the response body together with the underlying `httpResponse`. * @param messageId Message ID of video or audio * @returns A promise resolving to the response body together with the underlying `httpResponse`. * @see <a href="https://developers.line.biz/en/reference/messaging-api/#verify-video-or-audio-preparation-status">LINE Developers documentation</a> */ public async getMessageContentTranscodingByMessageIdWithHttpInfo( messageId: string, ): Promise<Types.ApiResponseType<GetMessageContentTranscodingResponse>> { const requestPath = buildPath( "/v2/bot/message/{messageId}/content/transcoding", { messageId: messageId, }, ); const res = await this.httpClient.get(requestPath); const text = await res.text(); const parsedBody = text ? JSON.parse(text) : null; return { httpResponse: res, body: parsedBody }; } /** * Download rich menu image. * Calls `GET https://api-data.line.me/v2/bot/richmenu/{richMenuId}/content`. * To inspect the HTTP status code or response headers, use {@link getRichMenuImageWithHttpInfo}. * @param richMenuId ID of the rich menu with the image to be downloaded * @returns A promise resolving to the response body. * @see <a href="https://developers.line.biz/en/reference/messaging-api/#download-rich-menu-image">LINE Developers documentation</a> */ public async getRichMenuImage(richMenuId: string): Promise<Readable> { return (await this.getRichMenuImageWithHttpInfo(richMenuId)).body; } /** * Download rich menu image. * Calls `GET https://api-data.line.me/v2/bot/richmenu/{richMenuId}/content`. * This method returns the response body together with the underlying `httpResponse`. * @param richMenuId ID of the rich menu with the image to be downloaded * @returns A promise resolving to the response body together with the underlying `httpResponse`. * @see <a href="https://developers.line.biz/en/reference/messaging-api/#download-rich-menu-image">LINE Developers documentation</a> */ public async getRichMenuImageWithHttpInfo( richMenuId: string, ): Promise<Types.ApiResponseType<Readable>> { const requestPath = buildPath("/v2/bot/richmenu/{richMenuId}/content", { richMenuId: richMenuId, }); const response = await this.httpClient.get(requestPath); return { httpResponse: response, body: convertResponseToReadable(response), }; } /** * Upload rich menu image * Calls `POST https://api-data.line.me/v2/bot/richmenu/{richMenuId}/content`. * To inspect the HTTP status code or response headers, use {@link setRichMenuImageWithHttpInfo}. * @param richMenuId The ID of the rich menu to attach the image to * @param body * @returns A promise resolving to the response body. * @see <a href="https://developers.line.biz/en/reference/messaging-api/#upload-rich-menu-image">LINE Developers documentation</a> */ public async setRichMenuImage( richMenuId: string, body: Blob, ): Promise<Types.MessageAPIResponseBase> { return (await this.setRichMenuImageWithHttpInfo(richMenuId, body)).body; } /** * Upload rich menu image * Calls `POST https://api-data.line.me/v2/bot/richmenu/{richMenuId}/content`. * This method returns the response body together with the underlying `httpResponse`. * @param richMenuId The ID of the rich menu to attach the image to * @param body * @returns A promise resolving to the response body together with the underlying `httpResponse`. * @see <a href="https://developers.line.biz/en/reference/messaging-api/#upload-rich-menu-image">LINE Developers documentation</a> */ public async setRichMenuImageWithHttpInfo( richMenuId: string, body: Blob, ): Promise<Types.ApiResponseType<Types.MessageAPIResponseBase>> { const requestPath = buildPath("/v2/bot/richmenu/{richMenuId}/content", { richMenuId: richMenuId, }); const params = body; const res = await this.httpClient.postBinaryContent(requestPath, params); const text = await res.text(); const parsedBody = text ? JSON.parse(text) : null; return { httpResponse: res, body: parsedBody }; } }