Opengram
Makes bots development simple
Easy to Use
Was designed up to be easily installed and used to get your first bot up quickly.
Focus on What Matters
Lets you focus on your code, and we'll do the chores.
Flexible
Can be extendable by plugins, have mechanisms for flexible decomposition
Quickstart
- Locally
- Try now
Installing opengram
- Yarn
- NPM
- pnpm
yarn add opengram
npm i opengram
pnpm add opengram
Create new file named index.js
, copy & paste this code:
const { Opengram, isTelegramError } = require('opengram')
const bot = new Opengram(process.env.BOT_TOKEN) // <-- put your bot token here (https://t.me/BotFather)
// Register handlers
bot.start((ctx) => ctx.reply('Welcome'))
bot.help((ctx) => ctx.reply('Send me a sticker'))
bot.on('sticker', (ctx) => ctx.reply('👍'))
bot.hears('hi', (ctx) => ctx.reply('Hey there'))
bot.catch((error, ctx) => {
if (isTelegramError(error)) {
console.error(error, ctx) // Print error and context
return
}
throw error
})
bot.launch() // Start bot using polling
// Enable graceful stop
process.once('SIGINT', () => bot.stop())
process.once('SIGTERM', () => bot.stop())
Run bot with command line
node index.js
* Live examples provided by replit.