Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/prantadas/telegrambot-scaffold

A simple telegraf Bot boilerplate built on top of Telegraf.Js to make the way of making a bot simpler.
https://github.com/prantadas/telegrambot-scaffold

Last synced: 1 day ago
JSON representation

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

Awesome Lists containing this project

README

        

Telegram Bot Scaffold 🐳

```typescript
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
```shell
$ git clone https://github.com/PrantaDas/TelegramBot-Scaffold.git
```
Go to the project directory

```shell
$ cd TelegramBot-Scaffold
```

Install dependencies
```shell
$ yarn or npm install or pnpm install
```

Start the bot
```shell
$ yarn start-dev or npm run start-dev or pnpm start-dev
```

Usage/Examples:

Include all the markup menus that will appear on telegram
```javascript
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.

```javascript
export default function actions(bot: Telegraf, 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

```javascript
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(
'Available Options', {
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

```javascript
const stage = new Scenes.Stage([buyWizard,other_middleware]);
```

Set the bot commands in `bot.ts` file before starting

```javascript
const myCommands: Command[] = [your_commands];

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

> Under Development 📝.