telegram-bot-api-nodejs
Advanced tools
@@ -48,5 +48,2 @@ export type ChatType = "private" | "group" | "supergroup" | "channel"; | ||
} | ||
export interface GetChatOptions { | ||
chat_id: string; | ||
} | ||
interface SetMyCommandsOptions { | ||
@@ -67,7 +64,2 @@ commands: BotCommand[]; | ||
} | ||
export interface GetUserProfilePhotosOptions { | ||
user_id: number | string; | ||
offset?: number; | ||
limit?: number; | ||
} | ||
interface PassportFile { | ||
@@ -522,6 +514,14 @@ file_id: string; | ||
}, signal: AbortSignal): Promise<Boolean>; | ||
export declare function getUserProfilePhotos(token: string, payload: GetUserProfilePhotosOptions, signal: AbortSignal): Promise<UserProfilePhotos>; | ||
export declare function getFile(token: string, file_id: string, signal: AbortSignal): Promise<File>; | ||
export declare function getUserProfilePhotos(token: string, payload: { | ||
user_id: number | string; | ||
offset?: number; | ||
limit?: number; | ||
}, signal: AbortSignal): Promise<UserProfilePhotos>; | ||
export declare function getFile(token: string, payload: { | ||
file_id: string; | ||
}, signal: AbortSignal): Promise<File>; | ||
export declare function answerCallbackQuery(token: string, payload: AnswerCallbackQueryOptions, signal: AbortSignal): Promise<File>; | ||
export declare function getChat(token: string, payload: GetChatOptions, signal: AbortSignal): Promise<Chat>; | ||
export declare function getChat(token: string, payload: { | ||
chat_id: string; | ||
}, signal: AbortSignal): Promise<Chat>; | ||
export declare function getChatMember(token: string, payload: { | ||
@@ -625,5 +625,7 @@ chat_id: string; | ||
export declare function parseCallbackQuery(v?: CallbackQuery): CallbackQuery | undefined; | ||
export declare function parseResponse<T>(response: Response): Promise<T>; | ||
export declare class TelegramError extends Error { | ||
status: number; | ||
constructor(message: string, status: number); | ||
error_code: number; | ||
parameters: Record<string, any>; | ||
constructor(message: string, error_code: number, parameters?: Record<string, any>); | ||
} | ||
@@ -630,0 +632,0 @@ /** |
17
index.js
@@ -100,6 +100,6 @@ /** | ||
} | ||
export function getFile(token, file_id, signal) { | ||
export function getFile(token, payload, signal) { | ||
return fetch(`https://api.telegram.org/bot${token}/getFile`, { | ||
method: "POST", | ||
body: JSON.stringify({ file_id }), | ||
body: JSON.stringify(payload), | ||
headers, | ||
@@ -454,3 +454,3 @@ signal | ||
} | ||
function parseResponse(response) { | ||
export function parseResponse(response) { | ||
return response.text().then(function (text) { | ||
@@ -470,10 +470,13 @@ let data; | ||
const description = String(data.description ?? ""); | ||
throw new TelegramError(description, response.status); | ||
const parameters = data.parameters || {}; | ||
throw new TelegramError(description, error_code, parameters); | ||
}); | ||
} | ||
export class TelegramError extends Error { | ||
status; | ||
constructor(message, status) { | ||
error_code; | ||
parameters; | ||
constructor(message, error_code, parameters = {}) { | ||
super(message); | ||
this.status = status; | ||
this.error_code = error_code; | ||
this.parameters = parameters; | ||
} | ||
@@ -480,0 +483,0 @@ } |
39
index.ts
@@ -220,6 +220,2 @@ /** | ||
export interface GetChatOptions { | ||
chat_id: string | ||
} | ||
interface SetMyCommandsOptions { | ||
@@ -247,8 +243,2 @@ commands: BotCommand[] | ||
export interface GetUserProfilePhotosOptions { | ||
user_id: number | string | ||
offset?: number; | ||
limit?: number; | ||
} | ||
interface SetGameScoreOptions { | ||
@@ -1163,3 +1153,7 @@ force?: boolean; | ||
export function getUserProfilePhotos(token: string, payload: GetUserProfilePhotosOptions, signal: AbortSignal) { | ||
export function getUserProfilePhotos(token: string, payload: { | ||
user_id: number | string | ||
offset?: number; | ||
limit?: number; | ||
}, signal: AbortSignal) { | ||
return fetch(`https://api.telegram.org/bot${token}/getUserProfilePhotos`, { | ||
@@ -1173,6 +1167,8 @@ method: "POST", | ||
export function getFile(token: string, file_id: string, signal: AbortSignal) { | ||
export function getFile(token: string, payload: { | ||
file_id: string | ||
}, signal: AbortSignal) { | ||
return fetch(`https://api.telegram.org/bot${token}/getFile`, { | ||
method: "POST", | ||
body: JSON.stringify({ file_id }), | ||
body: JSON.stringify(payload), | ||
headers, | ||
@@ -1192,3 +1188,5 @@ signal | ||
export function getChat(token: string, payload: GetChatOptions, signal: AbortSignal) { | ||
export function getChat(token: string, payload: { | ||
chat_id: string | ||
}, signal: AbortSignal) { | ||
return fetch(`https://api.telegram.org/bot${token}/getChat`, { | ||
@@ -1577,3 +1575,3 @@ method: "POST", | ||
function parseResponse<T>(response: Response) { | ||
export function parseResponse<T>(response: Response) { | ||
return response.text().then(function (text) { | ||
@@ -1597,4 +1595,5 @@ let data: any | ||
const description = String(data.description ?? "") | ||
const parameters = data.parameters || {} | ||
throw new TelegramError(description, response.status) | ||
throw new TelegramError(description, error_code, parameters) | ||
}) | ||
@@ -1604,8 +1603,10 @@ } | ||
export class TelegramError extends Error { | ||
status: number | ||
error_code: number | ||
parameters: Record<string, any> | ||
constructor(message: string, status: number) { | ||
constructor(message: string, error_code: number, parameters: Record<string, any> = {}) { | ||
super(message) | ||
this.status = status | ||
this.error_code = error_code | ||
this.parameters = parameters | ||
} | ||
@@ -1612,0 +1613,0 @@ } |
{ | ||
"name": "telegram-bot-api-nodejs", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Telegram Bot API client for nodejs", | ||
@@ -11,3 +11,4 @@ "type": "module", | ||
"build": "tsc", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"pretest": "npm run build", | ||
"test": "node --test" | ||
}, | ||
@@ -14,0 +15,0 @@ "author": "", |
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
73160
0.37%2543
0.32%1
-50%