Skip to content

Commit

Permalink
Announce name in chat (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
morozoffnor authored Feb 7, 2024
2 parents 045e529 + 53f9b40 commit 072d49a
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions app/api/phrases.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import express from 'express'
import {tokenChecker} from "./tools/APItokenChecker.mjs";
import {createNewName} from "../database/database.mjs";
import {createNewName, getUserById} from "../database/database.mjs";
import {checkIfNameExists} from "../tools/namesChecker.mjs";
import {bot} from "../main.mjs";
import {config} from "../config.mjs";

let PhrasesRouter = new express.Router()

Expand All @@ -17,8 +19,10 @@ PhrasesRouter.post('/names', express.json({type: 'application/json'}), async (re
title: name.name,
date: Date.now(),
addedBy: name.addedBy
}).then(() => {
}).then(async () => {
res.status(200).send()
const user = await getUserById(name.addedBy)
await sendMessage(`@${user.userName} добавил имя: ${name.name}`)
}).catch(() => {
res.status(500).send('error')
})
Expand All @@ -27,4 +31,8 @@ PhrasesRouter.post('/names', express.json({type: 'application/json'}), async (re

})

async function sendMessage(msg) {
await bot.telegram.sendMessage(config.chatId, msg, {parse_mode: "HTML"})
}

export default PhrasesRouter

0 comments on commit 072d49a

Please sign in to comment.