Browse Source

Merge pull request #5 from naresh97/development

Development
our-sejahtera-rebranding
Nareshkumar Rao 3 years ago
committed by GitHub
parent
commit
44471df433
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      src/db/utils.js
  2. 46
      src/routes/TelegramWebhookRoute.js
  3. 19
      src/strings.js
  4. 2
      src/telegram.js

3
src/db/utils.js

@ -1,3 +1,4 @@
const { strings_en } = require("../strings");
const { sendTelegramMessage } = require("../telegram");
const { User, Contact } = require("./db");
@ -11,7 +12,7 @@ function addContact(telegram, withUserID, done) {
);
sendTelegramMessage(
withUser.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");

46
src/routes/TelegramWebhookRoute.js

@ -1,28 +1,31 @@
const { Op } = require("sequelize");
const { User, Contact } = require("../db/db");
const { strings_en } = require("../strings");
const { sendTelegramMessage } = require("../telegram");
function TelegramWebhookRoute(req, res) {
try {
const messageText = req.body.message.text;
const telegramID = req.body.message.from.id;
if (messageText.toLowerCase() == "/covidpositive") {
userInfected(telegramID, (result) => {
if (result.saved) {
sendTelegramMessage(
telegramID,
"Thanks for informing us. We will notify the people you were in contact with!",
() => {}
);
informContacts(telegramID, () => {});
} else {
sendTelegramMessage(
telegramID,
"Sorry, something went wrong.",
() => {}
);
}
});
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") {
userInfected(telegramID, (result) => {
if (result.saved) {
sendTelegramMessage(
telegramID,
strings_en.telegram_inform_positive
);
informContacts(telegramID);
} else {
sendTelegramMessage(telegramID, "Sorry, something went wrong.");
}
});
}
}
} catch (e) {
console.log("Could not get Telegram Message");
@ -31,7 +34,7 @@ function TelegramWebhookRoute(req, res) {
res.send();
}
function informContacts(telegramID, doneCallback) {
function informContacts(telegramID, doneCallback = () => {}) {
User.findOne({
where: {
telegram: telegramID,
@ -54,8 +57,7 @@ function informContacts(telegramID, doneCallback) {
}).then((otherPerson) => {
sendTelegramMessage(
otherPerson.telegram,
"You're infected.",
() => {}
strings_en.telegram_inform_infect
);
});
});

19
src/strings.js

@ -0,0 +1,19 @@
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;

2
src/telegram.js

@ -16,7 +16,7 @@ function setTelegramWebHook(done) {
});
}
function sendTelegramMessage(telegramID, message, done) {
function sendTelegramMessage(telegramID, message, done = () => {}) {
const url = `https://api.telegram.org/bot${process.env.TELEGRAM_TOKEN}/sendMessage`;
axios
.post(url, {

Loading…
Cancel
Save