All Projects β†’ xamut β†’ Telegraphist

xamut / Telegraphist

Licence: mit
πŸ€– Telegram Bot API on Go

Programming Languages

go
31211 projects - #10 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Telegraphist

Telegrammer
Telegram Bot - written with Swift 5.2 / NIO, supports Linux, macOS
Stars: ✭ 248 (+1450%)
Mutual labels:  telegram-bot-api, telegram
Informer
A Telegram Mass Surveillance Bot in Python
Stars: ✭ 745 (+4556.25%)
Mutual labels:  telegram-bot-api, telegram
webhook-aiogram-heroku
A sample telegram bot made with aiogram, that fetches updates using the web-hook connection. Can be easily deployed to Heroku.
Stars: ✭ 36 (+125%)
Mutual labels:  telegram, telegram-bot-api
Java Telegram Bot Tutorial
Java Telegram Bot Tutorial. Feel free to submit issue if you found a mistake.
Stars: ✭ 165 (+931.25%)
Mutual labels:  telegram-bot-api, telegram
Telegram
Telegram Bot API Wrapper for Scala
Stars: ✭ 310 (+1837.5%)
Mutual labels:  telegram-bot-api, telegram
Rastreiobot
Telegram Bot @RastreioBot
Stars: ✭ 196 (+1125%)
Mutual labels:  telegram-bot-api, telegram
Java Telegram Bot Api
Telegram Bot API for Java
Stars: ✭ 819 (+5018.75%)
Mutual labels:  telegram-bot-api, telegram
Botserver
http://telegram.org Bot API Webhooks Framework, for Rubyists
Stars: ✭ 125 (+681.25%)
Mutual labels:  telegram-bot-api, telegram
Laravel Social Auto Posting
🌈Laravel social auto posting
Stars: ✭ 306 (+1812.5%)
Mutual labels:  telegram-bot-api, telegram
Telegram.bot.examples
Examples for the Telegram.Bot C# Library
Stars: ✭ 290 (+1712.5%)
Mutual labels:  telegram-bot-api, telegram
Telegram Bot Sdk
πŸ€– Telegram Bot API PHP SDK. Lets you build Telegram Bots easily! Supports Laravel out of the box.
Stars: ✭ 2,212 (+13725%)
Mutual labels:  telegram-bot-api, telegram
Pytelegrambotapi
Python Telegram bot api.
Stars: ✭ 4,986 (+31062.5%)
Mutual labels:  telegram-bot-api, telegram
Teledart
A Dart library interfacing with the latest Telegram Bot API.
Stars: ✭ 142 (+787.5%)
Mutual labels:  telegram-bot-api, telegram
Python Telegram
Python client for the Telegram's tdlib
Stars: ✭ 246 (+1437.5%)
Mutual labels:  telegram-bot-api, telegram
Telegram.bot
.NET Client for Telegram Bot API
Stars: ✭ 1,964 (+12175%)
Mutual labels:  telegram-bot-api, telegram
checkmk-telegram-notify
Get alerted by Check_MK via Telegram bash script
Stars: ✭ 28 (+75%)
Mutual labels:  telegram, telegram-bot-api
Zanzara
Asynchronous PHP Telegram Bot Framework built on top of ReactPHP
Stars: ✭ 107 (+568.75%)
Mutual labels:  telegram-bot-api, telegram
Bot Api Base
Clear and simple Telegram bot API
Stars: ✭ 122 (+662.5%)
Mutual labels:  telegram-bot-api, telegram
Telegram Bot Swift
Telegram Bot SDK for Swift (unofficial)
Stars: ✭ 275 (+1618.75%)
Mutual labels:  telegram-bot-api, telegram
Kotlin Telegram Bot
πŸ€– A wrapper for the Telegram Bot API written in Kotlin
Stars: ✭ 337 (+2006.25%)
Mutual labels:  telegram-bot-api, telegram

Telegraphist

GoDoc Telegraphist CI status Go Report Card GitHub tag (latest SemVer) GitHub

Telegram Bot API on Go. API v4.4 (29 July 2019) is supported. All methods and types represent their alter ego from Telegram Bot API so you would expect what you see in the official documentation. And you don't need to study the new API to use this library.

Documentation

Installation

go get -u github.com/xamut/telegraphist

Usage

package main

import (
	"encoding/json"
	"fmt"
	"os"

	Telegraphist "github.com/xamut/telegraphist"
	Telegram "github.com/xamut/telegraphist/telegram"
)

