Informabot
Informabot
(hosted on GitHub) is the Telegram bot that assists DISI students. You can chat with it here.
Dependencies
Go 1.21+ is required.
For JSON code formatting, Prettier @latest
is required.
Compilation
To compile the bot from the project’s root folder, use:
go build
Execution
Before the first execution, the submodule that includes cartabinaria/config
must be populated:
git submodule update --init --recursive
To launch the bot from the project’s root folder, use:
TOKEN=123:A4b5C6 go run .
using the authorization code received from BotFather instead of 123:A4b5C6
.
Configuration
When configuring the bot with BotFather, you will be asked to send the list of commands for your bot. You can paste the result of the /help_botfather
command from Informabot (unlike /help
, this command does not use /
in the result).
Adding new commands
Actions
Actions are stored in json/actions.json
. Each key is the command name that triggers the action, while each value is an object described by several attributes:
type
specifies the logic of the command. The available types are described below;data
provides additional data, all dependent on the type of action. All attributes described below are to be understood as belonging to this field;description
(optional) summarizes the goal of the action.
message
The bot responds with a static message specified by the text
attribute.
list
The bot responds with an automatically generated list, preceded by header
. Each list item is generated by substituting placeholders in template
with elements from a different vector from the items
attribute array.
help
The bot responds by listing each command-description pair. If a command has no description, it is omitted. The slashes
attribute specifies whether /
prefixes for commands should be used (as usual) or omitted (as requested by BotFather).
luck
Tests your luck.
alias
These commands are synonyms of others. The command
attribute specifies which command this alias refers to. Be careful with alias loops, which cause stack overflow due to infinite recursion.
lookingFor
The bot adds the user to the list of people looking for group mates in this chat and responds with the updated list. singularText
, pluralText
, and chatError
are used as customized messages to communicate with the user.
notLookingFor
The bot removes the user from the list of people looking for group mates in this chat. chatError
and nonFoundError
are used to communicate with the user.
yearly
Just as an alias having abc
as the value of the command
attribute triggers the abc
action, so an action of type yearly
having abc
as the value of its command
attribute might execute abc1
, abc2
, or abc3
depending on the chat it’s invoked in. The bot inspects the chat title and tries to infer the appropriate year of study. If the bot fails to guess any year of study, the noyear
attribute value is used as the default response.
buttonsLecture
Creates a step-by-step selection path for the courses’ lectures (bachelor’s and master’s) described in cartabinaria/config/timetables.json
. First, it asks for the selection of the course of study and the year, then it requests the selection of a day starting from today until the next 6 days. Steps work thanks to callbacks. Uses the title described in title
as the message header. In case of failure, fallbackText
is used as the response.
issue
The bot responds by tagging the maintainer
of Informabot who are present in the group. If there are no maintainers within the group, it suggests bringing the issue to the attention of the maintainers in the cartabinaria
group.
buttonsRepresentatives
Creates a step-by-step selection path for the representatives of the courses of study (bachelor’s and master’s) described in ‘cartabinaria/config/representatives.json. The command first asks to select the CdL and returns the list of representatives' emails. Steps work thanks to [callbacks](https://core.telegram.org/bots/api#callbackquery). Uses the title described in
titleas the message header. In case of failure,
fallbackText` is used as the response.
Courses and Degree Programs
Courses and degree programs are retrieved from the cartabinaria/config
submodule located in json/config/
.
Memes
Memes are stored in json/memes.json
. Each key is the name of the command that triggers the meme, while each value is the content of the bot’s response (a simple static message).
Before Contributing
After applying your changes, run the following from the project’s root folder:
go test -v ./... # runs tests
go fmt ./... # formats Go code
prettier --write **/*.json # formats JSON files
This ensures that automatic checks pass once the PR is opened.
Acknowledgments
Informabot originates from a JavaScript snippet delivered from the 2019/20 cohort to the 2020/21 cohort. The students’ thanks go to our colleague @Wifino, who maintained and expanded the original project for a long time.