|
|
@ -1,10 +1,7 @@ |
|
|
|
import { Request, Response } from "express"; |
|
|
|
import { Op } from "sequelize"; |
|
|
|
import { Contact } from "../db/models/Contact"; |
|
|
|
import { User } from "../db/models/User"; |
|
|
|
import { getUserByRowID, getUserByTelegramID } from "../db/models/User.helper"; |
|
|
|
import { getUserByTelegramID } from "../db/models/User.helper"; |
|
|
|
import { strings_en } from "../strings"; |
|
|
|
import { sendTelegramMessage } from "../telegram"; |
|
|
|
import { informContacts, sendTelegramMessage } from "../telegram"; |
|
|
|
import { TelegramID } from "../types"; |
|
|
|
|
|
|
|
interface TelegramWebhookRequest extends Request { |
|
|
@ -50,26 +47,6 @@ export async function TelegramWebhookRoute( |
|
|
|
res.send(); |
|
|
|
} |
|
|
|
|
|
|
|
async function informContacts(telegramID: TelegramID): Promise<void> { |
|
|
|
const user = await getUserByTelegramID(telegramID); |
|
|
|
if (!user) throw new Error("User not found"); |
|
|
|
const contacts = await Contact.findAll({ |
|
|
|
where: { |
|
|
|
[Op.or]: [{ user: user.id }, { with: user.id }], |
|
|
|
}, |
|
|
|
}); |
|
|
|
|
|
|
|
contacts.forEach(async (contact) => { |
|
|
|
const otherPersonID = contact.user == user.id ? contact.with : contact.user; |
|
|
|
const otherUser = await getUserByRowID(otherPersonID); |
|
|
|
if (!otherUser) throw new Error("Other user does not exist"); |
|
|
|
await sendTelegramMessage( |
|
|
|
otherUser.telegram, |
|
|
|
strings_en.telegram_inform_infect |
|
|
|
); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
async function userInfected(telegramID: TelegramID): Promise<void> { |
|
|
|
const user = await getUserByTelegramID(telegramID); |
|
|
|
if (!user) throw new Error("User not found"); |
|
|
|