Giter Club home page Giter Club logo

Comments (3)

mildsunrise avatar mildsunrise commented on June 4, 2024 1

Sorry for not getting in touch earlier! Botgram already supports middleware through the bot.all() function. I think middleware is a simpler way to add plugin-like functionality, it's what i.e. Telegraf and Express do :)

As an example, here's an hypothetical middleware:

// Middleware to apologize to users when the bot is down
function apologizeIfQueued(msg, reply, next) {
    if (!msg.queued) return next()
    const { context, chat } = msg

    // If it's the first time we see this chat, decide if apology is needed
    if (context.apologize === undefined) {
        const downtime = Date.now() - msg.date.getTime()
        context.apologize = (downtime > 60 * 1000)
        if (context.apologize) {
            reply.text("🤖 Sorry! I was having problems, but I'm back online now.")
            console.error("Apologizing to %s %s (%s) for %ss downtime",
                chat.type, chat.id, chat.name, Math.ceil(downtime/1000))
        }
    }

    // If apology was not deemed necessary, process messages
    if (!context.apologize) return next()
}
module.exports = apologizeIfQueued

And here's how you'd use it in a project:

// ...
const apologizeIfQueued = require("apologize-if-queued")
const bot = botgram("TOKEN")
bot.context()
bot.all(apologizeIfQueued)
// ...

But unlike Telegraf, I don't have the time or resources to maintain various middlewares for Botgram, at least not ATM. 😔

from botgram.

mildsunrise avatar mildsunrise commented on June 4, 2024 1

Great! :) Here's the link to the documentation on middleware:
https://github.com/botgram/botgram/blob/master/docs/handlers.md#miscellaneous

from botgram.

mehrancodes avatar mehrancodes commented on June 4, 2024

Great, I would like to work on it if I have tike for that.
Thank you!

from botgram.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.