Skip to content

Commit ecb00ff

Browse files
authored
chore: some updates (#220)
1 parent b5598fa commit ecb00ff

2 files changed

Lines changed: 23 additions & 23 deletions

File tree

apps/core-telegram/server/services/telegram/atrium-bot.ts

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { Context } from 'grammy'
33
import { createId } from '@paralleldrive/cuid2'
44
import { db } from '@roll-stack/database'
55
import { Bot } from 'grammy'
6-
import { generateAccessCode, getBotToken, getFileDownloadUrl, requestContactPhone, uploadToStorage } from './common'
6+
import { generateAccessCode, getAndUploadUserPhoto, getBotToken, requestContactPhone } from './common'
77

88
const logger = useLogger('telegram:atrium-bot')
99
const { telegram } = useRuntimeConfig()
@@ -83,7 +83,7 @@ async function handleContact(ctx: Context) {
8383
return
8484
}
8585

86-
const botToken = await getBotToken(telegram.wasabiBotId)
86+
const botToken = await getBotToken(telegram.atriumBotId)
8787
if (!botToken) {
8888
return null
8989
}
@@ -151,27 +151,6 @@ async function handleMessage(ctx: Context) {
151151
// ctx.reply('Сообщение передано в службу поддержки.')
152152
}
153153

154-
async function getAndUploadUserPhoto(ctx: Context, botToken: string): Promise<string | null> {
155-
if (!ctx.message?.from.id) {
156-
return null
157-
}
158-
159-
const photos = await ctx.api.getUserProfilePhotos(ctx.message.from.id)
160-
logger.log(`User ${ctx.message.from.id} have ${photos.total_count} photos:`, JSON.stringify(photos.photos))
161-
162-
const userPhoto = photos.photos[0]?.pop()
163-
if (userPhoto?.file_id) {
164-
const fileDownloadUrl = await getFileDownloadUrl({ ctx, fileId: userPhoto.file_id, botToken, isLocalBot: false })
165-
if (fileDownloadUrl) {
166-
const uploaded = await uploadToStorage(fileDownloadUrl, userPhoto.file_id)
167-
168-
return uploaded?.fileUrl ?? null
169-
}
170-
}
171-
172-
return null
173-
}
174-
175154
async function findOrCreateAtriumUser(data: { phone: string, user: { name: string, surname: string | undefined }, ctx: Context, botToken: string }): Promise<User> {
176155
const userInDB = await db.user.findByPhone(data.phone)
177156
if (!userInDB) {
@@ -189,6 +168,8 @@ async function findOrCreateAtriumUser(data: { phone: string, user: { name: strin
189168
name: data.user.name,
190169
surname: data.user.surname,
191170
avatarUrl: avatarUrl ?? defaultAvatarUrl,
171+
gender: 'female',
172+
caption: 'Новый участник команды',
192173
})
193174
logger.log('New user', createdUser)
194175

apps/core-telegram/server/services/telegram/common.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,22 @@ export async function getFileDownloadUrl(data: { ctx: Context, fileId: string, b
112112
return null
113113
}
114114
}
115+
116+
export async function getAndUploadUserPhoto(ctx: Context, botToken: string): Promise<string | null> {
117+
if (!ctx.message?.from.id) {
118+
return null
119+
}
120+
121+
const photos = await ctx.api.getUserProfilePhotos(ctx.message.from.id)
122+
const userPhoto = photos.photos[0]?.pop()
123+
if (userPhoto?.file_id) {
124+
const fileDownloadUrl = await getFileDownloadUrl({ ctx, fileId: userPhoto.file_id, botToken, isLocalBot: false })
125+
if (fileDownloadUrl) {
126+
const uploaded = await uploadToStorage(fileDownloadUrl, userPhoto.file_id)
127+
128+
return uploaded?.fileUrl ?? null
129+
}
130+
}
131+
132+
return null
133+
}

0 commit comments

Comments
 (0)