UNPKG

@line/bot-sdk

Version:
189 lines 9.57 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. */ import { buildPath } from "../../utils.js"; import HTTPFetchClient, { convertResponseToReadable, mergeHeaders, } from "../../http-fetch.js"; /** * @see {@link LineBotClient} for a unified interface that wraps this client. */ export class MessagingApiBlobClient { httpClient; /** * 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) { 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> */ async getMessageContent(messageId) { 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> */ async getMessageContentWithHttpInfo(messageId) { 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> */ async getMessageContentPreview(messageId) { 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> */ async getMessageContentPreviewWithHttpInfo(messageId) { 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> */ async getMessageContentTranscodingByMessageId(messageId) { 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> */ async getMessageContentTranscodingByMessageIdWithHttpInfo(messageId) { 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> */ async getRichMenuImage(richMenuId) { 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> */ async getRichMenuImageWithHttpInfo(richMenuId) { 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> */ async setRichMenuImage(richMenuId, body) { 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> */ async setRichMenuImageWithHttpInfo(richMenuId, body) { 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 }; } } //# sourceMappingURL=messagingApiBlobClient.js.map