Skip to content

nhanlethanh1198/githubwebhook_telegram

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

GitHub Webhook Telegram Bot

A Telegram bot that receives GitHub webhook notifications and forwards them to configured Telegram chats. Built with Grammy (Telegram bot framework), Hono (web framework), and TypeORM (database ORM).

Features

  • πŸ”” Receive GitHub webhook events (push, pull requests, issues, etc.)
  • πŸ€– Telegram bot interface for management
  • πŸ’Ύ SQLite database for storing projects and events
  • πŸ”§ Configurable for multiple GitHub projects
  • πŸ“± Clean command-based interface

Tech Stack

Setup

  1. Install dependencies:

    bun install
  2. Create Telegram Bot:

    • Message @BotFather on Telegram
    • Create a new bot and get the token
  3. Configure environment:

    • Copy .env.example to .env
    • Add your Telegram bot token: TELEGRAM_BOT_TOKEN=your_token_here
  4. Run the application:

    bun run dev

Project Structure

src/
β”œβ”€β”€ bot.ts              # Telegram bot setup
β”œβ”€β”€ server.ts           # Hono webhook server
β”œβ”€β”€ database.ts         # TypeORM configuration
β”œβ”€β”€ commands/           # Bot commands
β”‚   β”œβ”€β”€ start.ts
β”‚   β”œβ”€β”€ help.ts
β”‚   └── ...
β”œβ”€β”€ entities/           # Database entities
β”‚   β”œβ”€β”€ GitHubProject.ts
β”‚   └── WebhookEvent.ts
└── types/              # TypeScript types
    └── command.ts

Commands

Each command is implemented in src/commands/ with the following pattern:

import { Context } from "grammy";
import { Command } from "../types/command.js";

export const commandName: Command = {
  command: "commandname",
  description: "Command description",
  handler: async (ctx: Context) => {
    // Command logic here
  },
};

Available commands:

  • /start - Start the bot
  • /help - Show help information

GitHub Webhook Telegram Bot

A Telegram bot that receives GitHub webhook notifications and forwards them to configured Telegram chats. Built with Grammy (Telegram bot framework), Hono (web framework), and TypeORM (database ORM). Deployed on Vercel Functions for serverless operation.

Features

  • πŸ”” Receive GitHub webhook events (push, pull requests, issues, etc.)
  • πŸ€– Telegram bot interface for management
  • πŸ’Ύ SQLite database for storing projects and events
  • πŸ”§ Configurable for multiple GitHub projects
  • ☁️ Serverless deployment on Vercel
  • πŸ”— Webhook-based bot operation (no long polling)

Tech Stack

Local Development Setup

  1. Install dependencies:

    bun install
  2. Create Telegram Bot:

    • Message @BotFather on Telegram
    • Create a new bot and get the token
  3. Configure environment:

    • Copy .env.example to .env
    • Add your Telegram bot token: TELEGRAM_BOT_TOKEN=your_token_here
    • Set BOT_WEBHOOK_SECRET for webhook security
  4. Run locally:

    bun run dev

Vercel Deployment

1. Install Vercel CLI

npm install -g vercel
# or
bun add -g vercel

2. Deploy to Vercel

vercel

Follow the prompts to:

  • Link your Vercel account
  • Set up the project
  • Configure environment variables

3. Set Environment Variables in Vercel

In your Vercel dashboard or via CLI:

vercel env add TELEGRAM_BOT_TOKEN
vercel env add BOT_WEBHOOK_SECRET

4. Configure Webhooks

Telegram Bot Webhook:

  • After deployment, visit: https://your-app.vercel.app/api/bot
  • This sets up the Telegram webhook automatically

GitHub Webhooks:

  • Webhook URL format: https://your-app.vercel.app/api/github/{projectId}
  • Replace {projectId} with the actual project ID from the bot

Project Structure

api/
β”œβ”€β”€ bot/
β”‚   └── route.ts              # Telegram bot webhook handler
└── github/
    └── [projectId]/
        └── route.ts          # GitHub webhook handler

src/
β”œβ”€β”€ bot.ts                    # Bot setup and commands
β”œβ”€β”€ database.ts               # TypeORM configuration
β”œβ”€β”€ commands/                 # Bot commands (modular design)
β”‚   β”œβ”€β”€ start.ts
β”‚   β”œβ”€β”€ help.ts
β”‚   β”œβ”€β”€ projects.ts
β”‚   β”œβ”€β”€ addproject.ts
β”‚   └── events.ts
β”œβ”€β”€ entities/                 # Database entities
β”‚   β”œβ”€β”€ GitHubProject.ts
β”‚   └── WebhookEvent.ts
└── types/
    └── command.ts            # Command interface definition

Commands

Each command is implemented in src/commands/ with the following pattern:

import type { Context } from "grammy";
import type { Command } from "../types/command";

export const commandName: Command = {
  command: "commandname",
  description: "Command description",
  handler: async (ctx: Context) => {
    // Command logic here
  },
};

Available commands:

  • /start - Start the bot
  • /help - Show help information
  • /projects - List configured projects
  • /addproject <owner> <repo> [description] - Add new project
  • /events - Show recent webhook events

Database

The application uses SQLite with the following entities:

  • GitHubProject: Project configuration
  • WebhookEvent: Event storage with relations

Environment Variables

TELEGRAM_BOT_TOKEN=your_telegram_bot_token
BOT_WEBHOOK_SECRET=your_webhook_secret
DATABASE_URL=github_webhooks.db

Usage

  1. Add a project: Send /addproject owner repository to the bot

  2. Configure GitHub webhook:

    • Go to your repository settings
    • Add webhook URL: https://your-app.vercel.app/api/github/{projectId}
    • Set content type to application/json
  3. Receive notifications: The bot will automatically forward GitHub events to your configured chat

Development

# Local development
bun run dev

# Deploy to production
bun run deploy

License

MIT

Database

The application uses SQLite with the following entities:

  • GitHubProject: Stores GitHub repository configurations
  • WebhookEvent: Stores received webhook events

Development

# Development mode with hot reload
bun run dev

# Build for production
bun run build

# Start production server
bun run start

License

MIT

About

GitHub Webhook Telegram Bot - Serverless deployment on Vercel

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors