UNPKG

2.03 kBTypeScriptView Raw
1/// <reference types="node" />
2import * as http from 'http';
3import { Opts, Telegram } from '../types/typegram';
4import { AbortSignal } from 'abort-controller';
5import { URL } from 'url';
6declare namespace ApiClient {
7 type Agent = http.Agent | ((parsedUrl: URL) => http.Agent) | undefined;
8 interface Options {
9 /**
10 * Agent for communicating with the bot API.
11 */
12 agent?: http.Agent;
13 /**
14 * Agent for attaching files via URL.
15 * 1. Not all agents support both `http:` and `https:`.
16 * 2. When passing a function, create the agents once, outside of the function.
17 * Creating new agent every request probably breaks `keepAlive`.
18 */
19 attachmentAgent?: Agent;
20 apiRoot: string;
21 /**
22 * @default 'bot'
23 * @see https://github.com/tdlight-team/tdlight-telegram-bot-api#user-mode
24 */
25 apiMode: 'bot' | 'user';
26 webhookReply: boolean;
27 }
28 interface CallApiOptions {
29 signal?: AbortSignal;
30 }
31}
32declare class ApiClient {
33 readonly token: string;
34 private readonly response?;
35 readonly options: ApiClient.Options;
36 constructor(token: string, options?: Partial<ApiClient.Options>, response?: http.ServerResponse | undefined);
37 /**
38 * If set to `true`, first _eligible_ call will avoid performing a POST request.
39 * Note that such a call:
40 * 1. cannot report errors or return meaningful values,
41 * 2. resolves before bot API has a chance to process it,
42 * 3. prematurely confirms the update as processed.
43 *
44 * https://core.telegram.org/bots/faq#how-can-i-make-requests-in-response-to-updates
45 * https://github.com/telegraf/telegraf/pull/1250
46 */
47 set webhookReply(enable: boolean);
48 get webhookReply(): boolean;
49 callApi<M extends keyof Telegram>(method: M, payload: Opts<M>, { signal }?: ApiClient.CallApiOptions): Promise<ReturnType<Telegram[M]>>;
50}
51export default ApiClient;
52//# sourceMappingURL=client.d.ts.map
\No newline at end of file