Skip to content

Latest commit

 

History

History
57 lines (39 loc) · 1.38 KB

readme.md

File metadata and controls

57 lines (39 loc) · 1.38 KB

DynamoDB session for Telegraf

Session store in DynamoDB for telegraf bot framework

Installation

Install telegraf-session-dynamodb with npm

  npm install telegraf-session-dynamodb

Prerequites

  1. Installed @aws-sdk/client-dynamodb
  2. Table for storing sessions, by default is telegraf-sessions. With partition key key Example of table DynamoDB settings

How to use ?

You have to pass in DynamoDb store 2 parameters. region where you created table and name of the table. in example below region: "us-east-1" and table name table: "telegraf-sessions"

import { Telegraf, Markup } from "telegraf";

const { BOT_TOKEN } = process.env;
if (!BOT_TOKEN) throw new Error('"BOT_TOKEN" env var is required!');
const bot = new Telegraf(BOT_TOKEN);

const store = DynamoDbStore<{}>({
  region: "us-east-1",
  table: "telegraf-sessions"
});
bot.use(session(
  {store: store}
));

const keyboard = Markup.inlineKeyboard([
  Markup.button.url("❤️", "http://telegraf.js.org"),
  Markup.button.callback("Delete", "delete"),
]);

bot.start(ctx => ctx.reply("Hello"));
bot.help(ctx => ctx.reply("Help message"));
bot.on("message", ctx => ctx.copyMessage(ctx.message.chat.id, keyboard));
bot.action("delete", ctx => ctx.deleteMessage());

bot.launch();