### Install the package Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/vincent-petithory/dataurl/README.md Use the go get command to install the library. ```bash go get github.com/vincent-petithory/dataurl ``` -------------------------------- ### Install Go Color Package Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/fatih/color/README.md Install the color package using the go get command. This is the initial setup step for using the package. ```bash go get github.com/fatih/color ``` -------------------------------- ### Install go-colorable Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/mattn/go-colorable/README.md Use the go get command to install the package. ```bash $ go get github.com/mattn/go-colorable ``` -------------------------------- ### Install go-qrcode Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/skip2/go-qrcode/README.md Use the go get command to install the library and the command-line tool. ```bash go get -u github.com/skip2/go-qrcode/... ``` -------------------------------- ### Install Backoff Library Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/jpillora/backoff/README.md Use 'go get' to install the backoff library. This command fetches and installs the package. ```bash $ go get -v github.com/jpillora/backoff ``` -------------------------------- ### Install GoZulipBot Library Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/matterbridge/gozulipbot/README.md Use 'go get' to install the gozulipbot library. This command fetches and installs the specified package. ```bash go get github.com/ifo/gozulipbot ``` -------------------------------- ### Go Quick Start Example Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/d5/tengo/v2/README.md A Go program demonstrating how to compile and run Tengo script code. It shows how to add input values to the script and retrieve output values after execution. ```go package main import ( "context" "fmt" "github.com/d5/tengo/v2" ) func main() { // create a new Script instance script := tengo.NewScript([]byte( `each := func(seq, fn) { for x in seq { fn(x) } } sum := 0 mul := 1 each([a, b, c, d], func(x) { sum += x mul *= x })`)) // set values _ = script.Add("a", 1) _ = script.Add("b", 9) _ = script.Add("c", 8) _ = script.Add("d", 4) // run the script compiled, err := script.RunContext(context.Background()) if err != nil { panic(err) } // retrieve values sum := compiled.Get("sum") mul := compiled.Get("mul") fmt.Println(sum, mul) // "22 288" } ``` -------------------------------- ### Install msgpack/v5 Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/vmihailenco/msgpack/v5/README.md Install the msgpack/v5 library using go get. Ensure you have initialized a Go module first. ```shell go get github.com/vmihailenco/msgpack/v5 ``` -------------------------------- ### Install Slack Go Library Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/slack-go/slack/README.md Use 'go get' to install the Slack Go library. This command fetches and installs the latest version of the library. ```bash go get -u github.com/slack-go/slack ``` -------------------------------- ### Install go-isatty Package Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/mattn/go-isatty/README.md Use the go get command to install the go-isatty package. This command fetches and installs the package and its dependencies. ```bash $ go get github.com/mattn/go-isatty ``` -------------------------------- ### Basic Echo Server Example Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/labstack/echo/v4/README.md A minimal Go program demonstrating how to create an Echo instance, apply basic middleware (Logger and Recover), define a root route, and start the HTTP server. ```go package main import ( "github.com/labstack/echo/v4" "github.com/labstack/echo/v4/middleware" "net/http" ) func main() { // Echo instance e := echo.New() // Middleware e.Use(middleware.Logger()) e.Use(middleware.Recover()) // Routes e.GET("/", hello) // Start server e.Logger.Fatal(e.Start(":1323")) } // Handler func hello(c echo.Context) error { return c.String(http.StatusOK, "Hello, World!") } ``` -------------------------------- ### Install godown Command-Line Tool Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/mattn/godown/README.md Install the godown command-line tool using `go get`. This command fetches and installs the executable to your Go bin path. ```bash $ go get github.com/mattn/godown/cmd/godown ``` -------------------------------- ### Install multierr Source: https://github.com/42wim/matterbridge/blob/master/vendor/go.uber.org/multierr/README.md Use `go get` to install the latest version of the multierr library. ```bash go get -u go.uber.org/multierr@latest ``` -------------------------------- ### Install go-whatsapp Package Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/Rhymen/go-whatsapp/README.md Use 'go get' to install the go-whatsapp package. This is the initial step before importing it into your project. ```sh go get github.com/Rhymen/go-whatsapp ``` -------------------------------- ### Install Afero Go Package Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/spf13/afero/README.md Use 'go get' to install the latest version of the Afero library. ```bash $ go get github.com/spf13/afero ``` -------------------------------- ### Install Melody Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/olahol/melody/README.md Command to install the package via go get. ```bash go get github.com/olahol/melody ``` -------------------------------- ### Install the YAML package Source: https://github.com/42wim/matterbridge/blob/master/vendor/gopkg.in/yaml.v2/README.md Use the go get command to install the package into your Go environment. ```bash go get gopkg.in/yaml.v2 ``` -------------------------------- ### Install Go Color Package Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/labstack/gommon/color/README.md Use 'go get' to install the gommon/color package. ```sh go get github.com/labstack/gommon/color ``` -------------------------------- ### Install Gabs Utility Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/Jeffail/gabs/README.md Use 'go get' to install the Gabs utility. This command fetches and installs the specified package. ```bash go get github.com/Jeffail/gabs ``` -------------------------------- ### Install netdb package Source: https://github.com/42wim/matterbridge/blob/master/vendor/modernc.org/libc/honnef.co/go/netdb/README.md Use the go get command to download and install the package into your workspace. ```sh go get honnef.co/go/netdb ``` -------------------------------- ### Install and use tomll tool Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/pelletier/go-toml/v2/README.md Install the tomll utility and display its help menu. ```bash $ go install github.com/pelletier/go-toml/v2/cmd/tomll@latest $ tomll --help ``` -------------------------------- ### Install DiscordGo Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/bwmarrin/discordgo/README.md Use the go get command to install the latest tagged release of the package. ```sh go get github.com/bwmarrin/discordgo ``` -------------------------------- ### Install Blackfriday Package Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/russross/blackfriday/README.md Use 'go get' to install the Blackfriday package. This command resolves and adds the package to your module, then builds and installs it. ```go go get github.com/russross/blackfriday ``` -------------------------------- ### Install ansi Library Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/mgutz/ansi/README.md Use 'go get' to install the ansi library. This command fetches and installs the latest version. ```sh go get -u github.com/mgutz/ansi ``` -------------------------------- ### Install and use jsontoml tool Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/pelletier/go-toml/v2/README.md Install the jsontoml utility and display its help menu. ```bash $ go install github.com/pelletier/go-toml/v2/cmd/jsontoml@latest $ jsontoml --help ``` -------------------------------- ### Install mapstructure Go Library Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/mitchellh/mapstructure/README.md Use 'go get' to install the mapstructure library. This is the standard method for Go package installation. ```bash go get github.com/mitchellh/mapstructure ``` -------------------------------- ### Install uniseg Package Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/rivo/uniseg/README.md Use 'go get' to install the uniseg package. This command fetches and installs the specified package and its dependencies. ```bash go get github.com/rivo/uniseg ``` -------------------------------- ### Install Matterbridge from source Source: https://github.com/42wim/matterbridge/blob/master/README.md Commands to install stable or development versions of Matterbridge using Go. ```bash go install github.com/42wim/matterbridge ``` ```bash go install github.com/42wim/matterbridge@master ``` ```bash go install -tags nomsteams,nozulip github.com/42wim/matterbridge ``` -------------------------------- ### CLI Usage Examples Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/skip2/go-qrcode/README.md Examples of using the qrcode command-line tool to generate QR codes. ```bash qrcode hello word | display qrcode "homepage: https://github.com/skip2/go-qrcode" > out.png ``` -------------------------------- ### Install Echo Framework Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/labstack/echo/v4/README.md Use `go get` to install the latest version of the Echo framework. Ensure your Go version is compatible with the latest Echo release. ```shell go get github.com/labstack/echo/v4 ``` -------------------------------- ### Install Request Library Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/monaco-io/request/README.md Use go mod to install the package. ```bash go get github.com/monaco-io/request ``` -------------------------------- ### Install and use tomljson tool Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/pelletier/go-toml/v2/README.md Install the tomljson utility and display its help menu. ```bash $ go install github.com/pelletier/go-toml/v2/cmd/tomljson@latest $ tomljson --help ``` -------------------------------- ### Install Emoji Package Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/kyokomi/emoji/v2/README.md Use 'go get' to install the emoji package for your project. ```bash go get github.com/kyokomi/emoji/v2 ``` -------------------------------- ### Install the INI package Source: https://github.com/42wim/matterbridge/blob/master/vendor/gopkg.in/ini.v1/README.md Use the go get command to add the package to your project dependencies. ```sh $ go get gopkg.in/ini.v1 ``` -------------------------------- ### Installing Matterbridge from Source Source: https://context7.com/42wim/matterbridge/llms.txt Install Matterbridge directly from its source repository using 'go install'. This section also shows how to build with specific features disabled to reduce memory usage or enable experimental features like WhatsApp multi-device support. ```bash # Install from source go install github.com/42wim/matterbridge@latest # Build with specific features disabled (reduces memory usage) go install -tags nomsteams,nozulip github.com/42wim/matterbridge@latest # Build with WhatsApp multi-device support (GPL3 dependency) go install -tags whatsappmulti github.com/42wim/matterbridge@master ``` -------------------------------- ### Example Package Usage Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/lrstanley/girc/README.md This example demonstrates how to use the girc package for basic IRC client functionality, including event handling for commands. ```go package main import ( "fmt" "os" "github.com/lrstanley/girc" ) func main() { // Create a new girc client client := girc.New(girc.Config{ // Server details Server: "irc.libera.chat", Port: 6697, SSL: true, // Nickname to use Nick: "girc-bot", // Optional: Password for NickServ Pass: "", }) // Register event handlers client.Handlers.Add(girc.ALL_EVENTS, func(e girc.Event) { fmt.Printf("%s\n", e.Raw) }) // Handle specific commands client.Handlers.Add("PRIVMSG", func(e girc.Event) { fmt.Printf("PRIVMSG from %s to %s: %s\n", e.Nick, e.Target, e.Message) if e.Target == client.State.Nick && e.Message == "!ping" { client.Send("pong") } }) // Connect to the IRC server err := client.Connect() // Connect will block until the client disconnects if err != nil { fmt.Fprintf(os.Stderr, "Error connecting: %v\n", err) os.Exit(1) } } ``` -------------------------------- ### Install Golang Tag Parser Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/vmihailenco/tagparser/v2/README.md Use 'go get' to install the tagparser library version 2. ```shell go get github.com/vmihailenco/tagparser/v2 ``` -------------------------------- ### Run fsnotify command line example Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/fsnotify/fsnotify/README.md Executes the example provided in the cmd/fsnotify directory. ```bash % go run ./cmd/fsnotify ``` -------------------------------- ### Install Blackfriday Tool Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/russross/blackfriday/README.md Installs the 'blackfriday-tool', a command-line utility for processing Markdown files. This also installs the Blackfriday library. ```go go get github.com/russross/blackfriday-tool ``` -------------------------------- ### Gophers Application Example Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/olahol/melody/README.md A more complex example demonstrating session data storage, connection handling, and selective broadcasting. ```go package main import ( "net/http" "strings" "github.com/google/uuid" "github.com/olahol/melody" ) type GopherInfo struct { ID, X, Y string } func main() { m := melody.New() http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { http.ServeFile(w, r, "index.html") }) http.HandleFunc("/ws", func(w http.ResponseWriter, r *http.Request) { m.HandleRequest(w, r) }) m.HandleConnect(func(s *melody.Session) { ss, _ := m.Sessions() for _, o := range ss { value, exists := o.Get("info") if !exists { continue } info := value.(*GopherInfo) s.Write([]byte("set " + info.ID + " " + info.X + " " + info.Y)) } id := uuid.NewString() s.Set("info", &GopherInfo{id, "0", "0"}) s.Write([]byte("iam " + id)) }) m.HandleDisconnect(func(s *melody.Session) { value, exists := s.Get("info") if !exists { return } info := value.(*GopherInfo) m.BroadcastOthers([]byte("dis "+info.ID), s) }) m.HandleMessage(func(s *melody.Session, msg []byte) { p := strings.Split(string(msg), " ") value, exists := s.Get("info") if len(p) != 2 || !exists { return } info := value.(*GopherInfo) info.X = p[0] info.Y = p[1] m.BroadcastOthers([]byte("set "+info.ID+" "+info.X+" "+info.Y), s) }) http.ListenAndServe(":5000", nil) } ``` -------------------------------- ### Install GoJay Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/francoispqt/gojay/README.md Use this command to get the GoJay library for your project. ```bash go get github.com/francoispqt/gojay ``` -------------------------------- ### Install Logrus Prefixed Formatter Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/matterbridge/logrus-prefixed-formatter/README.md Use the go get command to add the package to your project. ```sh $ go get github.com/x-cray/logrus-prefixed-formatter ``` -------------------------------- ### Install Go LDAP v3 Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/mattermost/ldap/README.md Use this command to install the go-ldap/ldap/v3 library for Go Modules. ```bash go get github.com/go-ldap/ldap/v3 ``` -------------------------------- ### Example output Source: https://github.com/42wim/matterbridge/blob/master/vendor/gopkg.in/yaml.v2/README.md The expected output generated by running the provided Go example code. ```text --- t: {Easy! {2 [3 4]}} --- t dump: a: Easy! b: c: 2 d: [3, 4] --- m: map[a:Easy! b:map[c:2 d:[3 4]]] --- m dump: a: Easy! b: c: 2 d: - 3 - 4 ``` -------------------------------- ### Install YAML Package for Go Source: https://github.com/42wim/matterbridge/blob/master/vendor/gopkg.in/yaml.v3/README.md Use 'go get' to install the yaml package. The import path is gopkg.in/yaml.v3. ```bash go get gopkg.in/yaml.v3 ``` -------------------------------- ### Verify binary installation Source: https://github.com/42wim/matterbridge/blob/master/README.md Check the contents of the Go binary directory to confirm successful installation. ```bash $ ls ~/go/bin/ matterbridge ``` -------------------------------- ### Install slog-shim Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/sagikazarmark/slog-shim/README.md Use the go get command to add the dependency to your project. ```shell go get github.com/sagikazarmark/slog-shim ``` -------------------------------- ### Simple Backoff Example Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/jpillora/backoff/README.md Demonstrates basic usage of the backoff counter with default settings. Call Duration() to get the next delay, and Reset() to reset the counter. ```go b := &backoff.Backoff{ //These are the defaults Min: 100 * time.Millisecond, Max: 10 * time.Second, Factor: 2, Jitter: false, } fmt.Printf("%s\n", b.Duration()) fmt.Printf("%s\n", b.Duration()) fmt.Printf("%s\n", b.Duration()) fmt.Printf("Reset!\n") b.Reset() fmt.Printf("%s\n", b.Duration()) ``` -------------------------------- ### Install go-toml v2 module Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/pelletier/go-toml/v2/README.md Command to install the library for Go versions 1.13 and above. ```bash GO111MODULE=on go get github.com/pelletier/go-toml/v2 ``` -------------------------------- ### Install Go LDAP (Legacy) Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/mattermost/ldap/README.md For legacy GOPATH installations, use this command. Ensure GOPATH is set correctly. ```bash go get github.com/go-ldap/ldap ``` -------------------------------- ### Install Zerolog Logger Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/rs/zerolog/README.md Install the global logger package for simple logging operations. ```bash go get -u github.com/rs/zerolog/log ``` -------------------------------- ### Install and Upgrade Properties Library in Go Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/magiconair/properties/README.md Command to install or update the properties library using the Go build tool. ```shell go get -u github.com/magiconair/properties ``` -------------------------------- ### Install and Configure Crypt Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/spf13/viper/README.md Use the crypt command-line tool to manage configuration in a K/V store. ```bash $ go get github.com/sagikazarmark/crypt/bin/crypt $ crypt set -plaintext /config/hugo.json /Users/hugo/settings/config.json ``` ```bash $ crypt get -plaintext /config/hugo.json ``` -------------------------------- ### Initializing OsFs Backend Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/spf13/afero/README.md Demonstrates the initialization of Afero's OsFs backend, which wraps native OS calls. This is suitable for production environments and can be easily swapped for testing. ```go appfs := afero.NewOsFs() appfs.MkdirAll("src/a", 0755) ``` -------------------------------- ### Multi-Gateway Configuration Example Source: https://context7.com/42wim/matterbridge/llms.txt Set up multiple independent gateways to manage complex bridge topologies. This example demonstrates configuring Discord, Slack, Telegram, and IRC accounts and defining gateways for 'community', 'development', and 'samechannel' configurations. ```toml [discord.mydiscord] Token="YOUR_TOKEN" Server="myserver" AutoWebhooks=true [slack.myworkspace] Token="YOUR_TOKEN" [telegram.mytelegram] Token="YOUR_TOKEN" [irc.libera] Server="irc.libera.chat:6667" Nick="mybridge" # Gateway 1: Community channels [[gateway]] name="community" enable=true [[gateway.inout]] account="discord.mydiscord" channel="community" [[gateway.inout]] account="slack.myworkspace" channel="community" [[gateway.inout]] account="telegram.mytelegram" channel="-100111111111" # Gateway 2: Development channels [[gateway]] name="development" enable=true [[gateway.inout]] account="discord.mydiscord" channel="dev" [[gateway.inout]] account="irc.libera" channel="#myproject-dev" # Gateway 3: Same channel names across platforms [[samechannelgateway]] name="samechannel" enable=true accounts=["slack.myworkspace", "discord.mydiscord"] channels=["general", "random", "announcements"] ``` -------------------------------- ### Install Bytes Package Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/labstack/gommon/bytes/README.md Install the gommon/bytes package using go get. ```go go get github.com/labstack/gommon/bytes ``` -------------------------------- ### Full Logr Usage Example Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/mattermost/logr/v2/README.md Complete workflow for initializing Logr, adding a writer target, logging messages, and shutting down. ```go // Create Logr instance. lgr,_ := logr.New() // Create a filter and formatter. Both can be shared by multiple // targets. filter := &logr.StdFilter{Lvl: logr.Warn, Stacktrace: logr.Error} formatter := &formatters.Plain{Delim: " | "} // WriterTarget outputs to any io.Writer t := targets.NewWriterTarget(filter, formatter, os.StdOut, 1000) lgr.AddTarget(t) // One or more Loggers can be created, shared, used concurrently, // or created on demand. logger := lgr.NewLogger().With("user", "Sarah") // Now we can log to the target(s). logger.Debug("login attempt") logger.Error("login failed") // Ensure targets are drained before application exit. lgr.Shutdown() ``` -------------------------------- ### Initialize Discord Client Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/bwmarrin/discordgo/README.md Create a new client instance using a valid authentication token. ```go discord, err := discordgo.New("Bot " + "authentication token") ``` -------------------------------- ### Initializing MemMapFs Backend Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/spf13/afero/README.md Shows how to initialize Afero's MemMapFs, an atomic and concurrent memory-backed filesystem. It's ideal for mocking and speeding up operations when disk persistence is not required. ```go mm := afero.NewMemMapFs() mm.MkdirAll("src/a", 0755) ``` -------------------------------- ### Implement Yamux Client and Server Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/hashicorp/yamux/README.md Demonstrates basic setup for both client and server sides using a TCP connection. ```go func client() { // Get a TCP connection conn, err := net.Dial(...) if err != nil { panic(err) } // Setup client side of yamux session, err := yamux.Client(conn, nil) if err != nil { panic(err) } // Open a new stream stream, err := session.Open() if err != nil { panic(err) } // Stream implements net.Conn stream.Write([]byte("ping")) } func server() { // Accept a TCP connection conn, err := listener.Accept() if err != nil { panic(err) } // Setup server side of yamux session, err := yamux.Server(conn, nil) if err != nil { panic(err) } // Accept a stream stream, err := session.Accept() if err != nil { panic(err) } // Listen for a message buf := make([]byte, 4) stream.Read(buf) } ``` -------------------------------- ### ANSI Color Library Installation Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/mgutz/ansi/README.md Instructions on how to install the ansi Go library using the go get command. ```APIDOC ## Install Get it ```sh go get -u github.com/mgutz/ansi ``` ``` -------------------------------- ### Run Test Suite Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/spf13/viper/README.md Execute the project's test suite. Ensure Go is installed and dependencies are managed. ```shell make test ``` -------------------------------- ### Initialize and use fsnotify watcher Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/fsnotify/fsnotify/README.md Demonstrates creating a watcher, listening for events and errors in a goroutine, and adding a path to watch. ```go package main import ( "log" "github.com/fsnotify/fsnotify" ) func main() { // Create new watcher. watcher, err := fsnotify.NewWatcher() if err != nil { log.Fatal(err) } defer watcher.Close() // Start listening for events. go func() { for { select { case event, ok := <-watcher.Events: if !ok { return } log.Println("event:", event) if event.Has(fsnotify.Write) { log.Println("modified file:", event.Name) } case err, ok := <-watcher.Errors: if !ok { return } log.Println("error:", err) } } }() // Add a path. err = watcher.Add("/tmp") if err != nil { log.Fatal(err) } // Block main goroutine forever. <-make(chan struct{}) } ``` -------------------------------- ### Create and Run a Simple Telegram Bot Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/matterbridge/telegram-bot-api/v6/README.md This example demonstrates how to create a basic Telegram bot that echoes messages back to the sender. Ensure the library is installed and up to date. It uses polling to receive updates. ```go package main import ( "log" g "github.com/go-telegram-bot-api/telegram-bot-api/v5" ) func main() { bot, err := tgbotapi.NewBotAPI("MyAwesomeBotToken") if err != nil { log.Panic(err) } bot.Debug = true log.Printf("Authorized on account %s", bot.Self.UserName) u := tgbotapi.NewUpdate(0) u.Timeout = 60 updates := bot.GetUpdatesChan(u) for update := range updates { if update.Message != nil { // If we got a message log.Printf("[%s] %s", update.Message.From.UserName, update.Message.Text) msg := tgbotapi.NewMessage(update.Message.Chat.ID, update.Message.Text) msg.ReplyToMessageID = update.Message.MessageID bot.Send(msg) } } } ``` -------------------------------- ### Example of NewRatP usage Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/av-elier/go-decimal-to-rational/README.md Demonstrates converting decimals to rational fractions with a specified step precision using NewRatP. Ensure the dectofrac package is imported. ```go import dectofrac "github.com/av-elier/go-decimal-to-rational" import "fmt" func ExampleNewRatP() { fmt.Println(NewRatP(0.6666, 0.01).String()) fmt.Println(NewRatP(0.981, 0.001).String()) fmt.Println(NewRatP(0.75, 0.01).String()) // Output: // 2/3 // 981/1000 // 3/4 } ``` -------------------------------- ### Troubleshoot gRPC-Go Installation Error Source: https://github.com/42wim/matterbridge/blob/master/vendor/google.golang.org/grpc/README.md This console output shows a typical I/O timeout error when trying to 'go get' gRPC-Go due to network restrictions. The provided solution involves aliasing the import path using Go modules. ```console $ go get -u google.golang.org/grpc package google.golang.org/grpc: unrecognized import path "google.golang.org/grpc" (https fetch: Get https://google.golang.org/grpc?go-get=1: dial tcp 216.239.37.1:443: i/o timeout) ``` -------------------------------- ### Install tomll CLI Tool Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/pelletier/go-toml/README.md Installs the tomll command-line tool for linting TOML files. Use 'go install' with the specified path. ```bash go install github.com/pelletier/go-toml/cmd/tomll tomll --help ``` -------------------------------- ### Enable and start Matterbridge systemd service Source: https://github.com/42wim/matterbridge/wiki/Deploy:-Digitalocean Reloads the systemd daemon, enables the Matterbridge service to start on boot, and then starts the service immediately. ```bash sudo systemctl daemon-reload sudo systemctl enable matterbridge sudo systemctl start matterbridge ``` -------------------------------- ### Install jsontoml CLI Tool Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/pelletier/go-toml/README.md Installs the jsontoml command-line tool for converting JSON files to TOML. Use 'go install' with the specified path. ```bash go install github.com/pelletier/go-toml/cmd/jsontoml jsontoml --help ``` -------------------------------- ### Install tomljson CLI Tool Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/pelletier/go-toml/README.md Installs the tomljson command-line tool for converting TOML files to JSON. Use 'go install' with the specified path. ```bash go install github.com/pelletier/go-toml/cmd/tomljson tomljson --help ``` -------------------------------- ### Create Logger Instance Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/mattermost/logr/v2/README.md Create a lightweight logger instance for contextual logging. ```go logger := lgr.NewLogger() ``` ```go logger2 := logger.With(logr.String("user", "Sam")) ``` -------------------------------- ### Perform GET Request Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/monaco-io/request/README.md Execute a basic GET request with query parameters. ```go package main import ( "log" "github.com/monaco-io/request" ) func main() { client := request.Client{ URL: "https://google.com", Method: "GET", Params: map[string]string{"hello": "world"}, } resp, err := client.Do() log.Println(resp.Code, string(resp.Data), err) } ``` -------------------------------- ### Load Properties from Various Sources in Go Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/magiconair/properties/README.md Demonstrates initializing a properties object from files, maps, strings, URLs, and command-line flags. Ensure necessary imports are included. ```go import ( "flag" "github.com/magiconair/properties" ) func main() { // init from a file p := properties.MustLoadFile("${HOME}/config.properties", properties.UTF8) // or multiple files p = properties.MustLoadFiles([]string{ "${HOME}/config.properties", "${HOME}/config-${USER}.properties", }, properties.UTF8, true) // or from a map p = properties.LoadMap(map[string]string{"key": "value", "abc": "def"}) // or from a string p = properties.MustLoadString("key=value\nabc=def") // or from a URL p = properties.MustLoadURL("http://host/path") // or from multiple URLs p = properties.MustLoadURL([]string{ "http://host/config", "http://host/config-${USER}", }, true) // or from flags p.MustFlag(flag.CommandLine) // get values through getters host := p.MustGetString("host") port := p.GetInt("port", 8080) // or through Decode type Config struct { Host string `properties:"host"` Port int `properties:"port,default=9000"` Accept []string `properties:"accept,default=image/png;image;gif"` Timeout time.Duration `properties:"timeout,default=5s"` } var cfg Config if err := p.Decode(&cfg); err != nil { log.Fatal(err) } } ``` -------------------------------- ### Run mkall.sh to Generate Files (Old Build System) Source: https://github.com/42wim/matterbridge/blob/master/vendor/golang.org/x/sys/unix/README.md Use this script to generate Go files for your current OS and architecture when using the old build system. Ensure GOOS and GOARCH are set correctly. ```bash mkall.sh ``` -------------------------------- ### Set Up Pre-Push Hook Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/mattermost/ldap/README.md Create a symbolic link to set up a pre-push hook that runs tests and verification scripts automatically before each push. ```bash ln -s ../../.githooks/pre-push .git/hooks/pre-push ``` -------------------------------- ### TOML Commented Configuration Example Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/pelletier/go-toml/v2/README.md Demonstrates how go-toml can emit TOML documents with comments and commented-out values, useful for configuration files. ```toml # Host IP to connect to. host = '127.0.0.1' # Port of the remote server. port = 4242 # Encryption parameters (optional) # [TLS] # cipher = 'AEAD-AES128-GCM-SHA256' # version = 'TLS 1.3' ``` -------------------------------- ### Example of NewRatI usage Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/av-elier/go-decimal-to-rational/README.md Shows how to convert decimals to rational fractions using a specified number of iterations with NewRatI. The dectofrac package must be imported. ```go import dectofrac "github.com/av-elier/go-decimal-to-rational" import "fmt" func ExampleNewRatI() { fmt.Println(NewRatI(0.6667, 3).String()) fmt.Println(NewRatI(0.6667, 4).String()) // Output: // 2/3 // 6667/10000 } ``` -------------------------------- ### Create a New Color Instance Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/labstack/gommon/color/README.md Demonstrates creating a new instance of the color formatter for localized styling. ```go c := New() c.Green("green") ``` -------------------------------- ### Text Log Output Example Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/sirupsen/logrus/README.md Example of a text formatted log entry with caller information. ```text time="2015-03-26T01:27:38-04:00" level=fatal method=github.com/sirupsen/arcticcreatures.migrate msg="a penguin swims by" animal=penguin ``` -------------------------------- ### Basic LRU Cache Example Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/hashicorp/golang-lru/v2/README.md Demonstrates the creation and basic usage of a fixed-size, thread-safe LRU cache. Ensure the cache size is correctly managed to avoid unexpected evictions. ```go package main import ( "fmt" "github.com/hashicorp/golang-lru/v2" ) func main() { l, _ := lru.New[int, any](128) for i := 0; i < 256; i++ { l.Add(i, nil) } if l.Len() != 128 { panic(fmt.Sprintf("bad len: %v", l.Len())) } } ``` -------------------------------- ### JSON Log Output Example Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/sirupsen/logrus/README.md Example of a JSON formatted log entry with caller information. ```json {"animal":"penguin","level":"fatal","method":"github.com/sirupsen/arcticcreatures.migrate","msg":"a penguin swims by", "time":"2014-03-10 19:57:38.562543129 -0400 EDT"} ``` -------------------------------- ### Instantiate Logr Engine Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/mattermost/logr/v2/README.md Initialize the main Logr engine instance. ```go lgr,_ := logr.New() ``` -------------------------------- ### Install Lottie Dependency Source: https://github.com/42wim/matterbridge/wiki/Settings Command to install the lottie dependency required for Telegram animated sticker conversion. ```bash pip install lottie cairosvg ``` -------------------------------- ### Run Benchmarks Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/klauspost/compress/zstd/internal/xxhash/README.md Commands to compare pure-Go and assembly implementations using benchstat. ```bash benchstat <(go test -tags purego -benchtime 500ms -count 15 -bench 'Sum64$') benchstat <(go test -benchtime 500ms -count 15 -bench 'Sum64$') ``` -------------------------------- ### Simple Logging with Zerolog Source: https://github.com/42wim/matterbridge/blob/master/vendor/github.com/rs/zerolog/README.md Demonstrates basic logging using the global zerolog logger. Ensure to set the time field format if needed. By default, logs are written to os.Stderr at the trace level. ```go package main import ( "github.com/rs/zerolog" "github.com/rs/zerolog/log" ) func main() { // UNIX Time is faster and smaller than most timestamps zerolog.TimeFieldFormat = zerolog.TimeFormatUnix log.Print("hello world") } // Output: {"time":1516134303,"level":"debug","message":"hello world"} ```