telegraf-postgres-session
Advanced tools
Comparing version 1.0.4 to 1.0.5
{ | ||
"name": "telegraf-postgres-session", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "A middleware session for telegraf", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -15,4 +15,4 @@ # PostgreSQL session middleware for Telegraf | ||
```js | ||
const {Telegraf} = require('telegraf'); | ||
const PostgresSession = require('telegraf-postgres-session') | ||
import { Telegraf } from 'telegraf'; | ||
import PostgresSession from 'telegraf-postgres-session'; | ||
@@ -32,6 +32,33 @@ const bot = new Telegraf(process.env.BOT_TOKEN) // Your Bot token here | ||
ctx.reply(ctx.session.counter) | ||
}) | ||
}); | ||
bot.launch() | ||
bot.launch(); | ||
``` | ||
## Example with Typescript | ||
```ts | ||
import { Context, Telegraf } from 'telegraf'; | ||
import PostgresSession from 'telegraf-postgres-session'; | ||
interface SessionContext extends Context { | ||
session: any; | ||
}; | ||
const bot: Telegraf<SessionContext> = new Telegraf(process.env.BOT_TOKEN as string);// Your Bot token here | ||
bot.use((new PostgresSession({ | ||
connectionString: process.env.DATABASE_URL, | ||
ssl: { | ||
rejectUnauthorized: false | ||
} | ||
})).middleware()); | ||
bot.on('message', ctx => { | ||
ctx.session.counter = ctx.session.counter ? ctx.session.counter : 0 | ||
ctx.session.counter++ | ||
ctx.reply(ctx.session.counter) | ||
}); | ||
bot.launch(); | ||
``` | ||
The database connection configuration is described in The [PostgreSQL API](https://node-postgres.com). |
5843
63