Skip to content

QuantProcessing/notify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Notify

Go Reference License: MIT

English | 中文

A lightweight Go library for sending notifications via Feishu (Lark) and Telegram.

Features

Feishu / Lark

  • Webhook messages (text, rich-text / post)
  • SDK-based messaging via official Lark Open Platform
  • Phone urgent call notifications

Telegram

  • Bot with chat ID whitelist middleware
  • Simple Notify() helper for one-off messages
  • Long-polling command handler with Start()

Requirements

  • Go 1.24+

Install

go get github.com/QuantProcessing/notify

Import only what you need:

import "github.com/QuantProcessing/notify/feishu"
import "github.com/QuantProcessing/notify/telegram"

AI Agent Integration

npx skills add QuantProcessing/notify

Configuration

Variable Required Description
FEISHU_WEBHOOK Yes (Feishu) Webhook URL for bot messages
FEISHU_APP_ID No Lark App ID (for SDK features / urgent calls)
FEISHU_APP_SECRET No Lark App Secret
FEISHU_USER_OPEN_ID No User Open ID (for phone urgent calls)
TELEGRAM_BOT_TOKEN Yes (Telegram) Telegram bot token
TELEGRAM_CHAT_ID Yes (Telegram) Comma-separated chat IDs (first is default)

See .env.example for a complete template.

Usage

Feishu

Quick Start (Global API)

package main

import (
    "log"
    "github.com/QuantProcessing/notify/feishu"
)

func main() {
    feishu.Init(feishu.Config{
        Webhook: "https://open.feishu.cn/open-apis/bot/v2/hook/xxx",
    })

    if err := feishu.SendText("Hello from Go!"); err != nil {
        log.Fatal(err)
    }
}

Rich Text (Post)

err := feishu.SendRichText("Alert", [][]feishu.PostElem{
    {feishu.NewTextElem("Server "), feishu.NewAElem("down", "https://example.com")},
    {feishu.NewAtElem("ou_user_id")},
})

Urgent Phone Call

Requires App ID, App Secret, and User Open ID:

feishu.Init(feishu.Config{
    Webhook:    "https://open.feishu.cn/open-apis/bot/v2/hook/xxx",
    AppID:      "cli_xxx",
    AppSecret:  "xxx",
    UserOpenID: "ou_xxx",
})

if err := feishu.SendUrgentText("CRITICAL: System Down!"); err != nil {
    log.Fatal(err)
}

Multi-Instance Usage

bot := feishu.NewBot(feishu.Config{
    Webhook: "https://open.feishu.cn/open-apis/bot/v2/hook/xxx",
})

if err := bot.SendText("Hello!"); err != nil {
    log.Fatal(err)
}

Telegram

Quick Start (Global API)

package main

import (
    "log"
    "github.com/QuantProcessing/notify/telegram"
)

func main() {
    if err := telegram.Init(telegram.Config{
        BotToken: "123456:ABC-DEF...",
        ChatID:   "12345678",          // comma-separated for multiple
    }); err != nil {
        log.Fatal(err)
    }

    if err := telegram.Notify("Trade executed: BUY 0.01 BTC @ $65,000"); err != nil {
        log.Fatal(err)
    }
}

Start Bot (Long Polling)

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

telegram.Start(ctx) // blocks until ctx is cancelled

Multi-Instance Usage

bot, err := telegram.NewBot(telegram.Config{
    BotToken: "123456:ABC-DEF...",
    ChatID:   "12345678",
})
if err != nil {
    log.Fatal(err)
}

if err := bot.Notify("Hello!"); err != nil {
    log.Fatal(err)
}

Architecture

notify/
├── feishu/          # Feishu (Lark) notification package
│   ├── bot.go       # Global API + Bot struct
│   ├── client.go    # HTTP webhook + Lark SDK client
│   └── types.go     # Message type definitions
├── telegram/        # Telegram notification package
│   ├── bot.go       # Global API + Bot struct
│   └── middleware.go # Chat ID authorization middleware
├── go.mod
├── LICENSE          # MIT
└── README.md

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages