l want sample telegram bot code with JavaScript
- User
l want sample telegram bot code with JavaScript
- Assistant
Sure, here's a sample Telegram bot code using JavaScript:
const TelegramBot = require('node-telegram-bot-api'); const token = 'YOUR_TELEGRAM_BOT_TOKEN'; const bot = new TelegramBot(token, {polling: true}); bot.onText(/\/start/, (msg) => { const chatId = msg.chat.id; bot.sendMessage(chatId, 'Welcome to My Telegram Bot!'); }); bot.onText(/\/hello/, (msg) => { const chatId = msg.chat.id; bot.sendMessage(chatId, 'Hello, how can I help you?'); }); bot.onText(/\/echo (.+)/, (msg, match) => { const chatId = msg.chat.id; const echoMessage = match[1]; bot.sendMessage(chatId, echoMessage); });Make sure to replace
'YOUR_TELEGRAM_BOT_TOKEN'with your own bot token, which you can obtain by creating a new bot on Telegram's BotFather platform.This code sets up a Telegram bot that responds to three commands:
/start,/hello, and/echo./startand/hellocommands send a welcome message, while the/echocommand echoes back any text that comes after it.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.