# 11ff

> [![Version](https://img.shields.io/npm/v/cfworker-middware-telegraf.svg?style=flat-square)](https://www.npmjs.com/package/cfworker-middware-telegraf)

Latest version **1.1.7** (published 2021-03-02) · 0 weekly downloads

## Install

```sh
npm install 11ff
pnpm add 11ff
yarn add 11ff
bun add 11ff
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.7 |
| Published | 2021-03-02 |
| First published | 2021-02-27 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 17.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | vsamaru |

## Links

- npm: https://www.npmjs.com/package/11ff
- npm.io page: https://npm.io/package/11ff

## Recent versions

- 1.1.7 (latest) — 2021-03-02
- 1.1.6 — 2021-03-02
- 1.1.5 — 2021-03-02
- 1.1.4 — 2021-03-02
- 1.1.3 — 2021-03-02
- 1.1.2 — 2021-03-02
- 1.1.1 — 2021-03-02
- 1.0.9 — 2021-03-01
- 1.0.8 — 2021-03-01
- 1.0.7 — 2021-03-01
- 1.0.6 — 2021-03-01
- 1.0.5 — 2021-03-01
- 1.0.4 — 2021-03-01
- 1.0.3 — 2021-02-27
- 1.0.2 — 2021-02-27
- … 1 more at https://npm.io/package/11ff/versions

## README

# cfworker-middware-telegraf

[![Version](https://img.shields.io/npm/v/cfworker-middware-telegraf.svg?style=flat-square)](https://www.npmjs.com/package/cfworker-middware-telegraf)

Make [telegraf](https://github.com/telegraf/telegraf) (a telegram bot framework) useable in [Cloudflare Workers](https://workers.cloudflare.com/).

## Installation

```bash
npm i cfworker-middware-telegraf
```

## Usage

### 1. Write your code

```js
// index.js
const { Telegraf } = require('telegraf');
const { Application, Router } = require('@cfworker/web');
const createTelegrafMiddware = require('cfworker-middware-telegraf');

const bot = new Telegraf('BOT_TOKEN');

// Your code here, but do not `bot.launch()`

const router = new Router();
router.post('/SECRET_PATH', createTelegrafMiddware(bot));
new Application().use(router.middleware).listen();
```

### 2. Webpack your code and upload to cfworker

```js
// webpack.config.js
module.exports = {
  target: 'webworker',
  entry: './index.js',
  mode: 'production',
  node: {
    fs: 'empty',
  },
  module: {
    rules: [
      {
        test: /\.mjs$/,
        include: /node_modules/,
        type: 'javascript/auto',
      },
    ],
  },
  performance: {
    hints: false,
  },
};
```

Just copy and paste built code to cfworker online editor and save.

Or you can use [Wrangler](https://developers.cloudflare.com/workers/tooling/wrangler), an official CLI tool, so you don't need to copy and paste code manually anymore. But I don't like it due to its inexplicable bugs on Win10.

### 3. Set telegram bot webhook

These codes only need to be run once locally.

```js
const Telegraf = require('telegraf');
const bot = new Telegraf('BOT_TOKEN');

// set webhook
bot.telegram.setWebhook('https://your.cfworker.domain/SECRET_PATH');

// delete webhook
// bot.telegram.deleteWebhook();

// get webhook info
// bot.telegram.getWebhookInfo().then(console.log);
```

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