# telegraf-session-firebase

> Firebase powered session middleware for Telegraf

Latest version **0.1.0** (published 2018-08-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install telegraf-session-firebase
pnpm add telegraf-session-firebase
yarn add telegraf-session-firebase
bun add telegraf-session-firebase
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2018-08-23 |
| First published | 2017-09-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=6.2.1 |
| Dependencies | 0 |
| Unpacked size | 4.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 14 |
| Author | Vitaly Domnikov |
| Maintainers | dotcypress |
| Keywords | telegram, telegraf, session, middleware, firebase |

## Links

- npm: https://www.npmjs.com/package/telegraf-session-firebase
- Repository: https://github.com/telegraf/telegraf-session-firebase
- Homepage: https://github.com/telegraf/telegraf-session-firebase#readme
- Issues: https://github.com/telegraf/telegraf-session-firebase/issues
- npm.io page: https://npm.io/package/telegraf-session-firebase

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 0.1.0 (latest) — 2018-08-23
- 0.0.1 — 2017-09-11
- 0.0.0 — 2017-09-11

## README

[![Build Status](https://img.shields.io/travis/telegraf/telegraf-session-firebase.svg?branch=master&style=flat-square)](https://travis-ci.org/telegraf/telegraf-session-firebase)
[![NPM Version](https://img.shields.io/npm/v/telegraf-session-firebase.svg?style=flat-square)](https://www.npmjs.com/package/telegraf-session-firebase)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](http://standardjs.com/)

# Firebase session for Telegraf

[Firebase](https://firebase.google.com/docs/admin/setup) powered session middleware for [Telegraf](https://github.com/telegraf/telegraf).

## Installation

```js
$ npm install telegraf-session-firebase
```

## Example

```js
const Telegraf = require('telegraf')
const firebaseSession = require('telegraf-session-firebase')
const admin = require('firebase-admin')

const serviceAccount = require('path/to/serviceAccountKey.json')
admin.initializeApp({
  credential: admin.credential.cert(serviceAccount),
  databaseURL: 'https://<DATABASE_NAME>.firebaseio.com'
})
const database = admin.database()

const bot = new Telegraf(process.env.BOT_TOKEN)
bot.use(firebaseSession(database.ref('sessions')))
bot.on('text', (ctx, next) => {
  ctx.session.counter = ctx.session.counter || 0
  ctx.session.counter++
  return next()
})
bot.hears('/stats', ({ reply, session, from }) => reply(`${session.counter} messages from ${from.username}`))
bot.startPolling()

```

## API

### Options

* `property`: context property name (default: `session`)
* `getSessionKey`: session key resolver function (default: `(ctx) => any`)

Default implementation of `getSessionKey`:

```js
function getSessionKey(ctx) {
  if (!ctx.from || !ctx.chat) {
    return
  }
  return `${ctx.from.id}/${ctx.chat.id}`
}
```

### Destroying a session

To destroy a session simply set it to `null`.

```js
bot.on('text', (ctx) => {
  ctx.session = null
})

```

---
_Source: https://npm.io/package/telegraf-session-firebase · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
