How to configure webhook with self-signed certificate? #778
Answered
by
evilsprut
mixalezhnev
asked this question in
Q&A
-
It's straightforward in Telegraf docs, but not clearly by nestjs-telegraf docs. Anyway, does anyone have an understanding of how to properly configure a webhook connection with a self-signed certificate using this library? |
Beta Was this translation helpful? Give feedback.
Answered by
evilsprut
Apr 11, 2022
Replies: 1 comment 4 replies
-
First, a self-signed certificate cannot be set for a route or for a telegraph (specially). Self-signed certificate can be set for web server. So you have two options, install a certificate for your NestJs server or create a separate server for the Telegraf webhook. Example 1: const app = await NestFactory.createApplicationContext(AppModule);
const bot = app.get(getBotToken());
const tlsOptions = {
key: fs.readFileSync('server-key.pem'),
cert: fs.readFileSync('server-cert.pem'),
ca: [
fs.readFileSync('client-cert.pem')
]
}
bot.telegram.setWebhook('https://server.tld:8443/secret-path', {
certificate: { source: fs.readFileSync('server-cert.pem') }
})
bot.startWebhook('/secret-path', tlsOptions, 8443) Example 2: const httpsOptions = {
key: fs.readFileSync('./secrets/private-key.pem'),
cert: fs.readFileSync('./secrets/public-certificate.pem'),
};
const app = await NestFactory.create(AppModule, {
httpsOptions,
});
const bot = app.get(getBotToken());
app.use(bot.webhookCallback('/secret-path')); |
Beta Was this translation helpful? Give feedback.
4 replies
Answer selected by
mixalezhnev
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
First, a self-signed certificate cannot be set for a route or for a telegraph (specially). Self-signed certificate can be set for web server. So you have two options, install a certificate for your NestJs server or create a separate server for the Telegraf webhook.
Example 1: