Skip to content

Commit

Permalink
chore: add telegraf, puregram, node-telegram-bot-api usage examples
Browse files Browse the repository at this point in the history
  • Loading branch information
kravetsone committed May 18, 2024
1 parent ff2d610 commit 38c35c9
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 4 deletions.
83 changes: 80 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ const keyboard = new Keyboard()

## Usage with Frameworks

### Send via GramIO
### Send via [GramIO](https://gramio.dev/)

```ts
import { Bot, Keyboard } from "gramio"; // import from GramIO package!!

const bot = new Bot(process.env.TOKEN);
const bot = new Bot(process.env.TOKEN as string);

const data = ["Apple", "Realme", "Tesla", "Xiaomi"];

Expand All @@ -60,7 +60,7 @@ bot.on("message", (ctx) => {
import { Keyboard } from "@gramio/keyboards";
import { Bot } from "grammy";

const bot = new Bot(process.env.TOKEN);
const bot = new Bot(process.env.TOKEN as string);

const data = ["Apple", "Realme", "Tesla", "Xiaomi"];

Expand All @@ -78,6 +78,83 @@ bot.on("message", (ctx) => {
bot.start();
```

### Send via [Telegraf](https://github.com/telegraf/telegraf)

> [!WARNING]
> The `node-telegram-bot-api` does not support the latest version of Bot API
```ts
import { Keyboard } from "@gramio/keyboards";
import { Telegraf } from "telegraf";

const bot = new Telegraf(process.env.TOKEN as string);

const data = ["Apple", "Realme", "Tesla", "Xiaomi"];

bot.on("message", (ctx) => {
return ctx.reply("test", {
reply_markup: new Keyboard()
.columns(1)
.text("simple keyboard")
.add(...data.map((x) => Keyboard.text(x)))
.filter(({ button }) => button.text !== "Tesla")
.build(),
});
});

bot.launch();
```

### Send via [puregram](https://puregram.cool/)

```ts
import { Telegram } from "puregram";
import { Keyboard } from "@gramio/keyboards";

const bot = new Telegram({
token: process.env.TOKEN as string,
});

const data = ["Apple", "Realme", "Tesla", "Xiaomi"];

bot.on("message", (ctx) => {
return ctx.reply("test", {
reply_markup: new Keyboard()
.columns(1)
.text("simple keyboard")
.add(...data.map((x) => Keyboard.text(x)))
.filter(({ button }) => button.text !== "Tesla"),
});
});

bot.updates.startPolling();
```

### Send via [node-telegram-bot-api](https://www.npmjs.com/package/node-telegram-bot-api)

> [!WARNING]
> The `node-telegram-bot-api` does not support the latest version of Bot API and the types are badly written, so the types may not match
```ts
import { Keyboard } from "@gramio/keyboards";
import TelegramBot from "node-telegram-bot-api";

const bot = new TelegramBot(process.env.TOKEN as string, { polling: true });

const data = ["Apple", "Realme", "Tesla", "Xiaomi"];

bot.on("message", (msg) => {
return bot.sendMessage(msg.chat.id, "test", {
reply_markup: new Keyboard()
.columns(1)
.text("simple keyboard")
.add(...data.map((x) => Keyboard.text(x)))
.filter(({ button }) => button.text !== "Tesla")
.build(),
});
});
```

#### Result

```json
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@gramio/keyboards",
"version": "0.3.1",
"version": "0.3.2",
"description": "Framework-agnostic Telegram bot keyboard builder with many cool features!",
"main": "dist/index.js",
"type": "commonjs",
Expand Down

0 comments on commit 38c35c9

Please sign in to comment.