AWS S3 session middleware for Telegraf
AWS S3 powered session middleware for Telegraf.
Prerequisites
- You have made your AWS access and secret key available through a provided method, like storing them in the ~/.aws/credentials file or export them into environment variables
- You need to install Node.js with a minimum version of 8.9.0
Installation
$ npm install telegraf-session-s3
Example
const Telegraf = ;const S3Session = ; const bot = processenvBOT_TOKEN; const s3Session = bucket: processenvS3_STATES_BUCKET;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 s3Session = bucket: processenvS3_STATES_BUCKET; // Retrieve session state by session keys3Session ; // Save session states3Session;
API
Options
bucket
: AWS S3 Bucket where session will be storedproperty
: context property name (default:session
)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