|
1 | | -import fetch from 'node-fetch'; |
2 | | -import * as Sentry from '@sentry/node'; |
| 1 | +import fetch from "node-fetch"; |
| 2 | +import * as Sentry from "@sentry/node"; |
3 | 3 |
|
4 | 4 | const { TELEGRAM_BOT_TOKEN, APP_URL, SENTRY_DSN } = process.env; |
5 | 5 |
|
6 | 6 | Sentry.init({ dsn: SENTRY_DSN }); |
7 | 7 |
|
8 | 8 | /* used to activate webhook whenever we change the APP_URL */ |
9 | | -export default async(request, response) => { |
| 9 | +export default async (request, response) => { |
10 | 10 | try { |
11 | 11 | if (request.query.token === TELEGRAM_BOT_TOKEN) { |
12 | | - const fetchResponse = await fetch(`https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/setWebhook?url=${APP_URL}/api/telegram/update?token=${TELEGRAM_BOT_TOKEN}}`, { |
13 | | - method: 'POST', |
14 | | - headers: { |
15 | | - 'Content-Type': 'application/json', |
16 | | - }, |
17 | | - }); |
| 12 | + const fetchResponse = await fetch( |
| 13 | + `https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/setWebhook?url=${APP_URL}/api/telegram/update?token=${TELEGRAM_BOT_TOKEN}`, |
| 14 | + { |
| 15 | + method: "POST", |
| 16 | + headers: { |
| 17 | + "Content-Type": "application/json" |
| 18 | + } |
| 19 | + } |
| 20 | + ); |
18 | 21 | const jsonResponse = await fetchResponse.json(); |
19 | 22 |
|
20 | 23 | response.status(200).json(jsonResponse); |
21 | 24 | } else { |
22 | | - response.status(401).send('Unauthorized'); |
| 25 | + response.status(401).send("Unauthorized"); |
23 | 26 | } |
24 | 27 | } catch (error) { |
25 | 28 | Sentry.captureException(error); |
26 | 29 |
|
27 | | - response.status(400).send('not ok'); |
| 30 | + response.status(400).send("not ok"); |
28 | 31 | } |
29 | 32 | }; |
0 commit comments