Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/monoflash/tba

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/monoflash/tba

  • v0.0.0-20241108165257-5bae142482ef
  • Source
  • Go
  • Socket score

Version published
Created
Source

Golang Bindings for the Telegram Bot API

Go Reference Test

Headline

This is a maintained fork of go-telegram-bot-api that preserves the original design while staying current with the latest Telegram Bot API specifications. It continues the development of the original github.com/go-telegram-bot-api package.

Features

  • Complete coverage of the Telegram Bot API
  • Simple and intuitive interface
  • Minimal dependencies
  • Production-ready and actively maintained
  • Preserves original API structure for easy migration

Installation

Install the latest version:

go get -u github.com/OvyFlash/telegram-bot-api

❗ Tag versioning is discouraged due to the unstable nature of the Telegram Bot API, and it might break at any time after the API changes. go get -u github.com/OvyFlash/telegram-bot-api/v7

Quick Start

Here's a simple echo bot using polling:

package main

import (
    "log"
    "time"
    api "github.com/OvyFlash/telegram-bot-api"
)

func main() {
    bot, err := api.NewBotAPI("BOT_TOKEN")
    if err != nil {
        panic(err)
    }

    log.Printf("Authorized on account %s", bot.Self.UserName)

    updateConfig := api.NewUpdate(0)
    updateConfig.Timeout = 60
    updatesChannel := bot.GetUpdatesChan(updateConfig)

    // Optional: Clear initial updates
    time.Sleep(time.Millisecond * 500)
    updatesChannel.Clear()

    for update := range updatesChannel {
        if update.Message == nil {
            continue
        }

        log.Printf("[%s] %s", update.Message.From.UserName, update.Message.Text)

        msg := api.NewMessage(update.Message.Chat.ID, update.Message.Text)
        msg.ReplyParameters.MessageID = update.Message.MessageID

        bot.Send(msg)
    }
}

Webhook Setup

For webhook implementation:

  1. Check the examples folder for examples of webhook implementations
  2. Use HTTPS (required by Telegram)
    • Generate SSL certificate:
    openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 3560 -subj "//O=Org\CN=Test" -nodes
    
    • Bring your own SSL certificate. Let's Encrypt is recommended for free TLS certificates in production.

Documentation

Contributing

  • Issues and feature requests are welcome
  • Pull requests should maintain the existing design philosophy
  • The focus is on providing a clean API wrapper without additional features

License

The MIT License

Copyright (c) 2015 Syfaro

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

FAQs

Package last updated on 08 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc