1.0.0 • Published 3 years ago

@botocrat/express v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

Botocrat Express

This is express middleware creator to accept incoming updates from Telegram to pass '@botocrat/core' bot.

ParameterDescriptionDefaultRequired
botBot handler (@botocrat/core)Required if no 'onUpdate'
onUpdateUpdate handlerRequired if no 'bot'
clientTelegram bot client (@botocrat/telegram)Required
urlThe url that telegram will send requestsRequired
allowed_updatesArray of TTUpdateType["message"]Optional
drop_pending_updatesOptional

Installation

npm i express @botocrat/express --save

Example Code

// bot.js
import Botocrat from "@botocrat/core"

export default new Botocrat()
  .on('message', (req, res) => 
    res.reply("This is a reply"))
// client.js
import createClient from "@botocrat/telegram"

export default createClient({ debug: true, token: BOT_TOKEN })

Creating Express middleware and launching server

// index.js
import createMiddleware from "@botocrat/express"
import express from "express"
import bot from "./bot.js"
import client from "./client.js"

const botMiddleware = createMiddleware({
  bot, client,
  url: "http://botocrat.myfancybotdomain.com/" + BOT_TOKEN,
})

express()
  .use("/" + BOT_TOKEN, botMiddleware) // plug middleware
  .listen(80)