mirror of
https://github.com/hempyhemp/hh-auto-reply.git
synced 2026-06-08 18:04:57 +00:00
🌟 feat(file/topic): Добавление обработчиков входа по email и телефону.
All checks were successful
Deploy / deploy (push) Successful in 48s
All checks were successful
Deploy / deploy (push) Successful in 48s
This commit is contained in:
@@ -2,7 +2,7 @@ import bot from '@bot'
|
||||
import prisma from '@prisma'
|
||||
import { debugFunc } from '@/hh/handlers/debug'
|
||||
import { handleApply } from './handlers/apply.js'
|
||||
import { doLogin, handleLogin } from './handlers/auth.js'
|
||||
import { doLogin, handleLogin, handleLoginByEmail, handleLoginByPhone } from './handlers/auth.js'
|
||||
import { handleSkipped, handleStatus } from './handlers/info.js'
|
||||
import { finishOnboarding, showPromptStep, showQueryStep, showResumeInfo } from './handlers/onboarding.js'
|
||||
import { handleMyResume, handleResumeList, handleResumePick } from './handlers/resume.js'
|
||||
@@ -39,6 +39,18 @@ const CALLBACK_HANDLERS: Record<string, CallbackHandler> = {
|
||||
await bot.deleteMessage(chatId, messageId).catch(() => {})
|
||||
await handleLogin(chatId)
|
||||
},
|
||||
hh_login_method_email: async (chatId, messageId) => {
|
||||
const state = getState(chatId)
|
||||
state.loginMethodMsgId = null
|
||||
await bot.deleteMessage(chatId, messageId).catch(() => {})
|
||||
await handleLoginByEmail(chatId)
|
||||
},
|
||||
hh_login_method_phone: async (chatId, messageId) => {
|
||||
const state = getState(chatId)
|
||||
state.loginMethodMsgId = null
|
||||
await bot.deleteMessage(chatId, messageId).catch(() => {})
|
||||
await handleLoginByPhone(chatId)
|
||||
},
|
||||
hh_login_use_current: async (chatId, messageId) => {
|
||||
const state = getState(chatId)
|
||||
state.awaitingEmail = false
|
||||
@@ -109,6 +121,7 @@ const CALLBACK_HANDLERS: Record<string, CallbackHandler> = {
|
||||
async function clearAwaitingState(chatId: number): Promise<void> {
|
||||
const state = getState(chatId)
|
||||
const msgIds = [
|
||||
state.loginMethodMsgId,
|
||||
state.loginPromptMessageId,
|
||||
state.queryPromptMessageId,
|
||||
state.maxPromptMessageId,
|
||||
@@ -116,11 +129,13 @@ async function clearAwaitingState(chatId: number): Promise<void> {
|
||||
state.onboardingMsgId,
|
||||
]
|
||||
state.awaitingEmail = false
|
||||
state.awaitingPhone = false
|
||||
state.awaitingQuery = false
|
||||
state.awaitingMax = false
|
||||
state.awaitingPrompt = false
|
||||
state.onboardingStep = null
|
||||
state.onboardingMsgId = null
|
||||
state.loginMethodMsgId = null
|
||||
state.loginPromptMessageId = null
|
||||
state.queryPromptMessageId = null
|
||||
state.maxPromptMessageId = null
|
||||
@@ -170,7 +185,7 @@ export function registerHHCommands() {
|
||||
return
|
||||
}
|
||||
|
||||
const isAwaiting = state.awaitingEmail || state.awaitingQuery || state.awaitingMax || state.awaitingPrompt || state.onboardingStep !== null
|
||||
const isAwaiting = state.awaitingEmail || state.awaitingPhone || state.awaitingQuery || state.awaitingMax || state.awaitingPrompt || state.onboardingStep !== null
|
||||
const isMenuButton = Object.values(BTN).includes(msg.text as typeof BTN[keyof typeof BTN])
|
||||
|
||||
if (isMenuButton && isAwaiting) {
|
||||
|
||||
@@ -56,6 +56,19 @@ export async function doLogin(chatId: number, email: string): Promise<void> {
|
||||
}
|
||||
|
||||
export async function handleLogin(chatId: number): Promise<void> {
|
||||
const state = getState(chatId)
|
||||
const msg = await bot.sendMessage(chatId, '🔐 Выбери способ входа:', {
|
||||
reply_markup: {
|
||||
inline_keyboard: [[
|
||||
{ text: '📧 Email', callback_data: 'hh_login_method_email' },
|
||||
{ text: '📱 Телефон', callback_data: 'hh_login_method_phone' },
|
||||
]],
|
||||
},
|
||||
})
|
||||
state.loginMethodMsgId = msg.message_id
|
||||
}
|
||||
|
||||
export async function handleLoginByEmail(chatId: number): Promise<void> {
|
||||
const state = getState(chatId)
|
||||
const user = await prisma.user.findUnique({ where: { telegramId: chatId } })
|
||||
state.awaitingEmail = true
|
||||
@@ -79,3 +92,7 @@ export async function handleLogin(chatId: number): Promise<void> {
|
||||
state.loginPromptMessageId = prompt.message_id
|
||||
}
|
||||
}
|
||||
|
||||
export async function handleLoginByPhone(chatId: number): Promise<void> {
|
||||
await bot.sendMessage(chatId, '📱 Авторизация по телефону — скоро будет доступна')
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import bot from '@bot'
|
||||
import { startOnboarding } from '@/hh/handlers/onboarding'
|
||||
|
||||
export async function debugFunc(chatId: number): Promise<void> {
|
||||
await bot.sendMessage(chatId, '🌍 Регион — скоро будет доступно')
|
||||
await startOnboarding(chatId)
|
||||
// await startOnboarding(chatId)
|
||||
}
|
||||
|
||||
@@ -5,10 +5,12 @@ export interface UserState {
|
||||
autoCron: ScheduledTask | null
|
||||
isApplying: boolean
|
||||
awaitingEmail: boolean
|
||||
awaitingPhone: boolean
|
||||
awaitingQuery: boolean
|
||||
awaitingMax: boolean
|
||||
awaitingPrompt: boolean
|
||||
pendingResumes: ResumeListItem[]
|
||||
loginMethodMsgId: number | null
|
||||
loginPromptMessageId: number | null
|
||||
queryPromptMessageId: number | null
|
||||
maxPromptMessageId: number | null
|
||||
@@ -23,10 +25,12 @@ function makeUserState(): UserState {
|
||||
autoCron: null,
|
||||
isApplying: false,
|
||||
awaitingEmail: false,
|
||||
awaitingPhone: false,
|
||||
awaitingQuery: false,
|
||||
awaitingMax: false,
|
||||
awaitingPrompt: false,
|
||||
pendingResumes: [],
|
||||
loginMethodMsgId: null,
|
||||
loginPromptMessageId: null,
|
||||
queryPromptMessageId: null,
|
||||
maxPromptMessageId: null,
|
||||
|
||||
Reference in New Issue
Block a user