diff --git a/src/db/utils.ts b/src/db/utils.ts index 67b21c8..6e5f3d3 100644 --- a/src/db/utils.ts +++ b/src/db/utils.ts @@ -1,3 +1,4 @@ +import { strings_en } from "../strings"; import { sendTelegramMessage } from "../telegram"; import { User, Contact, TelegramID, UserRowID } from "./db"; @@ -20,7 +21,7 @@ export function addContact( ); sendTelegramMessage( userB!.telegram, - "Someone scanned your QR code. You will be notified if they are tested positive with Covid. If you are tested positive, please tell this bot /COVIDPOSITIVE" + strings_en.telegram_qr_scanned, ); done(true, "Successfully added contact"); }) diff --git a/src/routes/LoginRoute.ts b/src/routes/LoginRoute.ts index cac172c..b28dc37 100644 --- a/src/routes/LoginRoute.ts +++ b/src/routes/LoginRoute.ts @@ -25,6 +25,11 @@ export function LoginRoute(req: LoginRequest, res: Response) { const telegramResponse = req.body.telegramResponse; authUser(telegramResponse, (authObject) => { if (authObject) { + // User is already logged in + if (req.session.user == telegramResponse.id) { + res.send(authObject); + return; + } const verified = req.session.verified; const verifiedBy = req.session.verifiedBy; req.session.regenerate(() => { diff --git a/src/routes/TelegramWebhookRoute.ts b/src/routes/TelegramWebhookRoute.ts index e337ab3..f33c9e7 100644 --- a/src/routes/TelegramWebhookRoute.ts +++ b/src/routes/TelegramWebhookRoute.ts @@ -1,6 +1,7 @@ import { Request, Response } from "express"; import { Op } from "sequelize/types"; import { Contact, TelegramID, User } from "../db/db"; +import { strings_en } from "../strings"; import { sendTelegramMessage } from "../telegram"; interface TelegramWebhookRequest extends Request { @@ -10,6 +11,7 @@ interface TelegramWebhookRequest extends Request { from: { id: TelegramID; }; + connected_website: string; }; }; } @@ -19,6 +21,12 @@ export function TelegramWebhookRoute( res: Response ) { try { + if (req.body.message.connected_website) { + sendTelegramMessage( + req.body.message.from.id, + "Thanks for using OurSejahtera! Let's stay safer together <3" + ); + } else { const messageText = req.body.message.text; const telegramID = req.body.message.from.id; if (messageText.toLowerCase() == "/covidpositive") { @@ -26,7 +34,7 @@ export function TelegramWebhookRoute( if (result.saved) { sendTelegramMessage( telegramID, - "Thanks for informing us. We will notify the people you were in contact with!" + strings_en.telegram_inform_positive, ); informContacts(telegramID); } else { @@ -34,6 +42,7 @@ export function TelegramWebhookRoute( } }); } + } } catch (e) { console.log("Could not get Telegram Message"); } @@ -63,7 +72,7 @@ function informContacts(telegramID: TelegramID) { }, }).then((otherPerson) => { otherPerson && - sendTelegramMessage(otherPerson.telegram, "You're infected."); + sendTelegramMessage(otherPerson.telegram, strings_en.telegram_inform_infect); }); }); }); diff --git a/src/strings.ts b/src/strings.ts new file mode 100644 index 0000000..9509dc8 --- /dev/null +++ b/src/strings.ts @@ -0,0 +1,19 @@ +export const strings_en = { + telegram_inform_infect: + "ATTENTION! Someone you have been \ +in contact with has reported being tested POSITIVE with \ +COVID19. Please maintain a self-quarantine until getting \ +tested, and follow all local guidelines.", + + telegram_inform_positive: + "Thanks for informing us. We will \ +notify the people you were in contact with! Please follow all \ +local COVID19 guidelines.", + + telegram_qr_scanned: + "Someone scanned your QR code. You will \ +be notified if they report being tested positive with COVID19. If \ +you are tested positive, please tell me /COVIDPOSITIVE", +}; + +exports.strings_en = strings_en;