Redis session middleware for Telegraf
Redis powered session middleware for Telegraf.
Installation
$ npm install telegraf-session-redis
Example
const Telegraf = const RedisSession = const bot = processenvBOT_TOKEN const session = store: host: processenvTELEGRAM_SESSION_HOST || '127.0.0.1' port: processenvTELEGRAM_SESSION_PORT || 6379 bot bot bot
When you have stored the session key beforehand, you can access a session without having access to a context object. This is useful when you perform OAUTH or something similar, when a REDIRECT_URI is called on your bot server.
const redisSession = // Retrieve session state by session keyredisSession // Save session stateredisSession
API
Options
store
:host
: Redis host (default: 127.0.0.1)port
: Redis port (default: 6379)path
: Unix socket stringurl
: Redis url...
: Other redis connection options
property
: context property name (default:session
)ttl
: session ttl in seconds (default: forever)getSessionKey
: session key resolver function(ctx) => any
)
Default implementation of getSessionKey
:
{ if !ctxfrom || !ctxchat return return `:`}
Destroying a session
To destroy a session simply set it to null
.
bot