IRC, Slack, Telegram and RocketChat bot written in go

go-bot

Circle CI GoDoc Coverage Status Go report Reviewed by Hound

IRC, Slack & Telegram bot written in Go using go-ircevent for IRC connectivity, nlopes/slack for Slack and Syfaro/telegram-bot-api for Telegram.

2016-01-17 11 21 38 036

Plugins

Please see the plugins repository for a complete list of plugins.

You can also write your own, it's really simple.

Compiling and testing the bot and plugins (Debug)

This project uses the new Go 1.11 modules if you have Go 1.11 installed, just clone the project and follow the instructions bellow, when you build Go will automatically download all dependencies.

To test the bot, use the debug console app.

  • Clone this repository or use go get github.com/go-chat-bot/bot
  • Build everything: go build ./...
  • Build and execute the debug app:
    • cd debug
    • go build
    • ./debug
  • This will open a console where you can type commands
  • Type !help to see the list of available commands

Testing your plugin

  • Add your plugin to debug/main.go import list
  • Build the debug app
  • Execute it and test with the interactive console

Protocols

Slack

To deploy your go-bot to Slack, you need to:

  • Create a new bot user integration on Slack and get your token
  • Import the package github.com/go-chat-bot/bot/slack
  • Import the commands you would like to use
  • Call slack.Run(token)

Here is a full example reading the Slack token from the SLACK_TOKEN env var:

package main

import (
    "os"

    "github.com/go-chat-bot/bot/slack"
    _ "github.com/go-chat-bot/plugins/catfacts"
    _ "github.com/go-chat-bot/plugins/catgif"
    _ "github.com/go-chat-bot/plugins/chucknorris"
    // Import all the commands you wish to use
)

func main() {
    slack.Run(os.Getenv("SLACK_TOKEN"))
}

IRC

To deploy your own go-bot to IRC, you need to:

  • Import the package github.com/go-chat-bot/bot/irc
  • Import the commands you would like to use
  • Fill the Config struct
  • Call irc.Run(config)

Here is a full example:

package main

import (
	"github.com/go-chat-bot/bot/irc"
	_ "github.com/go-chat-bot/plugins/catfacts"
	_ "github.com/go-chat-bot/plugins/catgif"
	_ "github.com/go-chat-bot/plugins/chucknorris"
	// Import all the commands you wish to use
	"os"
	"strings"
)

func main() {
	irc.Run(&irc.Config{
		Server:   os.Getenv("IRC_SERVER"),
		Channels: strings.Split(os.Getenv("IRC_CHANNELS"), ","),
		User:     os.Getenv("IRC_USER"),
		Nick:     os.Getenv("IRC_NICK"),
		Password: os.Getenv("IRC_PASSWORD"),
		UseTLS:   true,
		Debug:    os.Getenv("DEBUG") != "",})
}

To join channels with passwords just put the password after the channel name separated by a space:

Channels: []string{"#mychannel mypassword", "#go-bot"}

Telegram

To deploy your go-bot to Telegram, you need to:

  • Follow Telegram instructions to create a new bot user and get your token
  • Import the package github.com/go-chat-bot/bot/telegram
  • Import the commands you would like to use
  • Call telegram.Run(token, debug)

Here is a full example reading the telegram token from the TELEGRAM_TOKEN env var:

package main

import (
    "os"

    "github.com/go-chat-bot/bot/telegram"
    _ "github.com/go-chat-bot/plugins/catfacts"
    _ "github.com/go-chat-bot/plugins/catgif"
    _ "github.com/go-chat-bot/plugins/chucknorris"
    // Import all the commands you wish to use
)

func main() {
    telegram.Run(os.Getenv("TELEGRAM_TOKEN"), os.Getenv("DEBUG") != "")
}

Rocket.chat

To deploy your go-bot to Rocket.chat, you need to:

  • Import the package github.com/go-chat-bot/bot/rocket
  • Import the commands you would like to use
  • Call rocket.Run(config)

Here is a full example:

package main

import (
	"os"

	"github.com/go-chat-bot/bot/rocket"
	_ "github.com/go-chat-bot/plugins/godoc"
	_ "github.com/go-chat-bot/plugins/catfacts"
	_ "github.com/go-chat-bot/plugins/catgif"
	_ "github.com/go-chat-bot/plugins/chucknorris"
)

