Gofra - Gofra, an XMPP bot engine written in Go

Gofra, an XMPP bot engine

Gofra is a tiny XMPP bot engine written in Go.

As of now, the current focus is on text-based commands.

Current design uses a Go plugin-based architecture as it was meant to be able to have its plugins hot-reloaded (or even replaced or updated).
Unfortunately, Go's plugin system is far from mature and (at least in this case) adds more complexity than it solves. Plugins need to be compiled against the same version of the binary that is going to use them. Also, testing of binary plugin files cannot be performed. More info on https://github.com/golang/go/issues/27751
As a matter of fact, Go 1.17 has a linker error crashing plugins accessing network resources.

So, although it's been a good and fun learning experience your cents are better invested in either going monolithic or using tools like https://github.com/hashicorp/go-plugin instead.
In that regard and due to the lack of support for plugin testing, Gofra will surely move away from the current plugin-based architecture.

Config

Config fields look as follows:

jid: "[email protected]"
password: "m0r3,S3cur3,Th4n,1234."
nick: "Gofra"
debug: true
logXML: true
pluginPaths:
  - "bin/plugins/"

mucs:
  - mucNick: "Gofra"
    mucJoinHistory: 0
    mucJid: "[email protected]"
    mucPassword: "open,sesame"

plugins:
  Commands:
    commandChar: "!"
  Dice:
    defaultDice: 6

For every MUC the bot needs to join, add an entry under mucs:.
mucJoinHistory refers to the amount of previous messages in the muc the bot will ask the server for.

To add configuration options for your plugin, create an entry for your plugin under plugins:.

Building the project & running tests

Bulding and running a Docker image

docker build -t gofra .
docker run --name gofra gofra

Building and running the binary

make all && ./bin/gofra

To build the project and run the tests:

make tests

Creating plugins

Gofra plugins must comply with the Plugin interface:

type Plugin interface {
  Name() string
  Description() string
  Init(Config, *Gofra)
}

As parameters of the Init method the plugin receives the API object which upon to perform calls, and also the configuration passed in to Gofra.

Aditionally, the Runnable interface can be implemented:

type Runnnable interface {
  Run()
}

The Run method is ran as a goroutine and is meant for plugins that require some code to be executed periodically. As an example of this, the reminder plugin implements the Runnable interface to provide time-based reminders. Other uses can be serving a webpage to display data gathered from Gofra or serving an API to manage Gofra through HTTP, for example.

An easy way to get a grasp is to see how other plugins work and build from there.

Events

Plugins subscribe to events and can trigger others. The following list covers the current available events published by Gofra and its plugins:

Engine events list

  • connected
  • initialized
  • messageReceived
  • presenceReceived
  • eventSubscribed

Available plugin event list

  • command/commandName
  • muc/joinedRoom
  • muc/getOccupants
  • muc/occupantJoinedMuc
  • muc/occupantLeftMuc
  • muc/occupants

Commands usage

assetinfo

User: !assetinfo btc
Gofra: Bitcoin is a peer-to-peer electronic cash system that allows participants to digitally transfer units of bitcoin without a trusted intermediary. Bitcoin combines a public transaction ledger (blockchain), a decentralized currency issuance algorithm (proof-of-work mining), and a transaction verification system (transaction script). Bitcoin has a supply cap of 21 million bitcoin, 95% of which will be mined by the year 2025. Bitcoin relies on Nakamoto consensus, or consensus implied by the longest blockchain that has accumulated the most computational effort.

price

User: !price btcusd
Gofra: btcusd: 37567

User: !price btceur
Gofra: btceur: 33314.3

remind

User: !remind me call the mechanic in one second
Gofra: Reminder added
Gofra: User, call the mechanic

pick

User: !pick Tokyo, Osaka, Kyoto
Gofra: Chose: Osaka

User: !pick 2 Strawberry, Chocolate, Vanilla, Caramel
Gofra: Chose: Caramel and Vanilla

dice

User: !dice
Gofra: 1d6: 6

User: !dice 3d20
Gofra: 3d20: 17, 6, 16

trivia

