PrantaDas / TelegramBot-Scaffold

A simple telegraf Bot boilerplate built on top of Telegraf.Js to make the way of making a bot simpler.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Telegram Bot Scaffold 🐳

A template for a telegram bot build on top of Telegraf.Js.
.
β”œβ”€β”€ config
|    β”œβ”€β”€ dev.env
|    └── prod.env
β”œβ”€β”€ src
|   β”œβ”€β”€ telegram
|   |   β”œβ”€β”€ wizards
|   |   |   β”œβ”€β”€ command.ts
|   |   |   └── demo.wizard.ts
|   |   β”œβ”€β”€ actions.ts
|   |   β”œβ”€β”€ bot.ts
|   |   β”œβ”€β”€ menu.ts
|   |   β”œβ”€β”€ types.ts
|   |   └── utils.ts
|   └── index.ts
|
β”œβ”€β”€ .gitignore
β”œβ”€β”€ Feedbacks.md
β”œβ”€β”€ License
β”œβ”€β”€ package.json
β”œβ”€β”€ README.md
β”œβ”€β”€ tsconfig.json
└── yarn.lock

Enviroment Variables

BOT_TOKEN = 'your_bot_token'
MODE = 'dev'

Installation

Clone the project

$ git clone https://github.com/PrantaDas/TelegramBot-Scaffold.git

Go to the project directory

$ cd TelegramBot-Scaffold

Install dependencies

$ yarn or npm install or pnpm install

Start the bot

$ yarn start-dev or npm run start-dev or pnpm start-dev

Usage/Examples:

Include all the markup menus that will appear on telegram

export default function (type?: string): InlineKeyboardMarkup {

    // include all the availabe commands here before starting
    const menu: UserCommand[] = [...defaultMenu];

}

Include the bot actions inside the action function.

export default function actions(bot: Telegraf<MyContext>, userData?: UserData) {
    // include all the bot actions here
    const botActions: Actions[] = [
        {
            action: 'sniperBot',
            name: 'Buy or Sell',
            sceneName: 'buy-sell',
            enterScene: true,
            callback: async () => console.log('entered the scene')
        }
    ];

}

Create custom scene

import { Scenes } from "telegraf";
import { message } from 'telegraf/filters';
import menu from "../menu";

const defaultWizard = new Scenes.WizardScene(
    "default-wizard",
    async (ctx) => {
        await ctx.replyWithHTML(
            '<b>Available Options</b>', {
            reply_markup: menu()
        }
        );
    },
    async (ctx) => {
        console.log(ctx);
        await ctx.scene.leave();
    },
);

defaultWizard.on(message('text'), async (ctx) => {
    console.log(ctx);
});

export default defaultWizard;

Then include the wizard to the state middleware

const stage = new Scenes.Stage<MyContext>([buyWizard,other_middleware]);

Set the bot commands in bot.ts file before starting

const myCommands: Command[] = [your_commands];

// setting the bot commands
bot.telegram.setMyCommands(myCommands);

Under Development πŸ“.

About

A simple telegraf Bot boilerplate built on top of Telegraf.Js to make the way of making a bot simpler.

License:MIT License


Languages

Language:TypeScript 100.0%