npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

adonisjs-grammy

v1.1.0

Published

Use Webhook on Telegram Bot Framework

Downloads

9

Readme

adonisjs-grammy

Introduction

adonisjs-grammy makes it easy for you to integrate AdonisJS with the Telegram Bot Framework -Grammy-, allowing you to implement Webhooks instead of using Long Polling. Learn more here and find out that Grammy doesn't support AdonisJS.

Installation

node ace add adonisjs-grammy

Next steps?

  1. Adjust the env configuration.

  2. Create a tunnel if running on a local machine (recomended: cloudflared or loophole)

  3. Set the webhook to http://<tunneling-addres>/<bot-token> using the following API.

    https://api.telegram.org/bot<bot-token>/setWebhook?url=http://<tunneling-address>/<bot-token>
  4. Continue developing!

Usage

Open start/grammy.ts and do whatever you want, as documented in the official Grammy documentation.

Example

import grammy from 'adonisjs-grammy/services/main'

// handle the /start command
grammy.command('start', (ctx) => ctx.reply('Welcome! Up and running.'))

// handle other messages
grammy.on('message', (ctx) => ctx.reply('Got another message!'))

Configuration

The configuration file is located at config/grammy.ts. Here are the available configuration options:

Environment Variables

| Variable | Type | Required | Description | |----------|------|----------|-------------| | TELEGRAM_API_TOKEN | string | Yes | Your Telegram Bot API token obtained from @BotFather | | TELEGRAM_SECRET_TOKEN | string | No | Optional secret token to secure your webhook endpoint |

Configuration Options

The config/grammy.ts file allows you to customize the following options:

| Option | Type | Default | Description | |--------|------|---------|-------------| | apiToken | string | process.env.TELEGRAM_API_TOKEN | The Telegram Bot API token | | secretToken | string | process.env.TELEGRAM_SECRET_TOKEN | Optional secret token for webhook security | | onTimeout | 'throw' | 'return' | Function | 'throw' | Defines behavior when webhook request times out | | timeoutMilliseconds | number | 10_000 | Webhook request timeout in milliseconds | | botRouteName | string | apiToken | Custom route name for the webhook endpoint | | botConfig | object | undefined | Additional bot configuration options |

Example configuration:

import env from '#start/env'
import { defineConfig } from 'adonisjs-grammy'

const grammyConfig = defineConfig({
  apiToken: env.get('TELEGRAM_API_TOKEN'),
  secretToken: env.get('TELEGRAM_SECRET_TOKEN'),
  
  // Timeout handling
  timeoutMilliseconds: 10_000, // 10 seconds
  onTimeout: 'throw', // or 'return', or custom function
  
  // Custom route name (optional)
  botRouteName: 'telegram-bot',
  
  // Additional bot configuration
  botConfig: {
    client: {
      baseFetchConfig: {
        compress: true,
      },
    },
  },
})

export default grammyConfig

License

The MIT License (MIT). Please see LICENSE file for more information.

Disclaimer

This package is not officially maintained by Telegram. Telegram trademarks and logo are the property of Telegram Messenger LLP.