Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(condo): DOMA-11012 telegram auth #5783

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

vovaaxeapolla
Copy link
Contributor

No description provided.

@vovaaxeapolla vovaaxeapolla force-pushed the feat/condo/DOMA-11012/telegram-auth branch from 22deb7c to 3b31396 Compare February 11, 2025 08:36

init () {
if (this.#bot) {
this.#bot.onText(/\/start (.+)/, this.#handleStart.bind(this))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth processing a simple /start command?

Comment on lines 44 to 45
const startData = await redisClient.get(`${TELEGRAM_AUTH_REDIS_START}${startKey}`)
await redisClient.del(`${TELEGRAM_AUTH_REDIS_START}${startKey}`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that forming a query in Redis based on user input without additional checks is not the best idea


if (!chatId || !contact) return

const { phone_number: phoneNumber, first_name: firstName, user_id: userId } = contact
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about lastname?

const redisClient = getRedisClient()

class TelegramAuthRoutes {
#telegramAuthBot = new TelegramAuthBotController()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you going to run the bot in every pod for condo-app? Will this work well?
I thought it was supposed to be a separate pod for a bot



function getUserType (req) {
let userType = RESIDENT
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why resident by default?

return res.status(400).json({ status: 'error', message: 'Missing uniqueKey' })
}

const token = await redisClient.get(`${TELEGRAM_AUTH_REDIS_TOKEN}${uniqueKey}`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is auth status, not token

return res.status(400).json({ status: TELEGRAM_AUTH_STATUS_ERROR, message: 'uniqueKey is expired' })
}

if (token === TELEGRAM_AUTH_STATUS_PENDING) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you comparing the token with auth status?

const startLink = `${TELEGRAM_AUTH_BOT_URL}?start=${startKey}`

await Promise.all([
redisClient.set(`${TELEGRAM_AUTH_REDIS_START}${startKey}`, JSON.stringify({ uniqueKey, userType }), 'EX', 300),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe make a small utility for generating a key, so as not to generate it manually each time?

} = require('@condo/domains/user/utils/serverSchema')

const dv = 1
const sender = { dv, fingerprint: 'user-external-identity-router' }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's worth adding information to the fingerprint that this is an integration with Telegram?

Comment on lines +62 to +64
if (existed) {
return await linkUser(context, existed, userInfo)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set isPhoneVerified: true for user?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants