Browse Source

ran linter

pull/5/head
Nareshkumar Rao 3 years ago
parent
commit
01d1090975
  1. 35
      src/routes/TelegramWebhookRoute.js
  2. 9
      src/strings.js

35
src/routes/TelegramWebhookRoute.js

@ -4,17 +4,22 @@ const { strings_en } = require("../strings");
const { sendTelegramMessage } = require("../telegram"); const { sendTelegramMessage } = require("../telegram");
function TelegramWebhookRoute(req, res) { function TelegramWebhookRoute(req, res) {
try { try {
if (req.body.message.connected_website) { if (req.body.message.connected_website) {
sendTelegramMessage(req.body.message.from.id, "Thanks for using OurSejahtera! Let's stay safer together <3");
sendTelegramMessage(
req.body.message.from.id,
"Thanks for using OurSejahtera! Let's stay safer together <3"
);
} else { } 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") {
userInfected(telegramID, (result) => { userInfected(telegramID, (result) => {
if (result.saved) { if (result.saved) {
sendTelegramMessage(telegramID, strings_en.telegram_inform_positive);
sendTelegramMessage(
telegramID,
strings_en.telegram_inform_positive
);
informContacts(telegramID); informContacts(telegramID);
} else { } else {
sendTelegramMessage(telegramID, "Sorry, something went wrong."); sendTelegramMessage(telegramID, "Sorry, something went wrong.");
@ -33,30 +38,32 @@ function informContacts(telegramID, doneCallback=()=>{}){
User.findOne({ User.findOne({
where: { where: {
telegram: telegramID, telegram: telegramID,
}
}).then(user => {
},
}).then((user) => {
if (user) { if (user) {
const userRowID = user.id; const userRowID = user.id;
Contact.findAll({ Contact.findAll({
where: { where: {
[Op.or]: [{ user: userRowID }, { with: userRowID }], [Op.or]: [{ user: userRowID }, { with: userRowID }],
}
})
.then(result => {
result.forEach(contact => {
const otherPersonID = contact.user == userRowID ? contact.with : contact.user;
},
}).then((result) => {
result.forEach((contact) => {
const otherPersonID =
contact.user == userRowID ? contact.with : contact.user;
User.findOne({ User.findOne({
where: { where: {
id: otherPersonID, id: otherPersonID,
}
}).then(otherPerson => {
sendTelegramMessage(otherPerson.telegram, strings_en.telegram_inform_infect);
},
}).then((otherPerson) => {
sendTelegramMessage(
otherPerson.telegram,
strings_en.telegram_inform_infect
);
}); });
}); });
}); });
} }
}); });
} }
function userInfected(telegramID, doneCallback) { function userInfected(telegramID, doneCallback) {

9
src/strings.js

@ -1,14 +1,17 @@
const strings_en = { const strings_en = {
telegram_inform_infect: "ATTENTION! Someone you have been \
telegram_inform_infect:
"ATTENTION! Someone you have been \
in contact with has reported being tested POSITIVE with \ in contact with has reported being tested POSITIVE with \
COVID19. Please maintain a self-quarantine until getting \ COVID19. Please maintain a self-quarantine until getting \
tested, and follow all local guidelines.", tested, and follow all local guidelines.",
telegram_inform_positive: "Thanks for informing us. We will \
telegram_inform_positive:
"Thanks for informing us. We will \
notify the people you were in contact with! Please follow all \ notify the people you were in contact with! Please follow all \
local COVID19 guidelines.", local COVID19 guidelines.",
telegram_qr_scanned: "Someone scanned your QR code. You will \
telegram_qr_scanned:
"Someone scanned your QR code. You will \
be notified if they report being tested positive with COVID19. If \ be notified if they report being tested positive with COVID19. If \
you are tested positive, please tell me /COVIDPOSITIVE", you are tested positive, please tell me /COVIDPOSITIVE",
}; };

Loading…
Cancel
Save