mirror of
https://github.com/hempyhemp/hh-auto-reply.git
synced 2026-06-08 18:04:57 +00:00
🚀 feat(bot-commands): Добавлена обработка статуса "откликаюсь на вакансии" при команде /apply.
All checks were successful
Deploy / deploy (push) Successful in 46s
All checks were successful
Deploy / deploy (push) Successful in 46s
This commit is contained in:
@@ -127,6 +127,12 @@ export function registerHHCommands() {
|
||||
|
||||
const chatId = msg.chat.id
|
||||
const state = getState(chatId)
|
||||
|
||||
if (state.isApplying) {
|
||||
await bot.sendMessage(chatId, '⏳ Подождите, идут отклики на вакансии...')
|
||||
return
|
||||
}
|
||||
|
||||
const isAwaiting = state.awaitingEmail || state.awaitingQuery || state.awaitingMax || state.awaitingPrompt
|
||||
const isMenuButton = Object.values(BTN).includes(msg.text as typeof BTN[keyof typeof BTN])
|
||||
|
||||
|
||||
@@ -1,18 +1,24 @@
|
||||
import bot from '@bot'
|
||||
import prisma from '@prisma'
|
||||
import { applyToJobs } from '../scraper.js'
|
||||
import { createStatusReporter, escapeHtml } from '../ui.js'
|
||||
import { APPLYING_REPLY_KEYBOARD, MAIN_REPLY_KEYBOARD, createStatusReporter, escapeHtml } from '../ui.js'
|
||||
import { getState } from '../state.js'
|
||||
|
||||
export async function handleApply(chatId: number): Promise<void> {
|
||||
const settings = await prisma.settings.findUnique({ where: { telegramId: chatId } })
|
||||
if (!settings)
|
||||
return
|
||||
|
||||
const state = getState(chatId)
|
||||
state.isApplying = true
|
||||
|
||||
const reporter = createStatusReporter(chatId)
|
||||
await reporter.keep(`🔄 Ищу вакансии по запросу "${settings.searchQuery}"...`)
|
||||
await bot.sendMessage(chatId, `🔄 Ищу вакансии по запросу "${settings.searchQuery}"...`, { reply_markup: APPLYING_REPLY_KEYBOARD })
|
||||
|
||||
applyToJobs({ query: settings.searchQuery, maxApplies: settings.maxApplies }, { chatId, reporter })
|
||||
.then(async (result) => {
|
||||
state.isApplying = false
|
||||
await bot.sendMessage(chatId, '✅ Готово', { reply_markup: MAIN_REPLY_KEYBOARD })
|
||||
if (result.error) {
|
||||
await bot.sendMessage(chatId, `❌ ${result.error}`)
|
||||
return
|
||||
@@ -46,4 +52,8 @@ export async function handleApply(chatId: number): Promise<void> {
|
||||
})
|
||||
}
|
||||
})
|
||||
.catch(async () => {
|
||||
state.isApplying = false
|
||||
await bot.sendMessage(chatId, '❌ Ошибка при откликах', { reply_markup: MAIN_REPLY_KEYBOARD })
|
||||
})
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import type { ScheduledTask } from 'node-cron'
|
||||
|
||||
export interface UserState {
|
||||
autoCron: ScheduledTask | null
|
||||
isApplying: boolean
|
||||
awaitingEmail: boolean
|
||||
awaitingQuery: boolean
|
||||
awaitingMax: boolean
|
||||
@@ -17,6 +18,7 @@ export interface UserState {
|
||||
function makeUserState(): UserState {
|
||||
return {
|
||||
autoCron: null,
|
||||
isApplying: false,
|
||||
awaitingEmail: false,
|
||||
awaitingQuery: false,
|
||||
awaitingMax: false,
|
||||
|
||||
@@ -52,6 +52,12 @@ export const INFO_REPLY_KEYBOARD = {
|
||||
persistent: true,
|
||||
}
|
||||
|
||||
export const APPLYING_REPLY_KEYBOARD = {
|
||||
keyboard: [[{ text: '⏳ Откликаюсь на вакансии...' }]],
|
||||
resize_keyboard: true,
|
||||
persistent: true,
|
||||
}
|
||||
|
||||
export const BACK_MARKUP = {
|
||||
inline_keyboard: [[{ text: '◀️ Назад', callback_data: 'hh_back' }]],
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user