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

const userId = ctx.message.from.id #1

Open
Selmarion opened this issue Jun 19, 2023 · 1 comment
Open

const userId = ctx.message.from.id #1

Selmarion opened this issue Jun 19, 2023 · 1 comment

Comments

@Selmarion
Copy link

There is no protection (filter) in your project by account telegram ID, so anyone who can access the BOT will be able to use its properties. It is necessary to limit consumption, because otherwise you can incur large financial losses.

Anyone who is included in the list and has his ID is able to work with the bot in the file ('./config/user id.json').


const userIds = JSON.parse(fs.readFileSync('./config/userid.json'));

bot.on(message('voice'), async (ctx) => {
ctx.session ??= INITIAL_SESSION
try {
const userId = ctx.message.from.id
if (userIds.includes(userId)) {
await ctx.reply(code('"Ok, Please wait..."'))
const link = await ctx.telegram.getFileLink(ctx.message.voice.file_id)
const userId = String(ctx.message.from.id)
const oggPath = await ogg.create(link.href, userId)
const mp3Path = await ogg.toMp3(oggPath, userId)

removeFile(oggPath)

const text = await openai.transcription(mp3Path)
  const respose = await openai.chat(text)
  await ctx.reply(code(`Ваш запрос: ${text}`))

  await processTextToChat(ctx, text)
} else {
  await ctx.reply(code('https://link.com/bay_limit_day'))
}

} catch (e) {
console.log(Error while voice message, e.message)
}
})

bot.on(message('text'), async (ctx) => {
ctx.session ??= INITIAL_SESSION
try {
const userId = ctx.message.from.id
if (userIds.includes(userId)) {
await ctx.reply(code('"Ok, Please wait..."'))
await processTextToChat(ctx, ctx.message.text)
} else {
await ctx.reply(code('https://link.com/bay_limit_day'))
}
} catch (e) {
console.log(Error while voice message, e.message)
}
})

@Oleh-Kliapko
Copy link
Owner

Oleh-Kliapko commented Jun 20, 2023

Hello, sorry, but I didnt understand. I created this bot for practice in Node JS. It doesnt work without running on my localhost because I dont want to deploy it on any server like render.com or others. If you want to use it You can download it, register own bot, get keys from Telegram and OpenAI and go ahead

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

No branches or pull requests

2 participants