|
|
@ -4,17 +4,22 @@ const { strings_en } = require("../strings"); |
|
|
|
const { sendTelegramMessage } = require("../telegram"); |
|
|
|
|
|
|
|
function TelegramWebhookRoute(req, res) { |
|
|
|
|
|
|
|
try { |
|
|
|
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 { |
|
|
|
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); |
|
|
|
sendTelegramMessage( |
|
|
|
telegramID, |
|
|
|
strings_en.telegram_inform_positive |
|
|
|
); |
|
|
|
informContacts(telegramID); |
|
|
|
} else { |
|
|
|
sendTelegramMessage(telegramID, "Sorry, something went wrong."); |
|
|
@ -33,30 +38,32 @@ function informContacts(telegramID, doneCallback=()=>{}){ |
|
|
|
User.findOne({ |
|
|
|
where: { |
|
|
|
telegram: telegramID, |
|
|
|
} |
|
|
|
}).then(user => { |
|
|
|
}, |
|
|
|
}).then((user) => { |
|
|
|
if (user) { |
|
|
|
const userRowID = user.id; |
|
|
|
Contact.findAll({ |
|
|
|
where: { |
|
|
|
[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({ |
|
|
|
where: { |
|
|
|
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) { |
|
|
|