All Projects → Tsuk1ko → cfworker-middware-telegraf

Tsuk1ko / cfworker-middware-telegraf

Licence: MIT License
Make telegraf (a telegram bot framework) useable in Cloudflare Workers

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to cfworker-middware-telegraf

Nayumi
A cute bot of Telegram.
Stars: ✭ 12 (-47.83%)
Mutual labels:  telegram, telegram-bot, telegraf
podsearch bot
Telegram bot that searches Podcast in iTunes store.
Stars: ✭ 28 (+21.74%)
Mutual labels:  telegram, telegram-bot, telegraf
telegram-bot-api-worker
Take an alternate route to Telegram Bot API :)
Stars: ✭ 75 (+226.09%)
Mutual labels:  telegram-bot, cloudflare, cloudflare-workers
Telegraf
Modern Telegram Bot Framework for Node.js
Stars: ✭ 5,178 (+22413.04%)
Mutual labels:  telegram, telegram-bot, telegraf
BooksAndBot
Telegram inline bot. Search for books and share them in a conversation
Stars: ✭ 26 (+13.04%)
Mutual labels:  telegram-bot, telegraf
duanwangzhi
Shorten your links without serves because it based on Cloudflare workers function with minimalist style.Hope u like:)
Stars: ✭ 79 (+243.48%)
Mutual labels:  cloudflare-workers, cfworker
ecasbot
EC AntiSpam bot for the Telegram messenger
Stars: ✭ 17 (-26.09%)
Mutual labels:  telegram, telegram-bot
telegraf-calendar-telegram
Inline calendar for Telegram bots using Telegraf framework
Stars: ✭ 43 (+86.96%)
Mutual labels:  telegram-bot, telegraf
Telegraf-Test
Telegraf Test - Simple Test ToolKit of Telegram Bots
Stars: ✭ 22 (-4.35%)
Mutual labels:  telegram-bot, telegraf
natural
Fastest Framework for NodeJS. Written in pure ES6+
Stars: ✭ 30 (+30.43%)
Mutual labels:  cloudflare, cloudflare-workers
PDF-Bot
A bot for PDF for doing Many Things....
Stars: ✭ 38 (+65.22%)
Mutual labels:  telegram, telegram-bot
quizquickanswer-telegram-game-bot
🎮 Funny quiz game for telegram, play with friends on your group!
Stars: ✭ 15 (-34.78%)
Mutual labels:  telegram-bot, telegraf
miniflare
🔥 Fully-local simulator for Cloudflare Workers
Stars: ✭ 2,811 (+12121.74%)
Mutual labels:  cloudflare, cloudflare-workers
wrangler2
🤠 wrangle your Cloudflare Workers
Stars: ✭ 349 (+1417.39%)
Mutual labels:  cloudflare, cloudflare-workers
workers-jwt
Generate JWTs on Cloudflare Workers using the WebCrypto API
Stars: ✭ 67 (+191.3%)
Mutual labels:  cloudflare, cloudflare-workers
formatbot1
Make instant view easily and fast, from any article on the internet in the best messenger ever Telegram
Stars: ✭ 127 (+452.17%)
Mutual labels:  telegram-bot, telegraf
relay-starter-kit
💥 Monorepo template (seed project) pre-configured with GraphQL API, PostgreSQL, React, Relay, Material UI.
Stars: ✭ 3,513 (+15173.91%)
Mutual labels:  cloudflare, cloudflare-workers
supaflare
URL shortener / redirection service powered by Supabase, Cloudflare Workers, Workers KV and Cloudflare Pages.
Stars: ✭ 51 (+121.74%)
Mutual labels:  cloudflare, cloudflare-workers
Defend-The-Castle
Telegram Bot Game - Defend The Castle
Stars: ✭ 21 (-8.7%)
Mutual labels:  telegram-bot, telegraf
worker-auth-providers
worker-auth-providers is an open-source providers to make authentication easy with workers. Very lightweight script which doesn't need a lot of dependencies. Plug it with any framework or template of workers.
Stars: ✭ 85 (+269.57%)
Mutual labels:  cloudflare, cloudflare-workers

cfworker-middware-telegraf

Version

Make telegraf (a telegram bot framework) useable in Cloudflare Workers.

You can use cfworker-telegraf-template directly.

v2 only support for telegraf@4. If you want to use telegraf@3, please downgrade to v1.

Installation

npm i cfworker-middware-telegraf

Usage

0. Install dependencies

Here we use webpack 5.

npm i @cfworker/web telegraf cfworker-middware-telegraf
npm i -D webpack webpack-cli node-polyfill-webpack-plugin

1. Write your code

// 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

// webpack.config.js
const path = require('path');
const NodePolyfillPlugin = require('node-polyfill-webpack-plugin');

module.exports = {
  entry: path.resolve(__dirname, 'index.js'),
  target: 'webworker',
  output: {
    filename: 'worker.js',
    path: path.resolve(__dirname, 'dist'),
  },
  mode: 'production',
  resolve: {
    fallback: {
      fs: false,
    },
  },
  plugins: [new NodePolyfillPlugin()],
  performance: {
    hints: false,
  },
};
npx webpack -c webpack.config.js

Just copy and paste built code dist/worker.js to cfworker online editor and save.

Or you can use 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.

const { Telegraf } = require('telegraf');
const bot = new Telegraf('BOT_TOKEN');

(async () => {
  // set webhook
  await bot.telegram.setWebhook('https://your.cfworker.domain/SECRET_PATH');

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

  // get webhook info
  await bot.telegram.getWebhookInfo().then(console.log);
})();
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].