I’m wondering if there’s a way to programmatically create Telegram bots without going through BotFather. My use case is that when users register on my platform, I want to automatically generate a personal bot for each of them.
I’ve been experimenting with a Node.js Telegram library, but I’m stuck on the phone verification step. Here’s what I’m working with:
const { TelegramAPI } = require('telegram-api-client');
const { Session } = require('telegram-api-client/sessions');
const readline = require('readline');
class BotGenerator {
constructor() {
this.appId = process.env.TELEGRAM_APP_ID;
this.appSecret = process.env.TELEGRAM_APP_SECRET;
this.session = new Session('');
}
async generateBot() {
const telegramAPI = new TelegramAPI(this.session, this.appId, this.appSecret, {
retries: 3,
});
await telegramAPI.connect({
phone: '+1234567890',
verificationCode: async () => {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
return new Promise(resolve => {
rl.question('Please enter verification code: ', answer => {
rl.close();
resolve(answer);
});
});
},
errorHandler: err => {
console.error('Connection failed:', err);
},
});
console.log('Successfully connected to Telegram');
await telegramAPI.sendText('self', 'Bot creation test message');
}
}
The main issue is that verification code prompt - it blocks the automated process. Is there any way to bypass this verification step or use a different approach that doesn’t require manual intervention? I need this to work completely automatically when users sign up.