func main() {
	config := &rocket.Config{
		Server:   os.Getenv("ROCKET_SERVER"),
		Port:     os.Getenv("ROCKET_PORT"),
		User:     os.Getenv("ROCKET_USER"),
		Email:    os.Getenv("ROCKET_EMAIL"),
		Password: os.Getenv("ROCKET_PASSWORD"),
		UseTLS:   false,
		Debug:    os.Getenv("DEBUG") != "",
	}
	rocket.Run(config)
}

Google Chat

To deploy your go-bot to Google Chat (also known as Hangouts Chat, not plain Hangouts) you will first need to follow documentation to setup pub/sub project in Google Cloud. This will enable your bot to receive messages even when it is behind a firewall.

Condensed, the steps you will need to take are as follows:

  • Create new project in google cloud console
    • ID of the project will be used in Config.PubSubProject
  • Create service credentials for this project
    • Path to downloaded credentials file should be in env variable GOOGLE_APPLICATION_CREDENTIALS
    • Choose "Pub/Sub Editor" role for the credential
  • Enable Pub/Sub API in cloud console
  • Create new topic in the Pub/Sub (say "google-chat")
    • Use the value of "Topic Name" (not "Topic ID") for Config.TopicName (e.g. /project/<proj_name>/topics/<topic_name>)
  • Modify permissions on created topic so that "[email protected]" has Pub/Sub Publisher permissions
  • Enable hangouts chat api in Cloud Console
  • Go to hangouts chat API config in the Cloud Console and fill in info
    • Connection settings - use Pub/Sub and fill in topic string you created above

Config.SubscriptionName should be unique for each environment or you'll not process messages correctly. If you encounter issues make sure your credentials are correct and permissions for topics/queues are set up correctly.

Config.WelcomeMessage is sent each time the bot joins a new room or private chat.

Full example is here:

package main

import (
	"os"

	"github.com/go-chat-bot/bot/google-chat"
	_ "github.com/go-chat-bot/plugins/godoc"
	_ "github.com/go-chat-bot/plugins/catfacts"
	_ "github.com/go-chat-bot/plugins/catgif"
	_ "github.com/go-chat-bot/plugins/chucknorris"
)

