UNPKG

5.14 kBTypeScriptView Raw
1/// <reference types="node" />
2/// <reference types="node" />
3import * as http from 'http';
4import * as tg from './core/types/typegram';
5import * as tt from './telegram-types';
6import { Composer } from './composer';
7import { MaybePromise } from './core/helpers/util';
8import ApiClient from './core/network/client';
9import Context from './context';
10import Telegram from './telegram';
11import { TlsOptions } from 'tls';
12export declare namespace Telegraf {
13 interface Options<TContext extends Context> {
14 contextType: new (...args: ConstructorParameters<typeof Context>) => TContext;
15 handlerTimeout: number;
16 telegram?: Partial<ApiClient.Options>;
17 }
18 interface LaunchOptions {
19 dropPendingUpdates?: boolean;
20 /** List the types of updates you want your bot to receive */
21 allowedUpdates?: tt.UpdateType[];
22 /** Configuration options for when the bot is run via webhooks */
23 webhook?: {
24 /** Public domain for webhook. */
25 domain: string;
26 /**
27 * Webhook url path; will be automatically generated if not specified
28 * @deprecated Pass `path` instead
29 * */
30 hookPath?: string;
31 /** Webhook url path; will be automatically generated if not specified */
32 path?: string;
33 host?: string;
34 port?: number;
35 /** The fixed IP address which will be used to send webhook requests instead of the IP address resolved through DNS */
36 ipAddress?: string;
37 /**
38 * Maximum allowed number of simultaneous HTTPS connections to the webhook for update delivery, 1-100. Defaults to 40.
39 * Use lower values to limit the load on your bot's server, and higher values to increase your bot's throughput.
40 */
41 maxConnections?: number;
42 /** TLS server options. Omit to use http. */
43 tlsOptions?: TlsOptions;
44 /**
45 * A secret token to be sent in a header `“X-Telegram-Bot-Api-Secret-Token”` in every webhook request.
46 * 1-256 characters. Only characters `A-Z`, `a-z`, `0-9`, `_` and `-` are allowed.
47 * The header is useful to ensure that the request comes from a webhook set by you.
48 */
49 secretToken?: string;
50 /**
51 * Upload your public key certificate so that the root certificate in use can be checked.
52 * See [self-signed guide](https://core.telegram.org/bots/self-signed) for details.
53 */
54 certificate?: tg.InputFile;
55 cb?: http.RequestListener;
56 };
57 }
58}
59export declare class Telegraf<C extends Context = Context> extends Composer<C> {
60 private readonly options;
61 private webhookServer?;
62 private polling?;
63 /** Set manually to avoid implicit `getMe` call in `launch` or `webhookCallback` */
64 botInfo?: tg.UserFromGetMe;
65 telegram: Telegram;
66 readonly context: Partial<C>;
67 /** Assign to this to customise the webhook filter middleware.
68 * `{ path, secretToken }` will be bound to this rather than the Telegraf instance.
69 * Remember to assign a regular function and not an arrow function so it's bindable.
70 */
71 webhookFilter: (this: {
72 /** @deprecated Use path instead */
73 hookPath: string;
74 path: string;
75 secretToken?: string;
76 }, req: http.IncomingMessage) => boolean;
77 private handleError;
78 constructor(token: string, options?: Partial<Telegraf.Options<C>>);
79 private get token();
80 /** @deprecated use `ctx.telegram.webhookReply` */
81 set webhookReply(webhookReply: boolean);
82 /** @deprecated use `ctx.telegram.webhookReply` */
83 get webhookReply(): boolean;
84 /**
85 * _Override_ error handling
86 */
87 catch(handler: (err: unknown, ctx: C) => MaybePromise<void>): this;
88 /**
89 * You must call `bot.telegram.setWebhook` for this to work.
90 * You should probably use {@link Telegraf.createWebhook} instead.
91 */
92 webhookCallback(path?: string, opts?: {
93 secretToken?: string;
94 }): (req: http.IncomingMessage & {
95 body?: tg.Update | undefined;
96 }, res: http.ServerResponse<http.IncomingMessage>, next?: () => void) => Promise<void>;
97 private getDomainOpts;
98 /**
99 * Specify a url to receive incoming updates via webhook.
100 * Returns an Express-style middleware you can pass to app.use()
101 */
102 createWebhook(opts: {
103 domain: string;
104 path?: string;
105 } & tt.ExtraSetWebhook): Promise<(req: http.IncomingMessage & {
106 body?: tg.Update | undefined;
107 }, res: http.ServerResponse<http.IncomingMessage>, next?: () => void) => Promise<void>>;
108 private startPolling;
109 private startWebhook;
110 secretPathComponent(): string;
111 launch(onLaunch?: () => void): Promise<void>;
112 launch(config: Telegraf.LaunchOptions, onLaunch?: () => void): Promise<void>;
113 stop(reason?: string): void;
114 private botInfoCall?;
115 handleUpdate(update: tg.Update, webhookResponse?: http.ServerResponse): Promise<void>;
116}
117//# sourceMappingURL=telegraf.d.ts.map
\No newline at end of file