User: !trivia categories
Gofra:
9: General Knowledge
16: Entertainment: Board Games
17: Science & Nature
18: Science: Computers
.
.
.

User: !trivia start 18
Gofra:
Science: Computers
easy
RAM stands for Random Access Memory.
A) False
B) True

User: B

Gofra:
Science: Computers
medium Which coding language was the #1 programming language in terms of usage on GitHub in 2015?
A) PHP
B) JavaScript
C) C#
D) Python
.
.
.

st (session tracker)

User: !st start
Gofra: Session started!

User: !st add reviewing code
Gofra: Task added

User: !st add very important meeting
Gofra: Task added

User: !st stop
Gofra: Session status: Stopped

Started at: 2022-Jan-26 08:28:17 AM
Duration: 1m18s
Tasks during session:
1- reviewing code. Started at: 2022-Jan-26 08:28:49 AM
2- very important meeting. Started at: 2022-Jan-26 08:29:21 AM

Similar Resources

Simple yet customizable bot framework written in Go.

Simple yet customizable bot framework written in Go.

Introduction Sarah is a general-purpose bot framework named after the author's firstborn daughter. This comes with a unique feature called "stateful c

Dec 12, 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

The modern cryptocurrency trading bot written in Go.

bbgo A trading bot framework written in Go. The name bbgo comes from the BB8 bot in the Star Wars movie. aka Buy BitCoin Go! Current Status Features E

Jan 2, 2023

A general-purpose bot library inspired by Hubot but written in Go. :robot:

Joe Bot 🤖 A general-purpose bot library inspired by Hubot but written in Go. Joe is a library used to write chat bots in the Go programming language.

Dec 24, 2022

An easy-to-use discord bot written in go

Discord Bot An easy-to-use discord bot template written in golang using discordgo. This template was written for learning golang. It will be updated a

Jan 23, 2022

An easy-to-use discord bot template written in golang using discordgo

Discord Bot An easy-to-use discord bot template written in golang using discordgo. This template was written for learning golang. It will be updated a

Oct 30, 2021

Discord Bot written in Go. Created for 'Intro to Golang', Fall 21

goDiscordBot Discord Bot written in Go. Created for 'Intro to Golang', Fall 21 Session where we coded the bot (goes over setup steps): https://gdsc.co

Nov 3, 2021

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
Comments
  • fix module name to make project importable

    fix module name to make project importable

    The previous module name is invalid, causing tools that are stricter than the compiler to fail to when reading this module. Changing it to the full import path allows these tools to work (eg. pkg.go.dev can now parse this package and show it in search results on go.dev).

    This also makes the module installable with go install

  • Bump mellium.im/xmpp from 0.20.0 to 0.21.1

    Bump mellium.im/xmpp from 0.20.0 to 0.21.1

    Bumps mellium.im/xmpp from 0.20.0 to 0.21.1.

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

Related tags
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
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
Quote-bot - Un bot utilisant l'API Twitter pour tweeter une citation par jour sur la programmation et les mathématiques.

Description Ceci est un simple bot programmé en Golang qui tweet une citation sur la programmation tout les jours. Ce bot est host sur le compte Twitt

Jan 1, 2022
Discord-bot - A Discord bot with golang

JS discord bots Install Clone repo git clone https://github.com/fu-js/discord-bo

Aug 2, 2022
Bot - Telegram Music Bot in Go

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

Jun 28, 2022
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
Slack-emoji-bot - This Slack bot will post the newly created custom Slack emojis to the channel of your choice

Slack Emoji Bot This Slack bot will post the newly created custom Slack emojis t

Oct 21, 2022
Sex-bot - The sex bot and its uncreative responses
Sex-bot - The sex bot and its uncreative responses

Sex Bot The sex bot, made with golang! The sex bot can't hear the word "sexo" he

Nov 11, 2022
Feline-bot - Feline Bot for Discord using Golang

Feline Bot for Discord Development This bot is implemented using Golang. Feature

Feb 10, 2022
IRC, Slack, Telegram and RocketChat bot written in go
IRC, Slack, Telegram and RocketChat bot written in go

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

Dec 20, 2022