Browse Source

Merge branch 'development' into tsMigration

tsMigration
Nareshkumar Rao 3 years ago
parent
commit
171200d225
  1. 3
      src/db/utils.ts
  2. 5
      src/routes/LoginRoute.ts
  3. 13
      src/routes/TelegramWebhookRoute.ts
  4. 19
      src/strings.ts

3
src/db/utils.ts

@ -1,3 +1,4 @@
import { strings_en } from "../strings";
import { sendTelegramMessage } from "../telegram"; import { sendTelegramMessage } from "../telegram";
import { User, Contact, TelegramID, UserRowID } from "./db"; import { User, Contact, TelegramID, UserRowID } from "./db";
@ -20,7 +21,7 @@ export function addContact(
); );
sendTelegramMessage( sendTelegramMessage(
userB!.telegram, 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"); done(true, "Successfully added contact");
}) })

5
src/routes/LoginRoute.ts

@ -25,6 +25,11 @@ export function LoginRoute(req: LoginRequest, res: Response) {
const telegramResponse = req.body.telegramResponse; const telegramResponse = req.body.telegramResponse;
authUser(telegramResponse, (authObject) => { authUser(telegramResponse, (authObject) => {
if (authObject) { if (authObject) {
// User is already logged in
if (req.session.user == telegramResponse.id) {
res.send(authObject);
return;
}
const verified = req.session.verified; const verified = req.session.verified;
const verifiedBy = req.session.verifiedBy; const verifiedBy = req.session.verifiedBy;
req.session.regenerate(() => { req.session.regenerate(() => {

13
src/routes/TelegramWebhookRoute.ts

@ -1,6 +1,7 @@
import { Request, Response } from "express"; import { Request, Response } from "express";
import { Op } from "sequelize/types"; import { Op } from "sequelize/types";
import { Contact, TelegramID, User } from "../db/db"; import { Contact, TelegramID, User } from "../db/db";
import { strings_en } from "../strings";
import { sendTelegramMessage } from "../telegram"; import { sendTelegramMessage } from "../telegram";
interface TelegramWebhookRequest extends Request { interface TelegramWebhookRequest extends Request {
@ -10,6 +11,7 @@ interface TelegramWebhookRequest extends Request {
from: { from: {
id: TelegramID; id: TelegramID;
}; };
connected_website: string;
}; };
}; };
} }
@ -19,6 +21,12 @@ export function TelegramWebhookRoute(
res: Response res: Response
) { ) {
try { 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 messageText = req.body.message.text;
const telegramID = req.body.message.from.id; const telegramID = req.body.message.from.id;
if (messageText.toLowerCase() == "/covidpositive") { if (messageText.toLowerCase() == "/covidpositive") {
@ -26,7 +34,7 @@ export function TelegramWebhookRoute(
if (result.saved) { if (result.saved) {
sendTelegramMessage( sendTelegramMessage(
telegramID, telegramID,
"Thanks for informing us. We will notify the people you were in contact with!"
strings_en.telegram_inform_positive,
); );
informContacts(telegramID); informContacts(telegramID);
} else { } else {
@ -34,6 +42,7 @@ export function TelegramWebhookRoute(
} }
}); });
} }
}
} catch (e) { } catch (e) {
console.log("Could not get Telegram Message"); console.log("Could not get Telegram Message");
} }
@ -63,7 +72,7 @@ function informContacts(telegramID: TelegramID) {
}, },
}).then((otherPerson) => { }).then((otherPerson) => {
otherPerson && otherPerson &&
sendTelegramMessage(otherPerson.telegram, "You're infected.");
sendTelegramMessage(otherPerson.telegram, strings_en.telegram_inform_infect);
}); });
}); });
}); });

19
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;
Loading…
Cancel
Save