nestjs-telegraf/docs/getting-updates.md

39 lines
964 B
Markdown
Raw Normal View History

2023-07-24 16:02:21 +03:00
# Getting updates
## Long polling
By default, the bot receives updates using long-polling and requires no additional action.
## Webhooks
2021-01-02 03:10:25 +03:00
If you want to configure a telegram bot webhook, you need to get a middleware via `getBotToken` helper in your `main.ts` file.
To access it, you must use the `app.get()` method, followed by the provider reference:
```typescript
2021-01-02 03:10:25 +03:00
import { getBotToken } from 'nestjs-telegraf';
// ...
const bot = app.get(getBotToken());
```
Now you can connect middleware:
```typescript
2021-01-02 03:10:25 +03:00
app.use(bot.webhookCallback('/secret-path'));
```
The last step is to specify launchOptions in `forRoot` method:
```typescript
TelegrafModule.forRootAsync({
2021-01-02 03:10:25 +03:00
imports: [ConfigModule],
useFactory: (configService: ConfigService) => ({
token: configService.get<string>('TELEGRAM_BOT_TOKEN'),
launchOptions: {
webhook: {
domain: 'domain.tld',
hookPath: '/secret-path',
}
}
}),
inject: [ConfigService],
});
```