func main() {
	googlechat.Run(&googlechat.Config{
		PubSubProject:    os.Getenv("HANGOUTS_PROJECT"),
		TopicName:        os.Getenv("HANGOUTS_TOPIC"),
		SubscriptionName: os.Getenv("HANGOUTS_SUB"),
		WelcomeMessage:   os.Getenv("HANGOUTS_WELCOME"),
}

Deploying your own bot

To see an example project on how to deploy your bot, please see my own configuration:

Comments
  • Send message on event

    Send message on event

    I currently developing a bot that monitor a websocket and forward messages received to a channel. Your library looks great to does this task and will allow to add more feature but the issue I get with is I don't find how to send a message without being into the context of a command most of the method to do that are a not exported. I would like to know if you have any idea how I can achieve this into a plugin?

  • how to register a package for transmitting the output of a webhook

    how to register a package for transmitting the output of a webhook

    I'd like to implement receiving an incoming webhook (perhaps using https://github.com/go-playground/webhooks) and then notifying a channel of the event. I'm uncertain if this is the same as the #37 discussion.

    Would it work to create a Webhooks.Run(&Config{...}) for use in main.go?

  • PassiveCommand does not work with Slack App Integrations

    PassiveCommand does not work with Slack App Integrations

    I have Slack Jira Integration and trying to implement a passive command that listens Jira bots messages. But it seems that bot couldn't parse bots name and raw message.

  • cannot use message (type string) as type slack.MsgOption in argument to api.PostMessage

    cannot use message (type string) as type slack.MsgOption in argument to api.PostMessage

    https://github.com/go-chat-bot/bot/blob/cf98806022032f1199b8e612483a21485156b169/slack/slack.go#L32

    `D:\Go\GOPATH\src\github.com\go-chat-bot>go build ./...

    github.com/go-chat-bot/bot/slack

    bot\slack\slack.go:32:17: cannot use message (type string) as type slack.MsgOption in argument to api.PostMessage bot\slack\slack.go:32:17: cannot use params (type slack.PostMessageParameters) as type slack.MsgOption in argument to api.PostMessage`

  • Getting two responses for single slack command

    Getting two responses for single slack command

    I am building slack bot which basically takes kubectl command like kubectl get pods. Now, I want to send some message like Your request has been acknowledged immediately after any command is sent from slack and then the result of command. Currently, I have implemented the command result sending process but couldn't figure out how to send the "pre result message". Any idea? I tried implementing this way:

    func response(command *bot.PassiveCmd) (string, error) {
       return fmt.Sprintf("Your request has been added to queue"), nil
    }
    func init() {
    	bot.RegisterPassiveCommand(
    					"",
    					response)
    }
    func init() {
    	bot.RegisterCommand(
     		"deployer",
     		"Kubectl Slack integration",
     		"",
    	kubectl)
     
    }
    

    But the problem is when I enter slack message with @deployer get pods, then it triggers kubectl and when I just hit kubectl get pods, it triggers response. But I need to combine both. PS: Here, my cmdprefix is @. Hope you get it. If I am not clear, please feel free to ask on comment. Thanks.

  • Expand with PeriodicCommands?

    Expand with PeriodicCommands?

    Hi, and thanks for this neat little bot! Sorry to open an issue but I wanted a place to discuss a little feature I've been thinking about. It's basically a new type of command 'PeriodicCommands' (a better name is welcome), which are commands run after some duration, or at a specific time (like a cron job).

    My use case for this would be checking some logs every X minute, and if some error occurs, post a message to the provided channel/user.

    The easiest way to accomplish this would be to add this new type of commands, as well as a RegisterPeriodicCommand function (similar to RegisterCommand). And in the loop check whether or not to run any of these periodic commands. Do you have any thoughts or different ideas to achieve the same goal? :-) I would be happy to code up a PR if you think this is something we should add to the bot.

    • Kjetil
  • build: error finding git.apache.org/thrift.git

    build: error finding git.apache.org/thrift.git

    Hi,

    I'm not sure how to debug this issue on my side, I'm just trying to build everything in order to build a new bot (it might not be the best practice), and this process blocks on this error:

    $ go build ./...
    go: finding git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999
    go: git.apache.org/[email protected]: git fetch -f https://git.apache.org/thrift.git refs/heads/*:refs/heads/* refs/tags/*:refs/tags/* in /home/alx/go/pkg/mod/cache/vcs/83dba939f95a790e497d565fc4418400145a1a514f955fa052f662d56e920c3e: exit status 128:
            fatal: unable to access 'https://git.apache.org/thrift.git/': Failed to connect to git.apache.org port 443: Connection timed out
    go: error loading module requirements
    

    Thanks,

    Alex

  • Initial implementation of filter commands

    Initial implementation of filter commands

    This commit adds new type of commands which can modify outputs of other plugins. It provides a way to implement new types of plugins such as generic URL shortener or silencer.

    Fixes #78

  • Add new command type: filter

    Add new command type: filter

    So I have 2 use cases that would need new type of command.

    Use cases:

    • When URLs are posted by the bot automatically use shortener on them
    • Provide ability to silence the bot for period of time in specific channel

    The way I imagine this working is as follows:

    • Add a new "filter" command registration
    • Filters get called around/inside SendMessage invocations

    They can either "skip" the message (second use case) or modify the output (first use case). It seems like a nicer approach then for example implementing shortener in JIRA and/or other plugins.

    Thoughts?

  • Telegram api error exit status 1

    Telegram api error exit status 1

    package main
    
    import (
        "os"
        "github.com/go-chat-bot/bot/telegram"
    )
    
    func main() {
        telegram.Run(os.Getenv("telegram__tokenhere"), os.Getenv("DEBUG") != "")
    }
    

    The result I received is:

    exit status 1
    

    My api token is working on other frameworks.

  • Actions

    Actions

    I wanted to be able to handle IRC actions (/me does things style messages), which turn out to be available on Slack as well. Since I wanted to keep the "action-ness" around without introducing BC breaks, I added a MessageData to commands and passivecommands, just like I did with ChannelData a while ago. For now it's just the actual message and a flag that is set if it's an action. Has no effects on Telegram, since there's no actions there. Has, to my knowledge, no effects on existing plugins and setups, either.

  • expose command prefix in `irc.Config`

    expose command prefix in `irc.Config`

    expose the command prefix variable in the Config struct, the current OS ENV solution feels like a cheat, plus it doesn't apply for plugins and is not documented.

    let me know if I could send a PR w/ the change.

  • Update request to use SocketMode and WSS as RTM is deprecated in Slack API.

    Update request to use SocketMode and WSS as RTM is deprecated in Slack API.

    https://github.com/go-chat-bot/bot/blob/763f9eeac7d5d43ac3ddce8cf2a32490d6757bbc/slack/slack.go#L16

    Since Slack recommends using SocketMode which uses Websockets for Interactivity the RTM method is deprecated in the Slack API.

    Request for an updated Slack implementation that uses WebSockets and SocketMode to implement Go-Chat-bot for Slack.

  • integration of RegisterMessageReceiveFilter work

    integration of RegisterMessageReceiveFilter work

    A while back I added the feature RegisterMessageReceiveFilter to my fork... https://github.com/bnfinet/go-chat-bot/blob/master/cmd.go#L282-L296

    This filter operation is conducted before command interpretation and execution. This allows for plugins to be created with a generalized allow/disallow and RBAC of commands based on proto/server/channel/user criteria.

    Instead of opening a PR I decided to start with an issue to see if this is worthy of inclusion. If so, I'll start from the current master in this repo and (non git) cherry pick the changes, since this work is mostly from a few years back.

    Thanks for your consideration.

    https://github.com/go-chat-bot/bot/commit/52715792d0b7549a656cc9a6d4f9c69898aeb1b1

  • Rocket.Chat default port for a bot?

    Rocket.Chat default port for a bot?

    I'm setting up a bot to connect to a server which doesn't belong to me and this server is using the default settings for almost everything including ports. Here's my current config:

    ...
    func main() {
            config := &rocket.Config{
                    Server:   "chat.server.com",
                    Port:     "?????",
                    User:     "test-1-bot",
                    Email:    "[email protected]",
                    Password: "********",
                    UseTLS:   false,
                    Debug:    os.Getenv("DEBUG") != "",
            }
            rocket.Run(config)
    }
    

    What is a default ROCKET_PORT value: 3000, 80 or 443 ? I tried using them all, but am getting the following results:

    3000: login err: Post http://chat.server.com:3000/api/v1/login: dial tcp ***.*.*.:3000: connect: connection refused 80: login err: Request error: 405 Method Not Allowed 443: login err: Request error: 400 Bad Request

  • Support text formatting for Slack

    Support text formatting for Slack

    If a command is sent with bold message formatting the logic doesn't seem to match it to a plugin. I would assume this has to do with the formatting of the message being surrounded in * characters. Is there an option to remove formatting or continue to route the message to the plugins if formatting is present?

  • Errors are shown publicly

    Errors are shown publicly

    Parsing errors are shown publicly, which is kinda odd considering that "command not found", which undoubtably is thrown more frequent, is only logged.

    I believe these lines are at fault, https://github.com/go-chat-bot/bot/blob/master/bot.go#L183-L187

    Patch attached:

    Index: bot.go
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    ===================================================================
    --- bot.go	(revision 3da6cae4547763aa55828a9f75ed4693bed5d36f)
    +++ bot.go	(date 1574671039000)
    @@ -180,11 +180,7 @@
     func (b *Bot) MessageReceived(channel *ChannelData, message *Message, sender *User) {
     	command, err := parse(message, channel, sender)
     	if err != nil {
    -		b.SendMessage(OutgoingMessage{
    -			Target:  channel.Channel,
    -			Message: err.Error(),
    -			Sender:  sender,
    -		})
    +		log.Fatalf("Error: %v, Channel: %v, Sender: %v", channel.Channel, err.Error(), sender.ID)
     		return
     	}
     
    
    
Related tags
Dlercloud-telegram-bot - A Telegram bot for managing your Dler Cloud account

Dler Cloud Telegram Bot A Telegram bot for managing your Dler Cloud account. Usa

Dec 30, 2021
Pro-bot - A telegram bot to play around with the community telegram channels

pro-bot ?? Pro Bot A Telegram Bot to Play Around With The Community Telegram Cha

Jan 24, 2022
REPLbot is a Slack bot that allows you to control a REPL from within Slack.
REPLbot is a Slack bot that allows you to control a REPL from within Slack.

?? REPLbot REPLbot is a Slack bot that allows you to control a REPL from within Slack. It comes with a few REPLs (Go ?? , Java, NodeJS, PHP, Python, R

Dec 31, 2022
This slack-bot collects all @gophers notifications into one slack channel

slack-bot Slack bot copying reference to a ping to notifications channel The bot is designed to listen on messages containing specific tag, copy refer

Apr 11, 2022
A bot based on Telegram Bot API written in Golang allows users to download public Instagram photos, videos, and albums without receiving the user's credentials.

InstagramRobot InstagramRobot is a bot based on Telegram Bot API written in Golang that allows users to download public Instagram photos, videos, and

Dec 16, 2021
IRC bot for launch ddos attack, Mainly of scan target are IoT device that run linux and open default SSH port
IRC bot for launch ddos attack, Mainly of scan target are IoT device that run linux and open default SSH port

This is my first IRC bot for launch ddos attack, Mainly of scan target are IoT device that run linux and open default SSH port, This bot is write on Go language. For education purpose only. Please test it in your lab. And i create this for join university in the future not for attack anyone server with out any permission!!!

Jan 2, 2023
Jaken - A general purpose IRC bot featuring user acls and arbitrary plugins

Design principles This bot is based on the premise of a loosely coupling between

Jul 21, 2022
The Tenyks IRC bot.

Tenyks is a computer program designed to relay messages between connections to IRC networks and custom built services written in any number of languages.

Sep 26, 2022
This is my first IRC bot for launch ddos attack, Write on Go language.
This is my first IRC bot for launch ddos attack, Write on Go language.

This is my first IRC bot for launch ddos attack, Write on Go language. For education purpose only. Please test it on your lab, And i create this for join university in the future not for attack anyone server with out any permission!!!

Sep 23, 2022
Bot - Telegram Music Bot in Go

Telegram Music Bot in Go An example bot using gotgcalls. Setup Install the serve

Jun 28, 2022
Slack bot core/framework written in Go with support for reactions to message updates/deletes
Slack bot core/framework written in Go with support for reactions to message updates/deletes

Overview Requirements Features Demo The Name Concepts Create Your Own Slackscot Assembling the Parts and Bringing Your slackscot to Life Configuration

Oct 28, 2022
A modern IRC server (daemon/ircd) written in Go.
A modern IRC server (daemon/ircd) written in Go.

Oragono is a modern IRC server written in Go. Its core design principles are: Being simple to set up and use Combining the features of an ircd, a serv

Dec 31, 2022
Bot-template - A simple bot template for creating a bot which includes a config, postgresql database

bot-template This is a simple bot template for creating a bot which includes a c

Sep 9, 2022
A serverless bot which periodically checks configured BigQuery capacity commitments, reservations and assignments against actual slot consumption of running jobs and reports findings to Slack/Google Chat.
A serverless bot which periodically checks configured BigQuery capacity commitments, reservations and assignments against actual slot consumption of running jobs and reports findings to Slack/Google Chat.

Solution Guide This solution implements a ChatOps-like approach to monitoring slot utilization of Google Cloud BigQuery reservations. As an alternativ

Dec 7, 2022
RaspChecker - A Telegram bot that allows you to monitor your Raspberry Pi's temperature and shut it down. Written in Golang.

RaspChecker Remotely monitor your Raspberry Pi's temperature and shut it down if you want. All through Telegram. How to set up In order to run the bot

Jan 2, 2022
Golang bot that connects to slack using Socketclient to read and write messages.
Golang bot that connects to slack using Socketclient to read and write messages.

?? (not)simple go project ?? Golang bot that connects to slack using Socketclient to read and write messages. ?? Use ?? @SquidBot : Mentions your name

Aug 23, 2022
The serverless OTP telegram service use telegram as OTP service, and send OTP through webhook

Setup OTP First thing, you need prepare API(webhook) with POST method, the payload format as below { "first_name": "Nolan", "last_name": "Nguyen",

Jul 24, 2022
Fancy, fully-featured, easy to use Telegram CAPTCHA bot written in Go
Fancy, fully-featured, easy to use Telegram CAPTCHA bot written in Go

Go Telegram Captcha Bot Fancy, fully-featured, easy to use, scalable Telegram CAPTCHA bot written in Go based on tucnak's telebot this robot only has

Jul 18, 2022
YouTube downloader bot for Telegram written in the Go programming language

ytdGoBot YouTube downloader bot for Telegram written in the Go programming language. For now it only downloads audio content from a provided YouTube l

Apr 15, 2022