func printResp(resp interface{}, err error) {
	if err != nil {
		fmt.Println(err)
	}
	respAsJSON, _ := json.MarshalIndent(resp, "", "\t")
	fmt.Println(string(respAsJSON))
}

func main() {
	telegraphist, err := Telegraphist.NewClient(&Telegraphist.ClientConfig{
		BotToken: "YOUR_BOT_TOKEN",
	})

	if err != nil {
		fmt.Println(err)
	}

	printResp(telegraphist.GetMe()) // Simple method to obtain basic bot info
					// https://core.telegram.org/bots/api#getme
					// Returns an User struct

	chatID := int64(<YOUR_CHAT_ID>)
	printResp(telegraphist.SendMessage(&Telegram.SendMessageParams{ // Send a text message to a chat
		ChatID: chatID,  				        // https://core.telegram.org/bots/api#sendmessage
		Text:   "Hello there!", 				// Returns a Message struct
	}))

	photo, _ := os.Open("<PATH_TO_PHOTO>")
	printResp(telegraphist.SendPhoto(&Telegram.SendPhotoParams{ // Send a photo to a chat
		ChatID:  chatID,              			    // https://core.telegram.org/bots/api#sendphoto
		Photo:   photo,					    // Returns a Message struct
		Caption: "Just a nice photo",
	}))
}

Getting updates

Webhook

  • Find your IP
curl ifconfig.co
  • Use nip.io to pretend you have a domain, for example, "app.X.X.X.X.nip.io"

  • Generate a certificate, replace X.X.X.X with your IP:

openssl req -newkey rsa:2048 \
  -new -nodes -x509 \
  -days 3650 \
  -out cert.pem \
  -keyout key.pem \
  -subj "/O=Organization/CN=app.X.X.X.X.nip.io"
  • Run server
package main

import (
	"encoding/json"
	"fmt"
	"log"
	"net/url"
	"os"
	"path"

	Telegraphist "github.com/xamut/telegraphist"
	Telegram "github.com/xamut/telegraphist/telegram"
)

func combineURL(host string, parts ...string) string {
	baseURL, err := url.Parse(host)
	if err != nil {
		log.Fatal(err)
	}
	parts = append([]string{baseURL.Path}, parts...)
	baseURL.Path = path.Join(parts...)

	return baseURL.String()
}

func main() {
	telegraphist, err := Telegraphist.NewClient(&Telegraphist.ClientConfig{
		BotToken: "<YOUR_BOT_TOKEN>",
	})

	if err != nil {
		log.Fatal(err)
	}

	host := "https://app.X.X.X.X.nip.io" // For example: "https://example.com"
	webhookPath := "<YOUR_WEBHOOK_PATH>" // For example: "/telegram_webhook"

	cert, _ := os.Open("./cert.pem")
	ok, err := telegraphist.SetWebhook(&Telegram.SetWebhookParams{
		URL:         combineURL(host, webhookPath),
		Certificate: cert,
	})

	if err != nil {
		log.Fatal(err)
	}

	if !ok {
		log.Println("Something went wrong and the webhook wasn't set up")
	}

	handlers := map[string]func(update Telegram.Update) error{
		// "message":              func(update Telegram.Update) error {},
		// "edited_message":       func(update Telegram.Update) error {},
		// "channel_post":         func(update Telegram.Update) error {},
		// "edited_channel_post":  func(update Telegram.Update) error {},
		// "inline_query":         func(update Telegram.Update) error {},
		// "chosen_inline_result": func(update Telegram.Update) error {},
		// "callback_query":       func(update Telegram.Update) error {},
		// "shipping_query":       func(update Telegram.Update) error {},
		// "pre_checkout_query":   func(update Telegram.Update) error {},
		// "poll":                 func(update Telegram.Update) error {},
		"always": func(update Telegram.Update) error {
			js, _ := json.MarshalIndent(update, "", "\t")
			fmt.Println(string(js))
			return nil
		},
	}

	err = Telegraphist.NewServer(&Telegraphist.ServerConfig{
		EnableHTTPS: true,
		Webhook:     webhookPath,
	}, &handlers)

	if err != nil {
		log.Fatal(err)
	}
}

NOTE: Use this example only for testing purposes, for production use something like nginx or traefik to serve HTTPS (and/or to (re)generate Let's Encrypt certificate).

License

Telegraphist is released under the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].