@line/bot-sdk
Version:
Node.js SDK for LINE Messaging API
269 lines • 18.2 kB
JavaScript
/**
* LINE Messaging API(Insight)
* This document describes LINE Messaging API(Insight).
*
* 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, { mergeHeaders, } from "../../http-fetch.js";
/**
* @see {@link LineBotClient} for a unified interface that wraps this client.
*/
export class InsightClient {
httpClient;
/**
* Initializes a new `InsightClient`.
*
* @param config Configuration for this API client.
* @param config.baseURL The base URL for requests. Defaults to `https://api.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 InsightClient({
* channelAccessToken: process.env.LINE_CHANNEL_ACCESS_TOKEN!,
* });
*/
constructor(config) {
const baseURL = config.baseURL || "https://api.line.me";
const defaultHeaders = mergeHeaders(config.defaultHeaders, {
Authorization: "Bearer " + config.channelAccessToken,
});
this.httpClient = new HTTPFetchClient({
defaultHeaders: defaultHeaders,
baseURL: baseURL,
});
}
/**
* Retrieves the demographic attributes for a LINE Official Account's friends.You can only retrieve information about friends for LINE Official Accounts created by users in Japan (JP), Thailand (TH), Taiwan (TW) and Indonesia (ID).
* Calls `GET https://api.line.me/v2/bot/insight/demographic`.
* To inspect the HTTP status code or response headers, use {@link getFriendsDemographicsWithHttpInfo}.
* @returns A promise resolving to the response body.
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#get-demographic">LINE Developers documentation</a>
*/
async getFriendsDemographics() {
return (await this.getFriendsDemographicsWithHttpInfo()).body;
}
/**
* Retrieves the demographic attributes for a LINE Official Account's friends.You can only retrieve information about friends for LINE Official Accounts created by users in Japan (JP), Thailand (TH), Taiwan (TW) and Indonesia (ID).
* Calls `GET https://api.line.me/v2/bot/insight/demographic`.
* This method returns the response body together with the underlying `httpResponse`.
* @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-demographic">LINE Developers documentation</a>
*/
async getFriendsDemographicsWithHttpInfo() {
const res = await this.httpClient.get("/v2/bot/insight/demographic");
const text = await res.text();
const parsedBody = text ? JSON.parse(text) : null;
return { httpResponse: res, body: parsedBody };
}
/**
* Returns statistics about how users interact with narrowcast messages or broadcast messages sent from your LINE Official Account.
* Calls `GET https://api.line.me/v2/bot/insight/message/event`.
* To inspect the HTTP status code or response headers, use {@link getMessageEventWithHttpInfo}.
* @summary Get user interaction statistics
* @param requestId Request ID of a narrowcast message or broadcast message. Each Messaging API request has a request ID.
* @returns A promise resolving to the response body.
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#get-message-event">LINE Developers documentation</a>
*/
async getMessageEvent(requestId) {
return (await this.getMessageEventWithHttpInfo(requestId)).body;
}
/**
* Returns statistics about how users interact with narrowcast messages or broadcast messages sent from your LINE Official Account.
* Calls `GET https://api.line.me/v2/bot/insight/message/event`.
* This method returns the response body together with the underlying `httpResponse`.
* @summary Get user interaction statistics
* @param requestId Request ID of a narrowcast message or broadcast message. Each Messaging API request has a request ID.
* @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-message-event">LINE Developers documentation</a>
*/
async getMessageEventWithHttpInfo(requestId) {
const queryParams = {
requestId: requestId,
};
const res = await this.httpClient.get("/v2/bot/insight/message/event", queryParams);
const text = await res.text();
const parsedBody = text ? JSON.parse(text) : null;
return { httpResponse: res, body: parsedBody };
}
/**
* Returns the number of users who have added the LINE Official Account on or before a specified date.
* Calls `GET https://api.line.me/v2/bot/insight/followers`.
* To inspect the HTTP status code or response headers, use {@link getNumberOfFollowersWithHttpInfo}.
* @summary Get number of followers
* @param date Date for which to retrieve the number of followers. Format: yyyyMMdd (e.g. 20191231) Timezone: UTC+9
* @returns A promise resolving to the response body.
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#get-number-of-followers">LINE Developers documentation</a>
*/
async getNumberOfFollowers(date) {
return (await this.getNumberOfFollowersWithHttpInfo(date)).body;
}
/**
* Returns the number of users who have added the LINE Official Account on or before a specified date.
* Calls `GET https://api.line.me/v2/bot/insight/followers`.
* This method returns the response body together with the underlying `httpResponse`.
* @summary Get number of followers
* @param date Date for which to retrieve the number of followers. Format: yyyyMMdd (e.g. 20191231) Timezone: UTC+9
* @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-number-of-followers">LINE Developers documentation</a>
*/
async getNumberOfFollowersWithHttpInfo(date) {
const queryParams = {
date: date,
};
if (queryParams["date"] === undefined) {
delete queryParams["date"];
}
const res = await this.httpClient.get("/v2/bot/insight/followers", queryParams);
const text = await res.text();
const parsedBody = text ? JSON.parse(text) : null;
return { httpResponse: res, body: parsedBody };
}
/**
* Returns the number of messages sent from LINE Official Account on a specified day.
* Calls `GET https://api.line.me/v2/bot/insight/message/delivery`.
* To inspect the HTTP status code or response headers, use {@link getNumberOfMessageDeliveriesWithHttpInfo}.
* @summary Get number of message deliveries
* @param date Date for which to retrieve number of sent messages. - Format: yyyyMMdd (e.g. 20191231) - Timezone: UTC+9
* @returns A promise resolving to the response body.
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#get-number-of-delivery-messages">LINE Developers documentation</a>
*/
async getNumberOfMessageDeliveries(date) {
return (await this.getNumberOfMessageDeliveriesWithHttpInfo(date)).body;
}
/**
* Returns the number of messages sent from LINE Official Account on a specified day.
* Calls `GET https://api.line.me/v2/bot/insight/message/delivery`.
* This method returns the response body together with the underlying `httpResponse`.
* @summary Get number of message deliveries
* @param date Date for which to retrieve number of sent messages. - Format: yyyyMMdd (e.g. 20191231) - Timezone: UTC+9
* @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-number-of-delivery-messages">LINE Developers documentation</a>
*/
async getNumberOfMessageDeliveriesWithHttpInfo(date) {
const queryParams = {
date: date,
};
const res = await this.httpClient.get("/v2/bot/insight/message/delivery", queryParams);
const text = await res.text();
const parsedBody = text ? JSON.parse(text) : null;
return { httpResponse: res, body: parsedBody };
}
/**
* Gets rich menu statistics broken down by day for the specified period, for a rich menu created via the Messaging API. Returns the daily impression count for the whole rich menu and the daily click count for each tappable area. When the total number of unique clicks during the period is below the privacy threshold, only `richMenuId` is returned and the other fields are omitted.
* Calls `GET https://api.line.me/v2/bot/insight/richmenu/{richMenuId}/daily`.
* To inspect the HTTP status code or response headers, use {@link getRichMenuInsightDailyWithHttpInfo}.
* @summary Get rich menu insight daily
* @param richMenuId ID of the rich menu created via the Messaging API.
* @param from Start date of the aggregation period (inclusive). Must be within the most recent 3 years. Format: yyyyMMdd (e.g. 20260213) Time zone: UTC+9
* @param to End date of the aggregation period (inclusive). The end date can be specified for up to 99 days after the start date. Format: yyyyMMdd (e.g. 20260215) Time zone: UTC+9
* @returns A promise resolving to the response body.
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#get-rich-menu-insight-daily">LINE Developers documentation</a>
*/
async getRichMenuInsightDaily(richMenuId, from, to) {
return (await this.getRichMenuInsightDailyWithHttpInfo(richMenuId, from, to)).body;
}
/**
* Gets rich menu statistics broken down by day for the specified period, for a rich menu created via the Messaging API. Returns the daily impression count for the whole rich menu and the daily click count for each tappable area. When the total number of unique clicks during the period is below the privacy threshold, only `richMenuId` is returned and the other fields are omitted.
* Calls `GET https://api.line.me/v2/bot/insight/richmenu/{richMenuId}/daily`.
* This method returns the response body together with the underlying `httpResponse`.
* @summary Get rich menu insight daily
* @param richMenuId ID of the rich menu created via the Messaging API.
* @param from Start date of the aggregation period (inclusive). Must be within the most recent 3 years. Format: yyyyMMdd (e.g. 20260213) Time zone: UTC+9
* @param to End date of the aggregation period (inclusive). The end date can be specified for up to 99 days after the start date. Format: yyyyMMdd (e.g. 20260215) Time zone: UTC+9
* @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-rich-menu-insight-daily">LINE Developers documentation</a>
*/
async getRichMenuInsightDailyWithHttpInfo(richMenuId, from, to) {
const requestPath = buildPath("/v2/bot/insight/richmenu/{richMenuId}/daily", {
richMenuId: richMenuId,
});
const queryParams = {
from: from,
to: to,
};
const res = await this.httpClient.get(requestPath, queryParams);
const text = await res.text();
const parsedBody = text ? JSON.parse(text) : null;
return { httpResponse: res, body: parsedBody };
}
/**
* Gets a summary of rich menu statistics for the specified period, for a rich menu created via the Messaging API. Returns the total impression count for the whole rich menu and the click count for each tappable area, aggregated over the entire period as a single result. When the total number of unique clicks during the period is below the privacy threshold, only `richMenuId` is returned and the other fields are omitted.
* Calls `GET https://api.line.me/v2/bot/insight/richmenu/{richMenuId}/summary`.
* To inspect the HTTP status code or response headers, use {@link getRichMenuInsightSummaryWithHttpInfo}.
* @summary Get rich menu insight summary
* @param richMenuId ID of the rich menu created via the Messaging API.
* @param from Start date of the aggregation period (inclusive). Must be within the most recent 3 years. Format: yyyyMMdd (e.g. 20260213) Time zone: UTC+9
* @param to End date of the aggregation period (inclusive). The end date can be specified for up to 396 days after the start date. Format: yyyyMMdd (e.g. 20260215) Time zone: UTC+9
* @returns A promise resolving to the response body.
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#get-rich-menu-insight-summary">LINE Developers documentation</a>
*/
async getRichMenuInsightSummary(richMenuId, from, to) {
return (await this.getRichMenuInsightSummaryWithHttpInfo(richMenuId, from, to)).body;
}
/**
* Gets a summary of rich menu statistics for the specified period, for a rich menu created via the Messaging API. Returns the total impression count for the whole rich menu and the click count for each tappable area, aggregated over the entire period as a single result. When the total number of unique clicks during the period is below the privacy threshold, only `richMenuId` is returned and the other fields are omitted.
* Calls `GET https://api.line.me/v2/bot/insight/richmenu/{richMenuId}/summary`.
* This method returns the response body together with the underlying `httpResponse`.
* @summary Get rich menu insight summary
* @param richMenuId ID of the rich menu created via the Messaging API.
* @param from Start date of the aggregation period (inclusive). Must be within the most recent 3 years. Format: yyyyMMdd (e.g. 20260213) Time zone: UTC+9
* @param to End date of the aggregation period (inclusive). The end date can be specified for up to 396 days after the start date. Format: yyyyMMdd (e.g. 20260215) Time zone: UTC+9
* @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-rich-menu-insight-summary">LINE Developers documentation</a>
*/
async getRichMenuInsightSummaryWithHttpInfo(richMenuId, from, to) {
const requestPath = buildPath("/v2/bot/insight/richmenu/{richMenuId}/summary", {
richMenuId: richMenuId,
});
const queryParams = {
from: from,
to: to,
};
const res = await this.httpClient.get(requestPath, queryParams);
const text = await res.text();
const parsedBody = text ? JSON.parse(text) : null;
return { httpResponse: res, body: parsedBody };
}
/**
* You can check the per-unit statistics of how users interact with push messages and multicast messages sent from your LINE Official Account.
* Calls `GET https://api.line.me/v2/bot/insight/message/event/aggregation`.
* To inspect the HTTP status code or response headers, use {@link getStatisticsPerUnitWithHttpInfo}.
* @param customAggregationUnit Name of aggregation unit specified when sending the message. Case-sensitive. For example, `Promotion_a` and `Promotion_A` are regarded as different unit names.
* @param from Start date of aggregation period. Format: yyyyMMdd (e.g. 20210301) Time zone: UTC+9
* @param to End date of aggregation period. The end date can be specified for up to 30 days later. For example, if the start date is 20210301, the latest end date is 20210331. Format: yyyyMMdd (e.g. 20210301) Time zone: UTC+9
* @returns A promise resolving to the response body.
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#get-statistics-per-unit">LINE Developers documentation</a>
*/
async getStatisticsPerUnit(customAggregationUnit, from, to) {
return (await this.getStatisticsPerUnitWithHttpInfo(customAggregationUnit, from, to)).body;
}
/**
* You can check the per-unit statistics of how users interact with push messages and multicast messages sent from your LINE Official Account.
* Calls `GET https://api.line.me/v2/bot/insight/message/event/aggregation`.
* This method returns the response body together with the underlying `httpResponse`.
* @param customAggregationUnit Name of aggregation unit specified when sending the message. Case-sensitive. For example, `Promotion_a` and `Promotion_A` are regarded as different unit names.
* @param from Start date of aggregation period. Format: yyyyMMdd (e.g. 20210301) Time zone: UTC+9
* @param to End date of aggregation period. The end date can be specified for up to 30 days later. For example, if the start date is 20210301, the latest end date is 20210331. Format: yyyyMMdd (e.g. 20210301) Time zone: UTC+9
* @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-statistics-per-unit">LINE Developers documentation</a>
*/
async getStatisticsPerUnitWithHttpInfo(customAggregationUnit, from, to) {
const queryParams = {
customAggregationUnit: customAggregationUnit,
from: from,
to: to,
};
const res = await this.httpClient.get("/v2/bot/insight/message/event/aggregation", queryParams);
const text = await res.text();
const parsedBody = text ? JSON.parse(text) : null;
return { httpResponse: res, body: parsedBody };
}
}
//# sourceMappingURL=insightClient.js.map