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'
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 π.