Botocrat Express
This is express middleware creator to accept incoming updates from Telegram to pass '@botocrat/core' bot.
Parameter | Description | Default | Required |
---|---|---|---|
bot | Bot handler (@botocrat/core ) |
Required if no 'onUpdate' | |
onUpdate | Update handler | Required if no 'bot' | |
client | Telegram bot client (@botocrat/telegram ) |
Required | |
url | The url that telegram will send requests | Required | |
allowed_updates | Array of TTUpdateType | ["message"] |
Optional |
drop_pending_updates | Optional |
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)